Data structure and interface for manipulating and handing firmware images for verified boot.

Review URL: http://codereview.chromium.org/564020
This commit is contained in:
Gaurav Shah
2010-02-12 15:54:37 -08:00
parent 1a055adf7b
commit 431b98886e
10 changed files with 872 additions and 41 deletions

57
utils/file_keys.c Normal file
View File

@@ -0,0 +1,57 @@
/* 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 functions for file and key handling.
*/
#include "file_keys.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "rsa_utility.h"
#include "utility.h"
uint8_t* BufferFromFile(char* input_file, int* len) {
int fd;
struct stat stat_fd;
uint8_t* buf = NULL;
if ((fd = open(input_file, O_RDONLY)) == -1) {
fprintf(stderr, "Couldn't open file.\n");
return NULL;
}
if (-1 == fstat(fd, &stat_fd)) {
fprintf(stderr, "Couldn't stat key file\n");
return NULL;
}
*len = stat_fd.st_size;
/* Read entire key binary blob into a buffer. */
buf = (uint8_t*) Malloc(*len);
if (!buf)
return NULL;
if (*len != read(fd, buf, *len)) {
fprintf(stderr, "Couldn't read key into a buffer.\n");
return NULL;
}
close(fd);
return buf;
}
RSAPublicKey* RSAPublicKeyFromFile(char* input_file) {
int len;
uint8_t* buf = BufferFromFile(input_file, &len);
RSAPublicKey* key = RSAPublicKeyFromBuf(buf, len);
Free(buf);
return key;
}