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

Side by Side Diff: tests/vboot_common3_tests.c

Issue 3126013: Fix KeyBlockVerify() to take an explicit param for whether to use hash only. (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Fix one last typo Created 10 years, 4 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
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 * Tests for firmware image library. 5 * Tests for firmware image library.
6 */ 6 */
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
(...skipping 22 matching lines...) Expand all
33 VbKeyBlockHeader *h; 33 VbKeyBlockHeader *h;
34 unsigned hsize; 34 unsigned hsize;
35 35
36 hdr = KeyBlockCreate(data_key, private_key, 0x1234); 36 hdr = KeyBlockCreate(data_key, private_key, 0x1234);
37 TEST_NEQ((size_t)hdr, 0, "KeyBlockVerify() prerequisites"); 37 TEST_NEQ((size_t)hdr, 0, "KeyBlockVerify() prerequisites");
38 if (!hdr) 38 if (!hdr)
39 return; 39 return;
40 hsize = (unsigned) hdr->key_block_size; 40 hsize = (unsigned) hdr->key_block_size;
41 h = (VbKeyBlockHeader*)Malloc(hsize + 1024); 41 h = (VbKeyBlockHeader*)Malloc(hsize + 1024);
42 42
43 TEST_EQ(KeyBlockVerify(hdr, hsize, NULL), 0, 43 TEST_EQ(KeyBlockVerify(hdr, hsize, NULL, 1), 0,
44 "KeyBlockVerify() ok using checksum"); 44 "KeyBlockVerify() ok using checksum");
45 TEST_EQ(KeyBlockVerify(hdr, hsize, public_key), 0, 45 TEST_EQ(KeyBlockVerify(hdr, hsize, public_key, 0), 0,
46 "KeyBlockVerify() ok using key"); 46 "KeyBlockVerify() ok using key");
47 TEST_NEQ(KeyBlockVerify(hdr, hsize, NULL, 0), 0,
48 "KeyBlockVerify() missing key");
47 49
48 TEST_NEQ(KeyBlockVerify(hdr, hsize - 1, NULL), 0, "KeyBlockVerify() size--"); 50 TEST_NEQ(KeyBlockVerify(hdr, hsize - 1, NULL, 1), 0,
49 TEST_EQ(KeyBlockVerify(hdr, hsize + 1, NULL), 0, "KeyBlockVerify() size++"); 51 "KeyBlockVerify() size--");
52 TEST_EQ(KeyBlockVerify(hdr, hsize + 1, NULL, 1), 0,
53 "KeyBlockVerify() size++");
50 54
51 Memcpy(h, hdr, hsize); 55 Memcpy(h, hdr, hsize);
52 h->magic[0] &= 0x12; 56 h->magic[0] &= 0x12;
53 TEST_NEQ(KeyBlockVerify(h, hsize, NULL), 0, "KeyBlockVerify() magic"); 57 TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() magic");
54 58
55 /* Care about major version but not minor */ 59 /* Care about major version but not minor */
56 Memcpy(h, hdr, hsize); 60 Memcpy(h, hdr, hsize);
57 h->header_version_major++; 61 h->header_version_major++;
58 ReChecksumKeyBlock(h); 62 ReChecksumKeyBlock(h);
59 TEST_NEQ(KeyBlockVerify(h, hsize, NULL), 0, "KeyBlockVerify() major++"); 63 TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() major++");
60 64
61 Memcpy(h, hdr, hsize); 65 Memcpy(h, hdr, hsize);
62 h->header_version_major--; 66 h->header_version_major--;
63 ReChecksumKeyBlock(h); 67 ReChecksumKeyBlock(h);
64 TEST_NEQ(KeyBlockVerify(h, hsize, NULL), 0, "KeyBlockVerify() major--"); 68 TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() major--");
65 69
66 Memcpy(h, hdr, hsize); 70 Memcpy(h, hdr, hsize);
67 h->header_version_minor++; 71 h->header_version_minor++;
68 ReChecksumKeyBlock(h); 72 ReChecksumKeyBlock(h);
69 TEST_EQ(KeyBlockVerify(h, hsize, NULL), 0, "KeyBlockVerify() minor++"); 73 TEST_EQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() minor++");
70 74
71 Memcpy(h, hdr, hsize); 75 Memcpy(h, hdr, hsize);
72 h->header_version_minor--; 76 h->header_version_minor--;
73 ReChecksumKeyBlock(h); 77 ReChecksumKeyBlock(h);
74 TEST_EQ(KeyBlockVerify(h, hsize, NULL), 0, "KeyBlockVerify() minor--"); 78 TEST_EQ(KeyBlockVerify(h, hsize, NULL, 1), 0, "KeyBlockVerify() minor--");
75 79
76 /* Check hash */ 80 /* Check hash */
77 Memcpy(h, hdr, hsize); 81 Memcpy(h, hdr, hsize);
78 h->key_block_checksum.sig_offset = hsize; 82 h->key_block_checksum.sig_offset = hsize;
79 ReChecksumKeyBlock(h); 83 ReChecksumKeyBlock(h);
80 TEST_NEQ(KeyBlockVerify(h, hsize, NULL), 0, 84 TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
81 "KeyBlockVerify() checksum off end"); 85 "KeyBlockVerify() checksum off end");
82 86
83 Memcpy(h, hdr, hsize); 87 Memcpy(h, hdr, hsize);
84 h->key_block_checksum.sig_size /= 2; 88 h->key_block_checksum.sig_size /= 2;
85 ReChecksumKeyBlock(h); 89 ReChecksumKeyBlock(h);
86 TEST_NEQ(KeyBlockVerify(h, hsize, NULL), 0, 90 TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
87 "KeyBlockVerify() checksum too small"); 91 "KeyBlockVerify() checksum too small");
88 92
89 Memcpy(h, hdr, hsize); 93 Memcpy(h, hdr, hsize);
90 GetPublicKeyData(&h->data_key)[0] ^= 0x34; 94 GetPublicKeyData(&h->data_key)[0] ^= 0x34;
91 TEST_NEQ(KeyBlockVerify(h, hsize, NULL), 0, 95 TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
92 "KeyBlockVerify() checksum mismatch"); 96 "KeyBlockVerify() checksum mismatch");
93 97
94 /* Check signature */ 98 /* Check signature */
95 Memcpy(h, hdr, hsize); 99 Memcpy(h, hdr, hsize);
96 h->key_block_signature.sig_offset = hsize; 100 h->key_block_signature.sig_offset = hsize;
97 ReChecksumKeyBlock(h); 101 ReChecksumKeyBlock(h);
98 TEST_NEQ(KeyBlockVerify(h, hsize, public_key), 0, 102 TEST_NEQ(KeyBlockVerify(h, hsize, public_key, 0), 0,
99 "KeyBlockVerify() sig off end"); 103 "KeyBlockVerify() sig off end");
100 104
101 Memcpy(h, hdr, hsize); 105 Memcpy(h, hdr, hsize);
102 h->key_block_signature.sig_size--; 106 h->key_block_signature.sig_size--;
103 ReChecksumKeyBlock(h); 107 ReChecksumKeyBlock(h);
104 TEST_NEQ(KeyBlockVerify(h, hsize, public_key), 0, 108 TEST_NEQ(KeyBlockVerify(h, hsize, public_key, 0), 0,
105 "KeyBlockVerify() sig too small"); 109 "KeyBlockVerify() sig too small");
106 110
107 Memcpy(h, hdr, hsize); 111 Memcpy(h, hdr, hsize);
108 GetPublicKeyData(&h->data_key)[0] ^= 0x34; 112 GetPublicKeyData(&h->data_key)[0] ^= 0x34;
109 TEST_NEQ(KeyBlockVerify(h, hsize, public_key), 0, 113 TEST_NEQ(KeyBlockVerify(h, hsize, public_key, 0), 0,
110 "KeyBlockVerify() sig mismatch"); 114 "KeyBlockVerify() sig mismatch");
111 115
112 /* Check that we signed header and data key */ 116 /* Check that we signed header and data key */
113 Memcpy(h, hdr, hsize); 117 Memcpy(h, hdr, hsize);
114 h->key_block_checksum.data_size = 4; 118 h->key_block_checksum.data_size = 4;
115 h->data_key.key_offset = 0; 119 h->data_key.key_offset = 0;
116 h->data_key.key_size = 0; 120 h->data_key.key_size = 0;
117 ReChecksumKeyBlock(h); 121 ReChecksumKeyBlock(h);
118 TEST_NEQ(KeyBlockVerify(h, hsize, NULL), 0, 122 TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
119 "KeyBlockVerify() didn't sign header"); 123 "KeyBlockVerify() didn't sign header");
120 124
121 Memcpy(h, hdr, hsize); 125 Memcpy(h, hdr, hsize);
122 h->data_key.key_offset = hsize; 126 h->data_key.key_offset = hsize;
123 ReChecksumKeyBlock(h); 127 ReChecksumKeyBlock(h);
124 TEST_NEQ(KeyBlockVerify(h, hsize, NULL), 0, 128 TEST_NEQ(KeyBlockVerify(h, hsize, NULL, 1), 0,
125 "KeyBlockVerify() data key off end"); 129 "KeyBlockVerify() data key off end");
126 130
127 /* TODO: verify parser can support a bigger header (i.e., one where 131 /* TODO: verify parser can support a bigger header (i.e., one where
128 * data_key.key_offset is bigger than expected). */ 132 * data_key.key_offset is bigger than expected). */
129 133
130 Free(h); 134 Free(h);
131 Free(hdr); 135 Free(hdr);
132 } 136 }
133 137
134 138
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 292
289 if (signing_public_key) 293 if (signing_public_key)
290 Free(signing_public_key); 294 Free(signing_public_key);
291 if (signing_private_key) 295 if (signing_private_key)
292 Free(signing_private_key); 296 Free(signing_private_key);
293 if (data_public_key) 297 if (data_public_key)
294 Free(data_public_key); 298 Free(data_public_key);
295 299
296 return error_code; 300 return error_code;
297 } 301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698