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

Side by Side Diff: build_kernel_image.sh

Issue 2818045: Use the new developer keys to sign things. (submit for Bill) (Closed) Base URL: ssh://gitrw.chromium.org/crosutils.git
Patch Set: fixed indet and column 80 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 | « build_image ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Helper script that generates the signed kernel image 7 # Helper script that generates the signed kernel image
8 8
9 . "$(dirname "$0")/common.sh" 9 . "$(dirname "$0")/common.sh"
10 10
11 get_default_board 11 get_default_board
12 12
13 # Flags. 13 # Flags.
14 DEFINE_string arch "x86" \ 14 DEFINE_string arch "x86" \
15 "The boot architecture: arm or x86. (Default: x86)" 15 "The boot architecture: arm or x86. (Default: x86)"
16 DEFINE_string to "/tmp/vmlinuz.image" \ 16 DEFINE_string to "/tmp/vmlinuz.image" \
17 "The path to the kernel image to be created. (Default: /tmp/vmlinuz.image)" 17 "The path to the kernel image to be created. (Default: /tmp/vmlinuz.image)"
18 DEFINE_string hd_vblock "/tmp/vmlinuz_hd.vblock" \
19 "The path to the installed kernel's vblock (Default: /tmp/vmlinuz_hd.vblock)"
18 DEFINE_string vmlinuz "vmlinuz" \ 20 DEFINE_string vmlinuz "vmlinuz" \
19 "The path to the kernel (Default: vmlinuz)" 21 "The path to the kernel (Default: vmlinuz)"
20 DEFINE_string working_dir "/tmp/vmlinuz.working" \ 22 DEFINE_string working_dir "/tmp/vmlinuz.working" \
21 "Working directory for in-progress files. (Default: /tmp/vmlinuz.working)" 23 "Working directory for in-progress files. (Default: /tmp/vmlinuz.working)"
22 DEFINE_boolean keep_work ${FLAGS_FALSE} \ 24 DEFINE_boolean keep_work ${FLAGS_FALSE} \
23 "Keep temporary files (*.keyblock, *.vbpubk). (Default: false)" 25 "Keep temporary files (*.keyblock, *.vbpubk). (Default: false)"
24 DEFINE_string keys_dir "${SRC_ROOT}/platform/vboot_reference/tests/testkeys" \ 26 DEFINE_string keys_dir "${SRC_ROOT}/platform/vboot_reference/tests/testkeys" \
25 "Directory with the RSA signing keys. (Defaults to test keys)" 27 "Directory with the RSA signing keys. (Defaults to test keys)"
26 # Note, to enable verified boot, the caller would manually pass: 28 # Note, to enable verified boot, the caller would manually pass:
27 # --boot_args='dm="... /dev/sd%D%P /dev/sd%D%P ..." \ 29 # --boot_args='dm="... /dev/sd%D%P /dev/sd%D%P ..." \
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 rootwait 125 rootwait
124 ro 126 ro
125 noresume 127 noresume
126 noswap 128 noswap
127 i915.modeset=1 129 i915.modeset=1
128 loglevel=7 130 loglevel=7
129 cros_secure 131 cros_secure
130 EOF 132 EOF
131 WORK="${WORK} ${FLAGS_working_dir}/config.txt" 133 WORK="${WORK} ${FLAGS_working_dir}/config.txt"
132 134
133 135 # We sign the image with the recovery_key, because this is what goes onto the
134 # FIX: The .vbprivk files are not encrypted, so we shouldn't just leave them 136 # USB key. We can only boot from the USB drive in recovery mode.
135 # lying around as a general thing.
136
137 # Wrap the kernel data keypair, used for the kernel body
138 vbutil_key \
139 --pack "${FLAGS_working_dir}/kernel_data_key.vbpubk" \
140 --key "${FLAGS_keys_dir}/key_rsa2048.keyb" \
141 --version 1 \
142 --algorithm 4
143 WORK="${WORK} ${FLAGS_working_dir}/kernel_data_key.vbpubk"
144
145 vbutil_key \
146 --pack "${FLAGS_working_dir}/kernel_data_key.vbprivk" \
147 --key "${FLAGS_keys_dir}/key_rsa2048.pem" \
148 --algorithm 4
149 WORK="${WORK} ${FLAGS_working_dir}/kernel_data_key.vbprivk"
150
151
152 # Wrap the kernel subkey pair, used for the kernel's keyblock
153 vbutil_key \
154 --pack "${FLAGS_working_dir}/kernel_subkey.vbpubk" \
155 --key "${FLAGS_keys_dir}/key_rsa4096.keyb" \
156 --version 1 \
157 --algorithm 8
158 WORK="${WORK} ${FLAGS_working_dir}/kernel_subkey.vbpubk"
159
160 vbutil_key \
161 --pack "${FLAGS_working_dir}/kernel_subkey.vbprivk" \
162 --key "${FLAGS_keys_dir}/key_rsa4096.pem" \
163 --algorithm 8
164 WORK="${WORK} ${FLAGS_working_dir}/kernel_subkey.vbprivk"
165
166
167 # Create the kernel keyblock, containing the kernel data key
168 vbutil_keyblock \
169 --pack "${FLAGS_working_dir}/kernel.keyblock" \
170 --datapubkey "${FLAGS_working_dir}/kernel_data_key.vbpubk" \
171 --signprivate "${FLAGS_working_dir}/kernel_subkey.vbprivk" \
172 --flags 15
173 WORK="${WORK} ${FLAGS_working_dir}/kernel.keyblock"
174
175 # Verify the keyblock.
176 vbutil_keyblock \
177 --unpack "${FLAGS_working_dir}/kernel.keyblock" \
178 --signpubkey "${FLAGS_working_dir}/kernel_subkey.vbpubk"
179
180 # TODO: We should sign the kernel blob using the recovery root key and
181 # recovery kernel data key instead (to create the recovery image), and then
182 # re-sign it this way for the install image. But we'll want to keep the
183 # install vblock separate, so we can just copy that part over separately when
184 # we install it instead of the whole kernel blob.
185 137
186 # Create and sign the kernel blob 138 # Create and sign the kernel blob
187 vbutil_kernel \ 139 vbutil_kernel \
188 --pack "${FLAGS_to}" \ 140 --pack "${FLAGS_to}" \
189 --keyblock "${FLAGS_working_dir}/kernel.keyblock" \ 141 --keyblock "${FLAGS_keys_dir}/recovery_kernel.keyblock" \
190 --signprivate "${FLAGS_working_dir}/kernel_data_key.vbprivk" \ 142 --signprivate "${FLAGS_keys_dir}/recovery_kernel_data_key.vbprivk" \
191 --version 1 \ 143 --version 1 \
192 --config "${FLAGS_working_dir}/config.txt" \ 144 --config "${FLAGS_working_dir}/config.txt" \
193 --bootloader /lib64/bootstub/bootstub.efi \ 145 --bootloader /lib64/bootstub/bootstub.efi \
194 --vmlinuz "${FLAGS_vmlinuz}" 146 --vmlinuz "${FLAGS_vmlinuz}"
195 147
196 # And verify it. 148 # And verify it.
197 vbutil_kernel \ 149 vbutil_kernel \
198 --verify "${FLAGS_to}" \ 150 --verify "${FLAGS_to}" \
199 --signpubkey "${FLAGS_working_dir}/kernel_subkey.vbpubk" 151 --signpubkey "${FLAGS_keys_dir}/recovery_key.vbpubk"
152
153
154 # Now we re-sign the same image using the normal keys. This is the kernel
155 # image that is put on the hard disk by the installer. Note: To save space on
156 # the USB image, we're only emitting the new verfication block, and the
157 # installer just replaces that part of the hard disk's kernel partition.
158 vbutil_kernel \
159 --repack "${FLAGS_hd_vblock}" \
160 --vblockonly \
161 --keyblock "${FLAGS_keys_dir}/kernel.keyblock" \
162 --signprivate "${FLAGS_keys_dir}/kernel_data_key.vbprivk" \
163 --oldblob "${FLAGS_to}"
164
165
166 # To verify it, we have to replace the vblock from the original image.
167 tempfile=$(mktemp)
168 trap "rm -f $tempfile" EXIT
169 cat "${FLAGS_hd_vblock}" > $tempfile
170 dd if="${FLAGS_to}" bs=65536 skip=1 >> $tempfile
171
172 vbutil_kernel \
173 --verify $tempfile \
174 --signpubkey "${FLAGS_keys_dir}/kernel_subkey.vbpubk"
175
176 rm -f $tempfile
177 trap - EXIT
200 178
201 elif [[ "${FLAGS_arch}" = "arm" ]]; then 179 elif [[ "${FLAGS_arch}" = "arm" ]]; then
202 # FIXME: For now, ARM just uses the unsigned kernel by itself. 180 # FIXME: For now, ARM just uses the unsigned kernel by itself.
203 cp -f "${FLAGS_vmlinuz}" "${FLAGS_to}" 181 cp -f "${FLAGS_vmlinuz}" "${FLAGS_to}"
204 else 182 else
205 error "Unknown arch: ${FLAGS_arch}" 183 error "Unknown arch: ${FLAGS_arch}"
206 fi 184 fi
207 185
208 set +e # cleanup failure is a-ok 186 set +e # cleanup failure is a-ok
209 187
210 if [[ ${FLAGS_keep_work} -eq ${FLAGS_FALSE} ]]; then 188 if [[ ${FLAGS_keep_work} -eq ${FLAGS_FALSE} ]]; then
211 info "Cleaning up temporary files: ${WORK}" 189 info "Cleaning up temporary files: ${WORK}"
212 rm ${WORK} 190 rm ${WORK}
213 rmdir ${FLAGS_working_dir} 191 rmdir ${FLAGS_working_dir}
214 fi 192 fi
215 193
216 info "Kernel partition image emitted: ${FLAGS_to}" 194 info "Kernel partition image emitted: ${FLAGS_to}"
217 195
218 if [[ -f ${FLAGS_rootfs_hash} ]]; then 196 if [[ -f ${FLAGS_rootfs_hash} ]]; then
219 info "Root filesystem hash emitted: ${FLAGS_rootfs_hash}" 197 info "Root filesystem hash emitted: ${FLAGS_rootfs_hash}"
220 fi 198 fi
OLDNEW
« no previous file with comments | « build_image ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698