Skip to content

Commit 30800c6

Browse files
committed
update_engine: drop manual padding
this padding was initially required for using sha256+rsa2048. It's not needed anymore as we can rely on the RSA_PKCS1_PADDING Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
1 parent ccb3c33 commit 30800c6

File tree

5 files changed

+1
-76
lines changed

5 files changed

+1
-76
lines changed

src/update_engine/payload_processor.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ ActionExitCode PayloadProcessor::VerifyPayload() {
361361
TEST_AND_RETURN_VAL(kActionCodeDownloadPayloadPubKeyVerificationError,
362362
signed_hasher.Finalize());
363363
vector<char> hash_data = signed_hasher.raw_hash();
364-
PayloadSigner::PadRSA2048SHA256Hash(&hash_data);
365364
TEST_AND_RETURN_VAL(kActionCodeDownloadPayloadPubKeyVerificationError,
366365
!hash_data.empty());
367366
if (hash_data != signed_hash_data) {

src/update_engine/payload_processor_unittest.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ static void SignGeneratedShellPayload(SignatureTest signature_test,
204204
// Pad the hash
205205
vector<char> hash;
206206
ASSERT_TRUE(utils::ReadFile(hash_file, &hash));
207-
ASSERT_TRUE(PayloadSigner::PadRSA2048SHA256Hash(&hash));
208207
ASSERT_TRUE(WriteFileVector(hash_file, hash));
209208

210209
string sig_file;

src/update_engine/payload_signer.cc

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,6 @@ const uint32_t kSignatureMessageCurrentVersion = 2;
2424

2525
namespace {
2626

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-
8027
// Given raw |signatures|, packs them into a protobuf and serializes it into a
8128
// binary blob. Returns true on success, false otherwise.
8229
bool ConvertSignatureToProtobufBlob(const vector<vector<char> >& signatures,
@@ -179,7 +126,6 @@ bool PayloadSigner::SignHash(const vector<char>& hash,
179126
// We expect unpadded SHA256 hash coming in
180127
TEST_AND_RETURN_FALSE(hash.size() == 32);
181128
vector<char> padded_hash(hash);
182-
PadRSA2048SHA256Hash(&padded_hash);
183129
TEST_AND_RETURN_FALSE(utils::WriteFile(hash_path.c_str(),
184130
padded_hash.data(),
185131
padded_hash.size()));
@@ -309,7 +255,7 @@ bool PayloadSigner::GetRawHashFromSignature(
309255
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(pkey, NULL);
310256
if (!ctx
311257
|| 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
313259
|| EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) {
314260
LOG(ERROR) << "Couldn't initialise EVP_PKEY_CTX";
315261
EVP_PKEY_free(pkey);
@@ -359,7 +305,6 @@ bool PayloadSigner::VerifySignedPayload(const std::string& payload_path,
359305
vector<char> hash;
360306
TEST_AND_RETURN_FALSE(OmahaHashCalculator::RawHashOfBytes(
361307
payload.data(), metadata_size + manifest.signatures_offset(), &hash));
362-
PadRSA2048SHA256Hash(&hash);
363308
TEST_AND_RETURN_FALSE(hash == signed_hash);
364309
return true;
365310
}
@@ -432,14 +377,4 @@ bool PayloadSigner::AddSignatureToPayload(
432377
return true;
433378
}
434379

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-
445380
} // namespace chromeos_update_engine

src/update_engine/payload_signer.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ class PayloadSigner {
113113
const std::string& public_key_path,
114114
uint32_t client_key_check_version);
115115

116-
// Pads a SHA256 hash so that it may be encrypted/signed with RSA2048
117-
// using the PKCS#1 v1.5 scheme.
118-
// hash should be a pointer to vector of exactly 256 bits. The vector
119-
// will be modified in place and will result in having a length of
120-
// 2048 bits. Returns true on success, false otherwise.
121-
static bool PadRSA2048SHA256Hash(std::vector<char>* hash);
122-
123116
// Reads the payload from the given |payload_path| into the |out_payload|
124117
// vector. It also parses the manifest protobuf in the payload and returns it
125118
// in |out_manifest| along with the size of the entire metadata in

src/update_engine/payload_signer_unittest.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ TEST(PayloadSignerTest, VerifySignatureTest) {
130130
vector<char> padded_hash_data(reinterpret_cast<const char *>(kDataHash),
131131
reinterpret_cast<const char *>(kDataHash +
132132
sizeof(kDataHash)));
133-
PayloadSigner::PadRSA2048SHA256Hash(&padded_hash_data);
134133
ASSERT_EQ(padded_hash_data.size(), hash_data.size());
135134
for (size_t i = 0; i < padded_hash_data.size(); i++) {
136135
EXPECT_EQ(padded_hash_data[i], hash_data[i]);

0 commit comments

Comments
 (0)