Randall Spangler | 32a6526 | 2011-06-27 10:49:11 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | * |
| 5 | * Host functions for keys. |
| 6 | */ |
| 7 | |
| 8 | /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ |
| 9 | |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 10 | #include <openssl/pem.h> |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <unistd.h> |
| 15 | |
Randall Spangler | f7559e4 | 2016-06-23 13:45:59 -0700 | [diff] [blame] | 16 | #include "2sysincludes.h" |
| 17 | #include "2common.h" |
| 18 | #include "2rsa.h" |
| 19 | #include "2sha.h" |
Randall Spangler | 32a6526 | 2011-06-27 10:49:11 -0700 | [diff] [blame] | 20 | #include "host_common.h" |
Randall Spangler | d55c645 | 2010-06-10 12:43:51 -0700 | [diff] [blame] | 21 | #include "host_misc.h" |
Randall Spangler | 98263a1 | 2016-06-02 16:05:49 -0700 | [diff] [blame] | 22 | #include "vb2_common.h" |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 23 | #include "vboot_common.h" |
| 24 | |
Randall Spangler | 98263a1 | 2016-06-02 16:05:49 -0700 | [diff] [blame] | 25 | int packed_key_looks_ok(const struct vb2_packed_key *key, uint32_t size) |
Bill Richardson | f16ed87 | 2014-08-27 15:37:47 -0700 | [diff] [blame] | 26 | { |
Randall Spangler | f7559e4 | 2016-06-23 13:45:59 -0700 | [diff] [blame] | 27 | struct vb2_public_key pubkey; |
Randall Spangler | 6e3931d | 2016-10-18 15:09:21 -0700 | [diff] [blame^] | 28 | if (VB2_SUCCESS != vb2_unpack_key_buffer(&pubkey, |
| 29 | (const uint8_t *)key, |
| 30 | size)) |
Randall Spangler | 98263a1 | 2016-06-02 16:05:49 -0700 | [diff] [blame] | 31 | return 0; |
Bill Richardson | f16ed87 | 2014-08-27 15:37:47 -0700 | [diff] [blame] | 32 | |
Randall Spangler | f7559e4 | 2016-06-23 13:45:59 -0700 | [diff] [blame] | 33 | if (key->key_version > VB2_MAX_KEY_VERSION) { |
| 34 | /* Currently, TPM only supports 16-bit version */ |
| 35 | VB2_DEBUG("%s() - packed key invalid version\n", __func__); |
Randall Spangler | 98263a1 | 2016-06-02 16:05:49 -0700 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | /* Success */ |
| 40 | return 1; |
Bill Richardson | f16ed87 | 2014-08-27 15:37:47 -0700 | [diff] [blame] | 41 | } |