| OLD | NEW |
| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (!TEST_EQ(VerifyFirmware(root_key, image, DEV_MODE_DISABLED), | 129 if (!TEST_EQ(VerifyFirmware(root_key, image, DEV_MODE_DISABLED), |
| 130 VERIFY_ROOT_SIGNATURE_FAILED, | 130 VERIFY_ROOT_SIGNATURE_FAILED, |
| 131 "Root Signature Tamper Verification (Trusted)")) | 131 "Root Signature Tamper Verification (Trusted)")) |
| 132 success = 0; | 132 success = 0; |
| 133 | 133 |
| 134 return success; | 134 return success; |
| 135 } | 135 } |
| 136 | 136 |
| 137 int main(int argc, char* argv[]) { | 137 int main(int argc, char* argv[]) { |
| 138 int len; | 138 int len; |
| 139 uint8_t* sign_key_buf; | 139 uint8_t* sign_key_buf = NULL; |
| 140 FirmwareImage* image; | 140 FirmwareImage* image = NULL; |
| 141 RSAPublicKey* root_key; | 141 RSAPublicKey* root_key = NULL; |
| 142 int success = 1; | 142 int error_code = 1; |
| 143 | 143 |
| 144 if(argc != 6) { | 144 if(argc != 6) { |
| 145 fprintf(stderr, "Usage: %s <algorithm> <root key> <processed root pubkey>" | 145 fprintf(stderr, "Usage: %s <algorithm> <root key> <processed root pubkey>" |
| 146 " <signing key> <processed signing key>\n", argv[0]); | 146 " <signing key> <processed signing key>\n", argv[0]); |
| 147 return -1; | 147 return -1; |
| 148 } | 148 } |
| 149 | 149 |
| 150 /* Read verification keys and create a test image. */ | 150 /* Read verification keys and create a test image. */ |
| 151 root_key = RSAPublicKeyFromFile(argv[3]); | 151 root_key = RSAPublicKeyFromFile(argv[3]); |
| 152 sign_key_buf = BufferFromFile(argv[5], &len); | 152 sign_key_buf = BufferFromFile(argv[5], &len); |
| 153 image = GenerateTestFirmwareImage(atoi(argv[1]), sign_key_buf, 1, | 153 image = GenerateTestFirmwareImage(atoi(argv[1]), sign_key_buf, 1, |
| 154 1, 1000); | 154 1, 1000); |
| 155 | 155 |
| 156 if (!root_key || !sign_key_buf || !image) { |
| 157 error_code = 1; |
| 158 goto failure; |
| 159 } |
| 160 |
| 156 /* Generate and populate signatures. */ | 161 /* Generate and populate signatures. */ |
| 157 if (!AddKeySignature(image, argv[2])) { | 162 if (!AddKeySignature(image, argv[2])) { |
| 158 fprintf(stderr, "Couldn't create key signature.\n"); | 163 fprintf(stderr, "Couldn't create key signature.\n"); |
| 159 return -1; | 164 error_code = 1; |
| 165 goto failure; |
| 160 } | 166 } |
| 161 | 167 |
| 162 if (!AddFirmwareSignature(image, argv[4], image->sign_algorithm)) { | 168 if (!AddFirmwareSignature(image, argv[4], image->sign_algorithm)) { |
| 163 fprintf(stderr, "Couldn't create firmware and preamble signature.\n"); | 169 fprintf(stderr, "Couldn't create firmware and preamble signature.\n"); |
| 164 return -1; | 170 error_code = 1; |
| 171 goto failure; |
| 165 } | 172 } |
| 166 | 173 |
| 167 if (!VerifyFirmwareTest(image, root_key)) | 174 if (!VerifyFirmwareTest(image, root_key)) |
| 168 success = 0; | 175 error_code = 255; |
| 169 if (!VerifyFirmwareTamperTest(image, root_key)) | 176 if (!VerifyFirmwareTamperTest(image, root_key)) |
| 170 success = 0; | 177 error_code = 255; |
| 171 | 178 |
| 172 /* Clean up. */ | 179 failure: |
| 173 Free(root_key); | 180 Free(root_key); |
| 174 Free(sign_key_buf); | 181 Free(sign_key_buf); |
| 175 Free(image); | 182 Free(image); |
| 176 | 183 |
| 177 return !success; | 184 return error_code; |
| 178 } | 185 } |
| OLD | NEW |