OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''Unit test for kernel_handler module. | 6 '''Unit test for kernel_handler module. |
7 | 7 |
8 Allows to verify kernel corrupt and restore actions. | 8 Allows to verify kernel corrupt and restore actions. |
9 ''' | 9 ''' |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 def get_kernel_key(section, pubkey_file): | 31 def get_kernel_key(section, pubkey_file): |
32 '''Retrieve from firmware the public key used to verify the kernel. | 32 '''Retrieve from firmware the public key used to verify the kernel. |
33 | 33 |
34 Skip the keyblock to reach the firmware preamble. Find out where the | 34 Skip the keyblock to reach the firmware preamble. Find out where the |
35 public key is and extract it into a separate file, adjusting the header's | 35 public key is and extract it into a separate file, adjusting the header's |
36 'offset' value. | 36 'offset' value. |
37 ''' | 37 ''' |
38 fum = flashrom_util.flashrom_util() | 38 fum = flashrom_util.flashrom_util() |
39 image = fum.read_whole() | 39 image = fum.read_whole() |
40 layout = fum.detect_chromeos_layout('bios', len(image)) | |
41 # get the block header | 40 # get the block header |
42 kblock = fum.get_section(image, layout, 'VBOOT' + section) | 41 kblock = fum.get_section(image, 'VBOOT' + section) |
43 kbsize = struct.unpack_from(KEYBLOCK_SIZE_ACCESS_FORMAT, kblock)[1] | 42 kbsize = struct.unpack_from(KEYBLOCK_SIZE_ACCESS_FORMAT, kblock)[1] |
44 | 43 |
45 pk_base_offset = kbsize + FW_PREAMBLE_PUBKEY_OFFSET | 44 pk_base_offset = kbsize + FW_PREAMBLE_PUBKEY_OFFSET |
46 offset, size, alg, version = struct.unpack_from( | 45 offset, size, alg, version = struct.unpack_from( |
47 PUBKEY_HEADER_FORMAT, kblock[pk_base_offset:]) | 46 PUBKEY_HEADER_FORMAT, kblock[pk_base_offset:]) |
48 | 47 |
49 key_data_offset = pk_base_offset + offset | 48 key_data_offset = pk_base_offset + offset |
50 | 49 |
51 # Retrieve the public key and save it in a file. | 50 # Retrieve the public key and save it in a file. |
52 pub_key = struct.pack('<QQQQ%ds' % size, 32, size, alg, version, | 51 pub_key = struct.pack('<QQQQ%ds' % size, 32, size, alg, version, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 self.backup_file = None | 140 self.backup_file = None |
142 shutil.rmtree(self.tmpd) | 141 shutil.rmtree(self.tmpd) |
143 | 142 |
144 | 143 |
145 if __name__ == '__main__': | 144 if __name__ == '__main__': |
146 unittest.main() | 145 unittest.main() |
147 | 146 |
148 | 147 |
149 | 148 |
150 | 149 |
OLD | NEW |