@@ -24,59 +24,6 @@ const uint32_t kSignatureMessageCurrentVersion = 2;
24
24
25
25
namespace {
26
26
27
- // The following is a standard PKCS1-v1_5 padding for SHA256 signatures, as
28
- // defined in RFC3447. It is prepended to the actual signature (32 bytes) to
29
- // form a sequence of 256 bytes (2048 bits) that is amenable to RSA signing. The
30
- // padded hash will look as follows:
31
- //
32
- // 0x00 0x01 0xff ... 0xff 0x00 ASN1HEADER SHA256HASH
33
- // |--------------205-----------||----19----||----32----|
34
- //
35
- // where ASN1HEADER is the ASN.1 description of the signed data. The complete 51
36
- // bytes of actual data (i.e. the ASN.1 header complete with the hash) are
37
- // packed as follows:
38
- //
39
- // SEQUENCE(2+49) {
40
- // SEQUENCE(2+13) {
41
- // OBJECT(2+9) id-sha256
42
- // NULL(2+0)
43
- // }
44
- // OCTET STRING(2+32) <actual signature bytes...>
45
- // }
46
- const unsigned char kRSA2048SHA256Padding [] = {
47
- // PKCS1-v1_5 padding
48
- 0x00 , 0x01 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
49
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
50
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
51
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
52
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
53
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
54
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
55
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
56
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
57
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
58
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
59
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
60
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
61
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
62
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
63
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
64
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
65
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
66
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
67
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
68
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
69
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
70
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
71
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
72
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
73
- 0xff , 0xff , 0xff , 0xff , 0x00 ,
74
- // ASN.1 header
75
- 0x30 , 0x31 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 ,
76
- 0x48 , 0x01 , 0x65 , 0x03 , 0x04 , 0x02 , 0x01 , 0x05 ,
77
- 0x00 , 0x04 , 0x20 ,
78
- };
79
-
80
27
// Given raw |signatures|, packs them into a protobuf and serializes it into a
81
28
// binary blob. Returns true on success, false otherwise.
82
29
bool ConvertSignatureToProtobufBlob (const vector<vector<char > >& signatures,
@@ -179,7 +126,6 @@ bool PayloadSigner::SignHash(const vector<char>& hash,
179
126
// We expect unpadded SHA256 hash coming in
180
127
TEST_AND_RETURN_FALSE (hash.size () == 32 );
181
128
vector<char > padded_hash (hash);
182
- PadRSA2048SHA256Hash (&padded_hash);
183
129
TEST_AND_RETURN_FALSE (utils::WriteFile (hash_path.c_str (),
184
130
padded_hash.data (),
185
131
padded_hash.size ()));
@@ -309,7 +255,7 @@ bool PayloadSigner::GetRawHashFromSignature(
309
255
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new (pkey, NULL );
310
256
if (!ctx
311
257
|| EVP_PKEY_verify_recover_init (ctx) <= 0
312
- || EVP_PKEY_CTX_set_rsa_padding (ctx, RSA_NO_PADDING ) <= 0
258
+ || EVP_PKEY_CTX_set_rsa_padding (ctx, RSA_PKCS1_PADDING ) <= 0
313
259
|| EVP_PKEY_CTX_set_signature_md (ctx, EVP_sha256 ()) <= 0 ) {
314
260
LOG (ERROR) << " Couldn't initialise EVP_PKEY_CTX" ;
315
261
EVP_PKEY_free (pkey);
@@ -359,7 +305,6 @@ bool PayloadSigner::VerifySignedPayload(const std::string& payload_path,
359
305
vector<char > hash;
360
306
TEST_AND_RETURN_FALSE (OmahaHashCalculator::RawHashOfBytes (
361
307
payload.data (), metadata_size + manifest.signatures_offset (), &hash));
362
- PadRSA2048SHA256Hash (&hash);
363
308
TEST_AND_RETURN_FALSE (hash == signed_hash);
364
309
return true ;
365
310
}
@@ -432,14 +377,4 @@ bool PayloadSigner::AddSignatureToPayload(
432
377
return true ;
433
378
}
434
379
435
- bool PayloadSigner::PadRSA2048SHA256Hash (std::vector<char >* hash) {
436
- TEST_AND_RETURN_FALSE (hash->size () == 32 );
437
- hash->insert (hash->begin (),
438
- reinterpret_cast <const char *>(kRSA2048SHA256Padding ),
439
- reinterpret_cast <const char *>(kRSA2048SHA256Padding +
440
- sizeof (kRSA2048SHA256Padding )));
441
- TEST_AND_RETURN_FALSE (hash->size () == 256 );
442
- return true ;
443
- }
444
-
445
380
} // namespace chromeos_update_engine
0 commit comments