Files
OpenCellular/host/lib/host_misc.c
Bill Richardson abf0550458 Switch to using .vbprivk for signing everything now.
This makes it much simpler to keep track of what we're doing.

vbutil_key can now wrap both .keyb and .pem keys. It figures out which is
which by trying both and just using the one that works.

vbutil_keyblock and vbutil_kernel now use .vbprivk files for signing.

replace debug() with VBDEBUG(()) in host-side sources, too.

rename PrivateKeyRead to PrivateKeyReadPem

Add real PrivateKeyRead and PrivateKeyWrite for .vbprivk files.

Review URL: http://codereview.chromium.org/2871033
2010-07-01 10:22:06 -07:00

69 lines
1.3 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;
}