| OLD | NEW |
| 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 * Common functions between firmware and kernel verified boot. | 5 * Common functions between firmware and kernel verified boot. |
| 6 * (Firmware portion) | 6 * (Firmware portion) |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "vboot_common.h" | 10 #include "vboot_common.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 if (VerifySignatureInside(block, block->key_block_size, sig)) { | 188 if (VerifySignatureInside(block, block->key_block_size, sig)) { |
| 189 VBDEBUG(("Key block signature off end of block\n")); | 189 VBDEBUG(("Key block signature off end of block\n")); |
| 190 return VBOOT_KEY_BLOCK_INVALID; | 190 return VBOOT_KEY_BLOCK_INVALID; |
| 191 } | 191 } |
| 192 | 192 |
| 193 rsa = PublicKeyToRSA(key); | 193 rsa = PublicKeyToRSA(key); |
| 194 if (!rsa) { | 194 if (!rsa) { |
| 195 VBDEBUG(("Invalid public key\n")); | 195 VBDEBUG(("Invalid public key\n")); |
| 196 return VBOOT_PUBLIC_KEY_INVALID; | 196 return VBOOT_PUBLIC_KEY_INVALID; |
| 197 } | 197 } |
| 198 |
| 199 /* Make sure advertised signature data sizes are sane. */ |
| 200 if (block->key_block_size < sig->data_size) { |
| 201 VBDEBUG(("Signature calculated past end of the block\n")); |
| 202 return VBOOT_KEY_BLOCK_INVALID; |
| 203 } |
| 198 rv = VerifyData((const uint8_t*)block, sig, rsa); | 204 rv = VerifyData((const uint8_t*)block, sig, rsa); |
| 199 RSAPublicKeyFree(rsa); | 205 RSAPublicKeyFree(rsa); |
| 200 if (rv) | 206 if (rv) |
| 201 return VBOOT_KEY_BLOCK_SIGNATURE; | 207 return VBOOT_KEY_BLOCK_SIGNATURE; |
| 202 | |
| 203 } else { | 208 } else { |
| 204 /* Check hash */ | 209 /* Check hash */ |
| 205 uint8_t* header_checksum = NULL; | 210 uint8_t* header_checksum = NULL; |
| 206 int rv; | 211 int rv; |
| 207 | 212 |
| 208 sig = &block->key_block_checksum; | 213 sig = &block->key_block_checksum; |
| 209 | 214 |
| 210 if (VerifySignatureInside(block, block->key_block_size, sig)) { | 215 if (VerifySignatureInside(block, block->key_block_size, sig)) { |
| 211 VBDEBUG(("Key block hash off end of block\n")); | 216 VBDEBUG(("Key block hash off end of block\n")); |
| 212 return VBOOT_KEY_BLOCK_INVALID; | 217 return VBOOT_KEY_BLOCK_INVALID; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 if (size < preamble->preamble_size) { | 267 if (size < preamble->preamble_size) { |
| 263 VBDEBUG(("Not enough data for preamble.\n")); | 268 VBDEBUG(("Not enough data for preamble.\n")); |
| 264 return VBOOT_PREAMBLE_INVALID; | 269 return VBOOT_PREAMBLE_INVALID; |
| 265 } | 270 } |
| 266 | 271 |
| 267 /* Check signature */ | 272 /* Check signature */ |
| 268 if (VerifySignatureInside(preamble, preamble->preamble_size, sig)) { | 273 if (VerifySignatureInside(preamble, preamble->preamble_size, sig)) { |
| 269 VBDEBUG(("Preamble signature off end of preamble\n")); | 274 VBDEBUG(("Preamble signature off end of preamble\n")); |
| 270 return VBOOT_PREAMBLE_INVALID; | 275 return VBOOT_PREAMBLE_INVALID; |
| 271 } | 276 } |
| 277 |
| 278 /* Make sure advertised signature data sizes are sane. */ |
| 279 if (preamble->preamble_size < sig->data_size) { |
| 280 VBDEBUG(("Signature calculated past end of the block\n")); |
| 281 return VBOOT_PREAMBLE_INVALID; |
| 282 } |
| 283 |
| 272 if (VerifyData((const uint8_t*)preamble, sig, key)) { | 284 if (VerifyData((const uint8_t*)preamble, sig, key)) { |
| 273 VBDEBUG(("Preamble signature validation failed\n")); | 285 VBDEBUG(("Preamble signature validation failed\n")); |
| 274 return VBOOT_PREAMBLE_SIGNATURE; | 286 return VBOOT_PREAMBLE_SIGNATURE; |
| 275 } | 287 } |
| 276 | 288 |
| 277 /* Verify we signed enough data */ | 289 /* Verify we signed enough data */ |
| 278 if (sig->data_size < sizeof(VbFirmwarePreambleHeader)) { | 290 if (sig->data_size < sizeof(VbFirmwarePreambleHeader)) { |
| 279 VBDEBUG(("Didn't sign enough data\n")); | 291 VBDEBUG(("Didn't sign enough data\n")); |
| 280 return VBOOT_PREAMBLE_INVALID; | 292 return VBOOT_PREAMBLE_INVALID; |
| 281 } | 293 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 /* Verify body signature is inside the block */ | 345 /* Verify body signature is inside the block */ |
| 334 if (VerifySignatureInside(preamble, preamble->preamble_size, | 346 if (VerifySignatureInside(preamble, preamble->preamble_size, |
| 335 &preamble->body_signature)) { | 347 &preamble->body_signature)) { |
| 336 VBDEBUG(("Kernel body signature off end of preamble\n")); | 348 VBDEBUG(("Kernel body signature off end of preamble\n")); |
| 337 return VBOOT_PREAMBLE_INVALID; | 349 return VBOOT_PREAMBLE_INVALID; |
| 338 } | 350 } |
| 339 | 351 |
| 340 /* Success */ | 352 /* Success */ |
| 341 return VBOOT_SUCCESS; | 353 return VBOOT_SUCCESS; |
| 342 } | 354 } |
| OLD | NEW |