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