Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: payload_signer_unittest.cc

Issue 6771024: AU: Switch to 2048 bit RSA keys; Pad SHA256 hashes appropriately. (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: remove debug log statement Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 #include <gtest/gtest.h> 7 #include <gtest/gtest.h>
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "update_engine/payload_signer.h" 9 #include "update_engine/payload_signer.h"
10 #include "update_engine/update_metadata.pb.h" 10 #include "update_engine/update_metadata.pb.h"
11 #include "update_engine/utils.h" 11 #include "update_engine/utils.h"
12 12
13 using std::string; 13 using std::string;
14 using std::vector; 14 using std::vector;
15 15
16 // Note: the test key was generated with the following command: 16 // Note: the test key was generated with the following command:
17 // openssl genrsa -out unittest_key.pem 1024 17 // openssl genrsa -out unittest_key.pem 2048
18 18
19 namespace chromeos_update_engine { 19 namespace chromeos_update_engine {
20 20
21 const char* kUnittestPrivateKeyPath = "unittest_key.pem"; 21 const char* kUnittestPrivateKeyPath = "unittest_key.pem";
22 const char* kUnittestPublicKeyPath = "unittest_key.pub.pem"; 22 const char* kUnittestPublicKeyPath = "unittest_key.pub.pem";
23 23
24 // Some data and its corresponding hash and signature: 24 // Some data and its corresponding hash and signature:
25 const char kDataToSign[] = "This is some data to sign."; 25 const char kDataToSign[] = "This is some data to sign.";
26
27 // Generated by:
28 // echo -n 'This is some data to sign.' | openssl dgst -sha256 -binary |
29 // hexdump -v -e '" " 8/1 "0x%02x, " "\n"'
26 const char kDataHash[] = { 30 const char kDataHash[] = {
27 0x7a, 0x07, 0xa6, 0x44, 0x08, 0x86, 0x20, 0xa6, 31 0x7a, 0x07, 0xa6, 0x44, 0x08, 0x86, 0x20, 0xa6,
28 0xc1, 0xf8, 0xd9, 0x02, 0x05, 0x63, 0x0d, 0xb7, 32 0xc1, 0xf8, 0xd9, 0x02, 0x05, 0x63, 0x0d, 0xb7,
29 0xfc, 0x2b, 0xa0, 0xa9, 0x7c, 0x9d, 0x1d, 0x8c, 33 0xfc, 0x2b, 0xa0, 0xa9, 0x7c, 0x9d, 0x1d, 0x8c,
30 0x01, 0xf5, 0x78, 0x6d, 0xc5, 0x11, 0xb4, 0x06 34 0x01, 0xf5, 0x78, 0x6d, 0xc5, 0x11, 0xb4, 0x06
31 }; 35 };
36
37 // Generated with openssl 1.0, which at the time of this writing, you need
38 // to download and install yourself. Here's my command:
39 // echo -n 'This is some data to sign.' | openssl dgst -sha256 -binary |
40 // ~/local/bin/openssl pkeyutl -sign -inkey unittest_key.pem -pkeyopt
41 // digest:sha256 | hexdump -v -e '" " 8/1 "0x%02x, " "\n"'
32 const char kDataSignature[] = { 42 const char kDataSignature[] = {
33 0xa4, 0xbc, 0x8f, 0xeb, 0x81, 0x05, 0xaa, 0x56, 43 0x9f, 0x86, 0x25, 0x8b, 0xf3, 0xcc, 0xe3, 0x95,
34 0x1b, 0x56, 0xe5, 0xcb, 0x9b, 0x1a, 0x00, 0xd7, 44 0x5f, 0x45, 0x83, 0xb2, 0x66, 0xf0, 0x2a, 0xcf,
35 0x1d, 0x87, 0x8e, 0xda, 0x5e, 0x90, 0x09, 0xb8, 45 0xb7, 0xaa, 0x52, 0x25, 0x7a, 0xdd, 0x9d, 0x65,
36 0x15, 0xf4, 0x25, 0x97, 0x2f, 0x3c, 0xa1, 0xf3, 46 0xe5, 0xd6, 0x02, 0x4b, 0x37, 0x99, 0x53, 0x06,
37 0x02, 0x75, 0xcd, 0x67, 0x4b, 0x0c, 0x1f, 0xf5, 47 0xc2, 0xc9, 0x37, 0x36, 0x25, 0x62, 0x09, 0x4f,
38 0x6e, 0xf1, 0x58, 0xd7, 0x0d, 0x8c, 0x18, 0x91, 48 0x6b, 0x22, 0xf8, 0xb3, 0x89, 0x14, 0x98, 0x1a,
39 0x52, 0x30, 0x98, 0x64, 0x58, 0xc0, 0xe2, 0xb5, 49 0xbc, 0x30, 0x90, 0x4a, 0x43, 0xf5, 0xea, 0x2e,
40 0x77, 0x3b, 0x96, 0x8f, 0x05, 0xc4, 0x7f, 0x7a, 50 0xf0, 0xa4, 0xba, 0xc3, 0xa7, 0xa3, 0x44, 0x70,
41 0x9a, 0x44, 0x0f, 0xc7, 0x1b, 0x90, 0x83, 0xf8, 51 0xd6, 0xc4, 0x89, 0xd8, 0x45, 0x71, 0xbb, 0xee,
42 0x69, 0x05, 0xa8, 0x02, 0x57, 0xcd, 0x2e, 0x5b, 52 0x59, 0x87, 0x3d, 0xd5, 0xe5, 0x40, 0x22, 0x3d,
43 0x96, 0xc7, 0x77, 0xa6, 0x1f, 0x97, 0x97, 0x05, 53 0x73, 0x7e, 0x2a, 0x58, 0x93, 0x8e, 0xcb, 0x9c,
44 0xb3, 0x30, 0x1c, 0x27, 0xd7, 0x2d, 0x31, 0x60, 54 0xf2, 0xbb, 0x4a, 0xc9, 0xd2, 0x2c, 0x52, 0x42,
45 0x84, 0x7e, 0x99, 0x00, 0xe6, 0xe1, 0x39, 0xa6, 55 0xb0, 0xd1, 0x13, 0x22, 0xa4, 0x78, 0xc7, 0xc6,
46 0xf3, 0x3a, 0x72, 0xba, 0xc4, 0xfe, 0x68, 0xa9, 56 0x3e, 0xf1, 0xdc, 0x4c, 0x7b, 0x2d, 0x40, 0xda,
47 0x08, 0xfa, 0xbc, 0xa8, 0x44, 0x66, 0xa0, 0x60, 57 0x58, 0xac, 0x4a, 0x11, 0x96, 0x3d, 0xa0, 0x01,
48 0xde, 0xc9, 0xb2, 0xba, 0xbc, 0x80, 0xb5, 0x55 58 0xf6, 0x96, 0x74, 0xf6, 0x6c, 0x0c, 0x49, 0x69,
59 0x4e, 0xc1, 0x7e, 0x9f, 0x2a, 0x42, 0xdd, 0x15,
60 0x6b, 0x37, 0x2e, 0x3a, 0xa7, 0xa7, 0x6d, 0x91,
61 0x13, 0xe8, 0x59, 0xde, 0xfe, 0x99, 0x07, 0xd9,
62 0x34, 0x0f, 0x17, 0xb3, 0x05, 0x4c, 0xd2, 0xc6,
63 0x82, 0xb7, 0x38, 0x36, 0x63, 0x1d, 0x9e, 0x21,
64 0xa6, 0x32, 0xef, 0xf1, 0x65, 0xe6, 0xed, 0x95,
65 0x25, 0x9b, 0x61, 0xe0, 0xba, 0x86, 0xa1, 0x7f,
66 0xf8, 0xa5, 0x4a, 0x32, 0x1f, 0x15, 0x20, 0x8a,
67 0x41, 0xc5, 0xb0, 0xd9, 0x4a, 0xda, 0x85, 0xf3,
68 0xdc, 0xa0, 0x98, 0x5d, 0x1d, 0x18, 0x9d, 0x2e,
69 0x42, 0xea, 0x69, 0x13, 0x74, 0x3c, 0x74, 0xf7,
70 0x6d, 0x43, 0xb0, 0x63, 0x90, 0xdb, 0x04, 0xd5,
71 0x05, 0xc9, 0x73, 0x1f, 0x6c, 0xd6, 0xfa, 0x46,
72 0x4e, 0x0f, 0x33, 0x58, 0x5b, 0x0d, 0x1b, 0x55,
73 0x39, 0xb9, 0x0f, 0x43, 0x37, 0xc0, 0x06, 0x0c,
74 0x29, 0x93, 0x43, 0xc7, 0x43, 0xb9, 0xab, 0x7d
49 }; 75 };
50 76
51 //class PayloadSignerTest : public ::testing::Test {}; 77 //class PayloadSignerTest : public ::testing::Test {};
52 78
53 namespace { 79 namespace {
54 void SignSampleData(vector<char>* out_signature_blob) { 80 void SignSampleData(vector<char>* out_signature_blob) {
55 string data_path; 81 string data_path;
56 ASSERT_TRUE( 82 ASSERT_TRUE(
57 utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL)); 83 utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL));
58 ScopedPathUnlinker data_path_unlinker(data_path); 84 ScopedPathUnlinker data_path_unlinker(data_path);
(...skipping 30 matching lines...) Expand all
89 } 115 }
90 116
91 TEST(PayloadSignerTest, VerifySignatureTest) { 117 TEST(PayloadSignerTest, VerifySignatureTest) {
92 vector<char> signature_blob; 118 vector<char> signature_blob;
93 SignSampleData(&signature_blob); 119 SignSampleData(&signature_blob);
94 120
95 vector<char> hash_data; 121 vector<char> hash_data;
96 EXPECT_TRUE(PayloadSigner::VerifySignature(signature_blob, 122 EXPECT_TRUE(PayloadSigner::VerifySignature(signature_blob,
97 kUnittestPublicKeyPath, 123 kUnittestPublicKeyPath,
98 &hash_data)); 124 &hash_data));
99 ASSERT_EQ(arraysize(kDataHash), hash_data.size()); 125 vector<char> padded_hash_data(kDataHash, kDataHash + sizeof(kDataHash));
100 for (size_t i = 0; i < arraysize(kDataHash); i++) { 126 PayloadSigner::PadRSA2048SHA256Hash(&padded_hash_data);
101 EXPECT_EQ(kDataHash[i], hash_data[i]); 127 ASSERT_EQ(padded_hash_data.size(), hash_data.size());
128 for (size_t i = 0; i < padded_hash_data.size(); i++) {
129 EXPECT_EQ(padded_hash_data[i], hash_data[i]);
102 } 130 }
103 } 131 }
104 132
105 } // namespace chromeos_update_engine 133 } // namespace chromeos_update_engine
OLDNEW
« payload_signer.cc ('K') | « payload_signer.cc ('k') | unittest_key.pem » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698