summaryrefslogtreecommitdiff
path: root/tests/verify_kernel_fuzz_driver.c
diff options
context:
space:
mode:
authorGaurav Shah <gauravsh@chromium.org>2010-03-17 20:40:23 -0700
committerGaurav Shah <gauravsh@chromium.org>2010-03-17 20:40:23 -0700
commitccaa90f73568653bd11998df3b5a42257bccffd6 (patch)
treeefc201631b177ee6887a4bf879924b9eefa025b7 /tests/verify_kernel_fuzz_driver.c
parent4f393869029cae57aeaab0ee093c7c69b8b649a2 (diff)
downloadvboot-ccaa90f73568653bd11998df3b5a42257bccffd6.tar.gz
Add fuzz testing driver programs for kernel and firmware verification.
The driver programs are useful in quick and dirty fuzz testing of the verification code with blind smartfuzzers like Bunny (http://code.google.com/p/bunny-the-fuzzer/). Also fixes a bug with image generation in kernel_utility. Tests: All existing tests still pass. VerifyKernel() and VerifyFirmware() can successfully verify images generated by {firmware|kernel}_utility. Review URL: http://codereview.chromium.org/975007
Diffstat (limited to 'tests/verify_kernel_fuzz_driver.c')
-rw-r--r--tests/verify_kernel_fuzz_driver.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/verify_kernel_fuzz_driver.c b/tests/verify_kernel_fuzz_driver.c
new file mode 100644
index 00000000..10272638
--- /dev/null
+++ b/tests/verify_kernel_fuzz_driver.c
@@ -0,0 +1,56 @@
+/* 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.
+ *
+ * Utility for aiding fuzz testing of kernel image verification code.
+ */
+
+#include <stdio.h>
+
+#include "file_keys.h"
+#include "kernel_image.h"
+#include "utility.h"
+
+int VerifySignedKernel(const char* image_file,
+ const char* firmware_key_file) {
+ int error, error_code = 0;
+ uint64_t len;
+ uint8_t* kernel_blob = BufferFromFile(image_file, &len);
+ uint8_t* firmware_key_blob = BufferFromFile(firmware_key_file, &len);
+
+ if (!firmware_key_blob) {
+ fprintf(stderr, "Couldn't read pre-processed public firmware key.\n");
+ error_code = 1;
+ }
+
+ if (!error_code && !kernel_blob) {
+ fprintf(stderr, "Couldn't read kernel image or malformed image.\n");
+ error_code = 1;
+ }
+
+ if (!error_code && (error = VerifyKernel(firmware_key_blob, kernel_blob,
+ 0))) { /* Trusted Mode. */
+ fprintf(stderr, "%s\n", VerifyKernelErrorString(error));
+ error_code = 1;
+ }
+ Free(firmware_key_blob);
+ Free(kernel_blob);
+ if (error_code)
+ return 0;
+ return 1;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s <image_to_verify> <firmware_keyb>\n", argv[0]);
+ return -1;
+ }
+ if (VerifySignedKernel(argv[1], argv[2])) {
+ fprintf(stderr, "Verification SUCCESS!\n");
+ return 0;
+ }
+ else {
+ fprintf(stderr, "Verification FAILURE!\n");
+ return -1;
+ }
+}