Files
OpenCellular/tests/kernel_splicing_tests.c
Gaurav Shah bd52fc793a VBoot Reference: Make kernel_config a 4K byte block, and move it after the verified boot block.
The kernel_config is now stored as a 4K binary block instead of the kconfig_options structure that was being used before. Since the verified boot code doesn't care what kernel config options are (other than the length of the kernel image and for verifying them before the rest of kernel), it is ok to keep them as a blackbox.

This CL also changes the verified boot kernel layout - VBlock Data followed by Kernel Config followed by the Kernel Image. This will allow them to be stored separately, or as a concatenated block (for easy memory mapping during kernel load). This should ease the process of generating a layout for verified boot kernel images which is also compatible with legacy BIOSes that don't support this mechanism.

Finally, there is also a new firmware API function to determine the size of a kernel verified boot block, given a pointer to its beginning (for determining the offset to the kernel config and data).

Review URL: http://codereview.chromium.org/1732022
2010-04-29 15:30:25 -07:00

85 lines
3.2 KiB
C

/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Splicing tests for the kernel image verification library.
*/
#include <stdio.h>
#include <stdlib.h>
#include "cryptolib.h"
#include "file_keys.h"
#include "kernel_image.h"
#include "test_common.h"
#include "utility.h"
#define FIRMWARE_KEY_BASE_NAME "testkeys/key_rsa2048"
#define KERNEL_KEY_BASE_NAME "testkeys/key_rsa1024"
const char* kFirmwareKeyPublicFile = FIRMWARE_KEY_BASE_NAME ".keyb";
const char* kFirmwareKeyFile = FIRMWARE_KEY_BASE_NAME ".pem";
const char* kKernelKeyPublicFile = KERNEL_KEY_BASE_NAME ".keyb";
const char* kKernelKeyFile = KERNEL_KEY_BASE_NAME ".pem";
void VerifyKernelSplicingTest()
{
uint64_t len;
KernelImage* image1 = NULL;
KernelImage* image2 = NULL;
uint8_t* kernel_blob = NULL;
uint8_t* kernel_sign_key_buf = NULL;
RSAPublicKey* firmware_key = RSAPublicKeyFromFile(kFirmwareKeyPublicFile);
uint8_t* firmware_key_blob = BufferFromFile(kFirmwareKeyPublicFile, &len);
kernel_sign_key_buf= BufferFromFile(kKernelKeyPublicFile, &len);
image1 = GenerateTestKernelImage(3, /* RSA2048/SHA1 */
0, /* RSA1024/SHA1 */
kernel_sign_key_buf,
1, /* Kernel Key Version. */
1, /* Kernel Version */
1000, /* Kernel Size. */
kFirmwareKeyFile,
kKernelKeyFile,
'K'); /* Kernel data fill. */
image2 = GenerateTestKernelImage(3, /* RSA2058/SHA1 */
0, /* RSA1024/SHA1 */
kernel_sign_key_buf,
1, /* Kernel Key Version. */
2, /* Kernel Version */
1000, /* Kernel Size */
kFirmwareKeyFile,
kKernelKeyFile,
'L'); /* Different Kernel data fill. */
/* Make sure the originals verify. */
TEST_EQ(VerifyKernelImage(firmware_key, image1, 0),
VERIFY_KERNEL_SUCCESS,
"KernelImage kernel_data Original");
TEST_EQ(VerifyKernelImage(firmware_key, image2, 0),
VERIFY_KERNEL_SUCCESS,
"KernelImage kernel_data Original");
/* Splice kernel_data + kernel signature from [image1]
* and put it into [image2]. */
Memcpy(image2->kernel_signature, image1->kernel_signature,
siglen_map[0]);
Memcpy(image2->kernel_data, image1->kernel_data,
image2->kernel_len);
TEST_EQ(VerifyKernelImage(firmware_key, image2, 0),
VERIFY_KERNEL_SIGNATURE_FAILED,
"KernelImage kernel_data Splicing");
kernel_blob = GetKernelBlob(image2, &len);
TEST_EQ(VerifyKernel(firmware_key_blob, kernel_blob, 0),
VERIFY_KERNEL_SIGNATURE_FAILED,
"Kernel Blob kernel_data Splicing");
}
int main(int argc, char* argv[])
{
int error_code = 0;
VerifyKernelSplicingTest();
if (!gTestSuccess)
error_code = 255;
return error_code;
}