Files
OpenCellular/host/lib/host_misc.c
Bill Richardson 60bcbe3cd4 New tools to help debug vboot failures.
This adds some tools to help us figure out why a particular kernel isn't
booting. Often we suspect it's because it was signed with the wrong keys, or
has flags restricting its use to certain boot modes. This change adds some
tools to extract and display all the keys from the BIOS, and try them on the
various kernels. We also display the sha1sum of all the keys we find, to
make comparing them easier.

Change-Id: I38e447bf95cb6c3a0b87aa949611bb135f2f94b4

BUG=chromeos-partner:888
TEST=manual

To test, obtain a root shell, and run dev_debug_vboot. You should see lots
of useful information go by.

Review URL: http://codereview.chromium.org/3303018
2010-09-09 14:53:56 -07:00

79 lines
1.6 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.
*
* Host functions for verified boot.
*/
/* TODO: change all 'return 0', 'return 1' into meaningful return codes */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "host_common.h"
#include "cryptolib.h"
#include "utility.h"
#include "vboot_common.h"
uint8_t* ReadFile(const char* filename, uint64_t* size) {
FILE* f;
uint8_t* buf;
f = fopen(filename, "rb");
if (!f) {
VBDEBUG(("Unable to open file %s\n", filename));
return NULL;
}
fseek(f, 0, SEEK_END);
*size = ftell(f);
rewind(f);
buf = Malloc(*size);
if (!buf) {
fclose(f);
return NULL;
}
if(1 != fread(buf, *size, 1, f)) {
VBDEBUG(("Unable to read from file %s\n", filename));
fclose(f);
Free(buf);
return NULL;
}
fclose(f);
return buf;
}
int WriteFile(const char* filename, const void *data, uint64_t size) {
FILE *f = fopen(filename, "wb");
if (!f) {
VBDEBUG(("Unable to open file %s\n", filename));
return 1;
}
if (1 != fwrite(data, size, 1, f)) {
VBDEBUG(("Unable to write to file %s\n", filename));
fclose(f);
unlink(filename); /* Delete any partial file */
}
fclose(f);
return 0;
}
void PrintPubKeySha1Sum(VbPublicKey* key) {
uint8_t* buf = ((uint8_t *)key) + key->key_offset;
uint64_t buflen = key->key_size;
uint8_t* digest = DigestBuf(buf, buflen, SHA1_DIGEST_ALGORITHM);
int i;
for (i=0; i<SHA1_DIGEST_SIZE; i++)
printf("%02x", digest[i]);
Free(digest);
}