OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 # |
| 6 # Generate .vbpubk and .vbprivk pairs for use by developer builds. These should |
| 7 # be exactly like the real keys except that the private keys aren't secret. |
| 8 |
| 9 |
| 10 # 0 = (RSA1024 SHA1) |
| 11 # 1 = (RSA1024 SHA256) |
| 12 # 2 = (RSA1024 SHA512) |
| 13 # 3 = (RSA2048 SHA1) |
| 14 # 4 = (RSA2048 SHA256) |
| 15 # 5 = (RSA2048 SHA512) |
| 16 # 6 = (RSA4096 SHA1) |
| 17 # 7 = (RSA4096 SHA256) |
| 18 # 8 = (RSA4096 SHA512) |
| 19 # 9 = (RSA8192 SHA1) |
| 20 # 10 = (RSA8192 SHA256) |
| 21 # 11 = (RSA8192 SHA512) |
| 22 function alg_to_keylen { |
| 23 echo $(( 1 << (10 + ($1 / 3)) )) |
| 24 } |
| 25 |
| 26 # Emit .vbpubk and .vbprivk using given basename and algorithm |
| 27 function make_pair { |
| 28 local base=$1 |
| 29 local alg=$2 |
| 30 local len=$(alg_to_keylen $alg) |
| 31 |
| 32 echo "creating $base keypair..." |
| 33 |
| 34 # make the RSA keypair |
| 35 openssl genrsa -F4 -out "${base}_${len}.pem" $len |
| 36 # create a self-signed certificate |
| 37 openssl req -batch -new -x509 -key "${base}_${len}.pem" \ |
| 38 -out "${base}_${len}.crt" |
| 39 # generate pre-processed RSA public key |
| 40 dumpRSAPublicKey "${base}_${len}.crt" > "${base}_${len}.keyb" |
| 41 |
| 42 # wrap the public key |
| 43 vbutil_key \ |
| 44 --pack "${base}.vbpubk" \ |
| 45 --key "${base}_${len}.keyb" \ |
| 46 --version 1 \ |
| 47 --algorithm $alg |
| 48 |
| 49 # wrap the private key |
| 50 vbutil_key \ |
| 51 --pack "${base}.vbprivk" \ |
| 52 --key "${base}_${len}.pem" \ |
| 53 --algorithm $alg |
| 54 |
| 55 # remove intermediate files |
| 56 rm -f "${base}_${len}.pem" "${base}_${len}.crt" "${base}_${len}.keyb" |
| 57 } |
| 58 |
| 59 |
| 60 # Emit a .keyblock containing flags and a public key, signed by a private key |
| 61 # flags are the bitwise OR of these (passed in decimal, though) |
| 62 # 0x01 Developer switch off |
| 63 # 0x02 Developer switch on |
| 64 # 0x04 Not recovery mode |
| 65 # 0x08 Recovery mode |
| 66 function make_keyblock { |
| 67 local base=$1 |
| 68 local flags=$2 |
| 69 local pubkey=$3 |
| 70 local signkey=$4 |
| 71 |
| 72 echo "creating $base keyblock..." |
| 73 |
| 74 # create it |
| 75 vbutil_keyblock \ |
| 76 --pack "${base}.keyblock" \ |
| 77 --flags $flags \ |
| 78 --datapubkey "${pubkey}.vbpubk" \ |
| 79 --signprivate "${signkey}.vbprivk" |
| 80 |
| 81 # verify it |
| 82 vbutil_keyblock \ |
| 83 --unpack "${base}.keyblock" \ |
| 84 --signpubkey "${signkey}.vbpubk" |
| 85 } |
| 86 |
| 87 |
| 88 |
| 89 # Create the normal keypairs |
| 90 make_pair root_key 11 |
| 91 make_pair firmware_data_key 7 |
| 92 make_pair kernel_subkey 7 |
| 93 make_pair kernel_data_key 4 |
| 94 |
| 95 # Create the recovery keypairs |
| 96 make_pair recovery_key 11 |
| 97 make_pair recovery_kernel_data_key 11 |
| 98 |
| 99 |
| 100 # Create the firmware keyblock for use only in Normal mode. This is redundant, |
| 101 # since it's never even checked during Recovery mode. |
| 102 make_keyblock firmware 7 firmware_data_key root_key |
| 103 |
| 104 # Create the recovery kernel keyblock for use only in Recovery mode. |
| 105 make_keyblock recovery_kernel 11 recovery_kernel_data_key recovery_key |
| 106 |
| 107 # Create the normal kernel keyblock for use only in Normal mode. |
| 108 make_keyblock kernel 7 kernel_data_key kernel_subkey |
| 109 |
| 110 |
| 111 # CAUTION: The public parts of most of these blobs must be compiled into the |
| 112 # firmware, which is built separately (and some of which can't be changed after |
| 113 # manufacturing). If you update these keys, you must coordinate the changes |
| 114 # with the BIOS people or you'll be unable to boot the resulting images. |
| 115 |
OLD | NEW |