1# Copyright (c) 2013 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 5from autotest_lib.server.cros.update_engine import update_engine_test 6 7 8class autoupdate_CatchBadSignatures(update_engine_test.UpdateEngineTest): 9 """Test to verify that update_engine correctly checks payload signatures.""" 10 version = 1 11 12 # The test image to use and the values associated with it. 13 _IMAGE_GS_URL='https://storage.googleapis.com/chromiumos-test-assets-public/autoupdate/autoupdate_CatchBadSignatures.bin' 14 _IMAGE_PUBLIC_KEY2='LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxZE03Z25kNDNjV2ZRenlydDE2UQpESEUrVDB5eGcxOE9aTys5c2M4aldwakMxekZ0b01Gb2tFU2l1OVRMVXArS1VDMjc0ZitEeElnQWZTQ082VTVECkpGUlBYVXp2ZTF2YVhZZnFsalVCeGMrSlljR2RkNlBDVWw0QXA5ZjAyRGhrckduZi9ya0hPQ0VoRk5wbTUzZG8Kdlo5QTZRNUtCZmNnMUhlUTA4OG9wVmNlUUd0VW1MK2JPTnE1dEx2TkZMVVUwUnUwQW00QURKOFhtdzRycHZxdgptWEphRm1WdWYvR3g3K1RPbmFKdlpUZU9POUFKSzZxNlY4RTcrWlppTUljNUY0RU9zNUFYL2xaZk5PM1JWZ0cyCk83RGh6emErbk96SjNaSkdLNVI0V3daZHVobjlRUllvZ1lQQjBjNjI4NzhxWHBmMkJuM05wVVBpOENmL1JMTU0KbVFJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==' 15 16 def _check_signature(self, expected_log_messages, 17 failure_message, public_key=None): 18 """Helper function for updating with a Canned Omaha response. 19 20 @param expected_log_messages: A list of strings that are expected to be 21 in the update_engine log. 22 @param failure_message: The message for exception to raise on error. 23 @param public_key: The public key to be passed to the update_engine. 24 25 """ 26 27 # Runs the update on the DUT and expect it to fail. 28 self._run_client_test_and_check_result('autoupdate_CannedOmahaUpdate', 29 image_url=self._IMAGE_GS_URL, 30 allow_failure=True, 31 public_key=public_key) 32 33 self._check_update_engine_log_for_entry(expected_log_messages, 34 raise_error=True, 35 err_str=failure_message) 36 37 38 def _check_bad_metadata_signature(self): 39 """Checks that update_engine rejects updates where the payload 40 and Omaha response do not agree on the metadata signature.""" 41 42 expected_log_messages = [ 43 'Mandating payload hash checks since Omaha Response for ' 44 'unofficial build includes public RSA key', 45 'Mandatory metadata signature validation failed'] 46 47 self._check_signature(expected_log_messages, 48 'Check for bad metadata signature failed.', 49 public_key=self._IMAGE_PUBLIC_KEY2) 50 51 52 def _check_bad_payload_signature(self): 53 """Checks that update_engine rejects updates where the payload 54 signature does not match what is expected.""" 55 56 expected_log_messages = [ 57 'Mandating payload hash checks since Omaha Response for ' 58 'unofficial build includes public RSA key', 59 'Metadata hash signature matches value in Omaha response.', 60 'Public key verification failed, thus update failed'] 61 62 self._check_signature(expected_log_messages, 63 'Check for payload signature failed.') 64 65 66 def run_once(self): 67 """Runs the test on a DUT.""" 68 69 self._check_bad_metadata_signature() 70 self._check_bad_payload_signature() 71