OLD | NEW |
---|---|
(Empty) | |
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 | |
3 * found in the LICENSE file. | |
4 * | |
5 * Splicing tests for the kernel image verification library. | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 | |
11 #include "file_keys.h" | |
12 #include "kernel_image.h" | |
13 #include "padding.h" | |
14 #include "rsa_utility.h" | |
15 #include "test_common.h" | |
16 #include "utility.h" | |
17 | |
18 void VerifyKernelSplicingTest() | |
19 { | |
20 uint64_t len; | |
21 KernelImage* image1 = NULL; | |
22 KernelImage* image2 = NULL; | |
23 uint8_t* kernel_blob = NULL; | |
24 uint8_t* kernel_sign_key_buf = NULL; | |
25 RSAPublicKey* firmware_key = | |
26 RSAPublicKeyFromFile("testkeys/key_rsa2048.keyb"); | |
27 uint8_t* firmware_key_blob = BufferFromFile("testkeys/key_rsa2048.keyb", | |
28 &len); | |
Will Drewry
2010/03/29 23:03:40
spacing ;)
| |
29 kernel_sign_key_buf= BufferFromFile("testkeys/key_rsa1024.keyb", &len); | |
30 image1 = GenerateTestKernelImage(3, /* RSA2048/SHA1 */ | |
31 0, /* RSA1024/SHA1 */ | |
32 kernel_sign_key_buf, | |
33 1, /* Kernel Key Version. */ | |
34 1, /* Kernel Version */ | |
35 1000, /* Kernel Size. */ | |
36 "testkeys/key_rsa2048.pem", | |
37 "testkeys/key_rsa1024.pem", | |
38 (uint8_t) 'K'); /* Kernel data fill. */ | |
39 image2 = GenerateTestKernelImage(3, /* RSA2058/SHA1 */ | |
40 0, /* RSA1024/SHA1 */ | |
41 kernel_sign_key_buf, | |
42 1, /* Kernel Key Version. */ | |
43 2, /* Kernel Version */ | |
44 1000, /* Kernel Size */ | |
45 "testkeys/key_rsa2048.pem", | |
46 "testkeys/key_rsa1024.pem", | |
47 (uint8_t) 'K'); /* Kernel data fill. */ | |
48 /* Make sure the originals verify. */ | |
49 TEST_EQ(VerifyKernelImage(firmware_key, image1, 0), | |
50 VERIFY_KERNEL_SUCCESS, | |
51 "KernelImage kernel_data Original"); | |
52 TEST_EQ(VerifyKernelImage(firmware_key, image2, 0), | |
53 VERIFY_KERNEL_SUCCESS, | |
54 "KernelImage kernel_data Original"); | |
55 | |
56 /* Splice kernel_data + kernel signature from [image1] | |
57 * and put it into [image2]. */ | |
58 Memcpy(image2->kernel_signature, image1->kernel_signature, | |
59 siglen_map[0]); | |
60 Memcpy(image2->kernel_data, image1->kernel_data, | |
61 image2->options.kernel_len); | |
62 | |
63 TEST_EQ(VerifyKernelImage(firmware_key, image2, 0), | |
64 VERIFY_KERNEL_SIGNATURE_FAILED, | |
65 "KernelImage kernel_data Splicing"); | |
66 kernel_blob = GetKernelBlob(image2, &len); | |
67 TEST_EQ(VerifyKernel(firmware_key_blob, kernel_blob, 0), | |
68 VERIFY_KERNEL_SIGNATURE_FAILED, | |
69 "Kernel Blob kernel_data Splicing"); | |
70 } | |
71 | |
72 int main(int argc, char* argv[]) | |
73 { | |
74 int error_code = 0; | |
75 VerifyKernelSplicingTest(); | |
76 if (!gTestSuccess) | |
77 error_code = 255; | |
78 return error_code; | |
79 } | |
OLD | NEW |