mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 18:25:10 +00:00
Vboot Reference: Make firmware image verification test handle errors gracefully.
The test should bail immediately on an unrecoverable error. Review URL: http://codereview.chromium.org/647027
This commit is contained in:
@@ -136,10 +136,10 @@ int VerifyFirmwareTamperTest(FirmwareImage* image, RSAPublicKey* root_key) {
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
int len;
|
int len;
|
||||||
uint8_t* sign_key_buf;
|
uint8_t* sign_key_buf = NULL;
|
||||||
FirmwareImage* image;
|
FirmwareImage* image = NULL;
|
||||||
RSAPublicKey* root_key;
|
RSAPublicKey* root_key = NULL;
|
||||||
int success = 1;
|
int error_code = 1;
|
||||||
|
|
||||||
if(argc != 6) {
|
if(argc != 6) {
|
||||||
fprintf(stderr, "Usage: %s <algorithm> <root key> <processed root pubkey>"
|
fprintf(stderr, "Usage: %s <algorithm> <root key> <processed root pubkey>"
|
||||||
@@ -153,26 +153,33 @@ int main(int argc, char* argv[]) {
|
|||||||
image = GenerateTestFirmwareImage(atoi(argv[1]), sign_key_buf, 1,
|
image = GenerateTestFirmwareImage(atoi(argv[1]), sign_key_buf, 1,
|
||||||
1, 1000);
|
1, 1000);
|
||||||
|
|
||||||
|
if (!root_key || !sign_key_buf || !image) {
|
||||||
|
error_code = 1;
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
/* Generate and populate signatures. */
|
/* Generate and populate signatures. */
|
||||||
if (!AddKeySignature(image, argv[2])) {
|
if (!AddKeySignature(image, argv[2])) {
|
||||||
fprintf(stderr, "Couldn't create key signature.\n");
|
fprintf(stderr, "Couldn't create key signature.\n");
|
||||||
return -1;
|
error_code = 1;
|
||||||
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AddFirmwareSignature(image, argv[4], image->sign_algorithm)) {
|
if (!AddFirmwareSignature(image, argv[4], image->sign_algorithm)) {
|
||||||
fprintf(stderr, "Couldn't create firmware and preamble signature.\n");
|
fprintf(stderr, "Couldn't create firmware and preamble signature.\n");
|
||||||
return -1;
|
error_code = 1;
|
||||||
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!VerifyFirmwareTest(image, root_key))
|
if (!VerifyFirmwareTest(image, root_key))
|
||||||
success = 0;
|
error_code = 255;
|
||||||
if (!VerifyFirmwareTamperTest(image, root_key))
|
if (!VerifyFirmwareTamperTest(image, root_key))
|
||||||
success = 0;
|
error_code = 255;
|
||||||
|
|
||||||
/* Clean up. */
|
failure:
|
||||||
Free(root_key);
|
Free(root_key);
|
||||||
Free(sign_key_buf);
|
Free(sign_key_buf);
|
||||||
Free(image);
|
Free(image);
|
||||||
|
|
||||||
return !success;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user