1 # Copyright 2014 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 5 from dbus.mainloop.glib import DBusGMainLoop 6 7 from autotest_lib.client.bin import test 8 from autotest_lib.client.common_lib import error 9 from autotest_lib.client.cros import cryptohome, pkcs11 10 11 12 class platform_CryptohomeMigrateChapsTokenClient(test.test): 13 """ This is a helper to platform_CryptohomeMigrateChapsToken 14 It logs a test user in and either generates a chaps signing 15 key or checks if a signing key was generated 16 """ 17 version = 1 18 19 20 def initialize(self): 21 super(platform_CryptohomeMigrateChapsTokenClient, self).initialize() 22 bus_loop = DBusGMainLoop(set_as_default=True) 23 self._cryptohome_proxy = cryptohome.CryptohomeProxy( 24 bus_loop, self.autodir, self.job) 25 26 def run_once(self, generate_key=False): 27 28 user = "user (at] test.com" 29 password = "test_password" 30 if generate_key: 31 # Make sure that the tpm is owned. 32 status = cryptohome.get_tpm_status() 33 if not status['Owned']: 34 cryptohome.take_tpm_ownership() 35 36 # We generate a chaps key tied to |user|. 37 self._cryptohome_proxy.ensure_clean_cryptohome_for(user, password) 38 result = pkcs11.generate_user_key() 39 if not result: 40 raise error.TestFail('Unable to generate key for ' + user) 41 else: 42 # Check if the chaps key previously generated is still present. 43 # If the key is present, migration was successful, and chaps keys 44 # weren't destroyed. 45 result = self._cryptohome_proxy.mount(user, password) 46 if not result: 47 raise error.TestFail('Unable to remount users cryptohome') 48 result = pkcs11.test_and_cleanup_key() 49 if not result: 50 raise error.TestFail('No Generated keys present for ' + user) 51 self._cryptohome_proxy.remove(user) 52 53