• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2011 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
5import gobject, hashlib, logging, os
6from dbus.mainloop.glib import DBusGMainLoop
7
8from autotest_lib.client.bin import test, utils
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.common_lib.cros import chrome, session_manager
11from autotest_lib.client.cros import constants, cryptohome, ownership
12
13
14class login_OwnershipNotRetaken(test.test):
15    """Subsequent logins after the owner must not clobber the owner's key."""
16    version = 2
17
18    _TEST_USER = 'example@chromium.org'
19    _TEST_PASS = 'testme'
20    _TEST_GAIAID = '7583'
21
22
23    def initialize(self):
24        super(login_OwnershipNotRetaken, self).initialize()
25        # Start clean, wrt ownership and the desired user.
26        ownership.restart_ui_to_clear_ownership_files()
27
28        bus_loop = DBusGMainLoop(set_as_default=True)
29        self._cryptohome_proxy = cryptohome.CryptohomeProxy(bus_loop)
30
31
32    def run_once(self):
33        # TODO(apronin): crbug.com/618392. This test flakes on these boards.
34        boards_to_skip = ['tricky', 'peach_pit', 'falco']
35        board = utils.get_current_board()
36        if board in boards_to_skip:
37            logging.info("Skipping test run on %s.", board)
38            return
39
40        listener = session_manager.OwnershipSignalListener(gobject.MainLoop())
41        listener.listen_for_new_key_and_policy()
42        # Sign in. Sign out happens automatically when cr goes out of scope.
43        with chrome.Chrome(clear_enterprise_policy=False) as cr:
44            listener.wait_for_signals(desc='Owner settings written to disk.')
45
46        key = open(constants.OWNER_KEY_FILE, 'rb')
47        hash = hashlib.md5(key.read())
48        key.close()
49        mtime = os.stat(constants.OWNER_KEY_FILE).st_mtime
50
51        # Sign in/sign out as a second user.
52        with chrome.Chrome(clear_enterprise_policy=False,
53                           username=self._TEST_USER,
54                           password=self._TEST_PASS,
55                           gaia_id=self._TEST_GAIAID) as cr:
56            pass
57
58        # Checking mtime to see if key file was touched during second sign in.
59        if os.stat(constants.OWNER_KEY_FILE).st_mtime > mtime:
60            raise error.TestFail("Owner key was touched on second login!")
61
62        # Sanity check.
63        key2 = open(constants.OWNER_KEY_FILE, 'rb')
64        hash2 = hashlib.md5(key2.read())
65        key2.close()
66        if hash.hexdigest() != hash2.hexdigest():
67            raise error.TestFail("Owner key was touched on second login!")
68
69
70    def cleanup(self):
71        self._cryptohome_proxy.remove(self._TEST_USER)
72        super(login_OwnershipNotRetaken, self).cleanup()
73