Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | |
| 2 * Use of this source code is governed by a BSD-style license that can be | |
| 3 * found in the LICENSE file. | |
| 4 * | |
| 5 * Functions for updating the TPM state with the status of boot path. | |
| 6 */ | |
| 7 | |
| 8 #include "tpm_bootmode.h" | |
| 9 | |
| 10 #include "tlcl.h" | |
| 11 #include "utility.h" | |
| 12 | |
| 13 /* TPM PCR to use for storing boot mode measurements. */ | |
| 14 #define BOOT_MODE_PCR 0 | |
| 15 | |
| 16 /* Input digests for PCR extend. | |
| 17 * These are calculated as: | |
| 18 * SHA1("|Developer_Mode||Recovery_Mode||Keyblock_Mode|"). | |
| 19 * Developer_Mode can be 0 or 1. | |
| 20 * Recovery_Mode can be 0 or 1. | |
| 21 * Keyblock flags are defined in vboot_struct.h | |
| 22 * | |
| 23 * We map them to Keyblock_Mode as follows: | |
| 24 * ----------------------------------------- | |
| 25 * Keyblock Flags | Keyblock Mode | |
| 26 * ----------------------------------------- | |
| 27 * 6 (Dev-signed firmware) | 2 | |
| 28 * 7 Normal-signed firmware | 1 | |
| 29 * (anything else) | 0 | |
| 30 */ | |
| 31 const uint8_t kBootStateSHA1Digests[][20] = { | |
| 32 /* SHA1("\x00\x00\x00") */ | |
| 33 "\x29\xe2\xdc\xfb\xb1\x6f\x63\xbb\x02\x54\xdf\x75\x85\xa1\x5b\xb6" | |
| 34 "\xfb\x5e\x92\x7d", | |
| 35 | |
| 36 /* SHA1("\x00\x00\x01") */ | |
| 37 "\x25\x47\xcc\x73\x6e\x95\x1f\xa4\x91\x98\x53\xc4\x3a\xe8\x90\x86" | |
| 38 "\x1a\x3b\x32\x64", | |
| 39 | |
| 40 /* SHA1("\x00\x00\x02") */ | |
| 41 "\x1e\xf6\x24\x48\x2d\x62\x0e\x43\xe6\xd3\x4d\xa1\xaf\xe4\x62\x67" | |
| 42 "\xfc\x69\x5d\x9b", | |
| 43 | |
| 44 /* SHA1("\x00\x01\x00") */ | |
| 45 "\x62\x57\x18\x91\x21\x5b\x4e\xfc\x1c\xea\xb7\x44\xce\x59\xdd\x0b" | |
| 46 "\x66\xea\x6f\x73", | |
| 47 | |
| 48 /* SHA1("\x00\x01\x01") */ | |
| 49 "\xee\xe4\x47\xed\xc7\x9f\xea\x1c\xa7\xc7\xd3\x4e\x46\x32\x61\xcd" | |
| 50 "\xa4\xba\x33\x9e", | |
| 51 | |
| 52 /* SHA1("\x00\x01\x02") */ | |
| 53 "\x0c\x7a\x62\x3f\xd2\xbb\xc0\x5b\x06\x42\x3b\xe3\x59\xe4\x02\x1d" | |
| 54 "\x36\xe7\x21\xad", | |
| 55 | |
| 56 /* SHA1("\x01\x00\x00") */ | |
| 57 "\x95\x08\xe9\x05\x48\xb0\x44\x0a\x4a\x61\xe5\x74\x3b\x76\xc1\xe3" | |
| 58 "\x09\xb2\x3b\x7f", | |
| 59 | |
| 60 /* SHA1("\x01\x00\x01") */ | |
| 61 "\xc4\x2a\xc1\xc4\x6f\x1d\x4e\x21\x1c\x73\x5c\xc7\xdf\xad\x4f\xf8" | |
| 62 "\x39\x11\x10\xe9", | |
| 63 | |
| 64 /* SHA1("\x01\x00\x02") */ | |
| 65 "\xfa\x01\x0d\x26\x64\xcc\x5b\x3b\x82\xee\x48\x8f\xe2\xb9\xf5\x0f" | |
| 66 "\x49\x32\xeb\x8f", | |
| 67 | |
| 68 /* SHA1("\x01\x01\x00") */ | |
| 69 "\x47\xec\x8d\x98\x36\x64\x33\xdc\x00\x2e\x77\x21\xc9\xe3\x7d\x50" | |
| 70 "\x67\x54\x79\x37", | |
| 71 | |
| 72 /* SHA1("\x01\x01\x01") */ | |
| 73 "\x28\xd8\x6c\x56\xb3\xbf\x26\xd2\x36\x56\x9b\x8d\xc8\xc3\xf9\x1f" | |
| 74 "\x32\xf4\x7b\xc7", | |
| 75 | |
| 76 /* SHA1("\x01\x01\x02") */ | |
| 77 "\x12\xa3\x40\xd7\x89\x7f\xe7\x13\xfc\x8f\x02\xac\x53\x65\xb8\x6e" | |
| 78 "\xbf\x35\x31\x78", | |
| 79 }; | |
| 80 | |
| 81 #define MAX_BOOT_STATE_INDEX (sizeof(kBootStateSHA1Digests)/sizeof(char[20])) | |
| 82 | |
| 83 /* Used for PCR extend when passed in boot state if invalid or | |
|
Randall Spangler
2011/03/15 23:26:11
/if/is
| |
| 84 * there is an internal error. */ | |
| 85 const uint8_t kBootInvalidSHA1Digest[20] = { | |
| 86 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" | |
| 87 "\xff\xff\xff\xff" | |
| 88 }; | |
| 89 | |
| 90 /* Given the boot state, return the correct SHA1 digest index for TPMExtend | |
| 91 * in kBootStateSHA1Digests[]. */ | |
| 92 int GetBootStateIndex(int dev_mode, int rec_mode, int keyblock_flags) { | |
| 93 int index = 0; | |
| 94 | |
| 95 /* Convert keyblock flags into keyblock mode which we use to index into | |
| 96 * kBootStateSHA1Digest[]. */ | |
| 97 switch(keyblock_flags) { | |
| 98 case 6: /* KEY_BLOCK_FLAG_RECOVERY_0 | KEY_BLOCK_FLAG_DEVELOPER_1 */ | |
| 99 /* Developer firmware. */ | |
| 100 index = 2; | |
| 101 break; | |
| 102 case 7: /* KEY_BLOCK_FLAG_RECOVERY_0 | KEY_BLOCK_FLAG_DEVELOPER_0 | |
| 103 * | KEY_BLOCK_FLAGS_DEVELOPER_1 */ | |
| 104 index = 1; | |
| 105 break; | |
| 106 default: | |
| 107 index = 0; /* Any other keyblock flags. */ | |
| 108 }; | |
| 109 | |
| 110 if (rec_mode) | |
| 111 index += 3; | |
| 112 if (dev_mode) | |
| 113 index += 6; | |
| 114 return index; | |
| 115 } | |
| 116 | |
| 117 uint32_t SetTPMBootModeState(int developer_mode, int recovery_mode, | |
| 118 int fw_keyblock_flags) { | |
| 119 uint32_t result; | |
| 120 const uint8_t* in_digest = NULL; | |
| 121 uint8_t out_digest[20]; /* For PCR extend output. */ | |
| 122 int digest_index = GetBootStateIndex(developer_mode, recovery_mode, | |
| 123 fw_keyblock_flags); | |
| 124 | |
| 125 if (digest_index >= 0 && digest_index < MAX_BOOT_STATE_INDEX) | |
| 126 in_digest = kBootStateSHA1Digests[digest_index]; | |
| 127 else | |
| 128 in_digest = kBootInvalidSHA1Digest; /* Internal out of bounds error. */ | |
| 129 result = TlclExtend(BOOT_MODE_PCR, in_digest, out_digest); | |
| 130 VBDEBUG(("TPM: SetTPMBootModeState boot mode PCR out_digest %02x %02x %02x " | |
| 131 "%02x\n", out_digest, out_digest+1, out_digest+2, out_digest+3)); | |
| 132 return result; | |
| 133 } | |
| OLD | NEW |