Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: host/lib/host_key.c

Issue 2812034: Adding --repack and --headeronly options to vbutil_kernel (Closed) Base URL: ssh://git@chromiumos-git//vboot_reference.git
Patch Set: oops. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « host/include/host_key.h ('k') | host/linktest/main.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Host functions for keys. 5 * Host functions for keys.
6 */ 6 */
7 7
8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ 8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */
9 9
10 #define OPENSSL_NO_SHA 10 #define OPENSSL_NO_SHA
11 #include <openssl/engine.h> 11 #include <openssl/engine.h>
12 #include <openssl/pem.h> 12 #include <openssl/pem.h>
13 #include <openssl/rsa.h> 13 #include <openssl/rsa.h>
14 14
15 #include <stdio.h> 15 #include <stdio.h>
16 #include <stdlib.h> 16 #include <stdlib.h>
17 #include <unistd.h> 17 #include <unistd.h>
18 18
19 #include "host_key.h" 19 #include "host_key.h"
20 20
21 #include "cryptolib.h" 21 #include "cryptolib.h"
22 #include "host_misc.h" 22 #include "host_misc.h"
23 #include "utility.h" 23 #include "utility.h"
24 #include "vboot_common.h" 24 #include "vboot_common.h"
25 25
26 26
27 VbPrivateKey* PrivateKeyRead(const char* filename, uint64_t algorithm) { 27 VbPrivateKey* PrivateKeyReadPem(const char* filename, uint64_t algorithm) {
28 28
29 VbPrivateKey* key; 29 VbPrivateKey* key;
30 RSA* rsa_key; 30 RSA* rsa_key;
31 FILE* f; 31 FILE* f;
32 32
33 if (algorithm >= kNumAlgorithms) { 33 if (algorithm >= kNumAlgorithms) {
34 debug("PrivateKeyRead() called with invalid algorithm!\n"); 34 debug("%s() called with invalid algorithm!\n", __FUNCTION__);
35 return NULL; 35 return NULL;
36 } 36 }
37 37
38 /* Read private key */ 38 /* Read private key */
39 f = fopen(filename, "r"); 39 f = fopen(filename, "r");
40 if (!f) { 40 if (!f) {
41 debug("PrivateKeyRead(): Couldn't open key file: %s\n", filename); 41 debug("%s(): Couldn't open key file: %s\n", __FUNCTION__, filename);
42 return NULL; 42 return NULL;
43 } 43 }
44 rsa_key = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL); 44 rsa_key = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL);
45 fclose(f); 45 fclose(f);
46 if (!rsa_key) { 46 if (!rsa_key) {
47 debug("PrivateKeyRead(): Couldn't read private key from file: %s\n", 47 debug("%s(): Couldn't read private key from file: %s\n", __FUNCTION__,
48 filename); 48 filename);
49 return NULL; 49 return NULL;
50 } 50 }
51 51
52 /* Store key and algorithm in our struct */ 52 /* Store key and algorithm in our struct */
53 key = (VbPrivateKey*)Malloc(sizeof(VbPrivateKey)); 53 key = (VbPrivateKey*)Malloc(sizeof(VbPrivateKey));
54 if (!key) { 54 if (!key) {
55 RSA_free(rsa_key); 55 RSA_free(rsa_key);
56 return NULL; 56 return NULL;
57 } 57 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (0 != PublicKeyCopy(kcopy, key)) { 174 if (0 != PublicKeyCopy(kcopy, key)) {
175 Free(kcopy); 175 Free(kcopy);
176 return 1; 176 return 1;
177 } 177 }
178 178
179 /* Write the copy, then free it */ 179 /* Write the copy, then free it */
180 rv = WriteFile(filename, kcopy, kcopy->key_offset + kcopy->key_size); 180 rv = WriteFile(filename, kcopy, kcopy->key_offset + kcopy->key_size);
181 Free(kcopy); 181 Free(kcopy);
182 return rv; 182 return rv;
183 } 183 }
OLDNEW
« no previous file with comments | « host/include/host_key.h ('k') | host/linktest/main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698