• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 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 logging
6
7from autotest_lib.client.common_lib import error
8from autotest_lib.server.cros.faft.cr50_test import Cr50Test
9
10
11class firmware_Cr50Password(Cr50Test):
12    """Verify cr50 set password."""
13    version = 1
14    NEW_PASSWORD = 'robot'
15
16
17    def run_once(self):
18        """Check we can set the cr50 password."""
19        # Make sure to enable testlab mode, so we can guarantee the password
20        # can be cleared.
21        self.fast_ccd_open(enable_testlab=True)
22        self.cr50.ccd_reset()
23
24        # Set the password.
25        self.set_ccd_password(self.CCD_PASSWORD)
26        if self.cr50.password_is_reset():
27            raise error.TestFail('Failed to set password')
28
29        # Test 'ccd reset' clears the password.
30        self.cr50.ccd_reset()
31        if not self.cr50.password_is_reset():
32            raise error.TestFail('ccd reset did not clear the password')
33        # Set OpenFromUSB to IfOpened, so the test will only be able to open
34        # ccd with a console command if the password is set. This is cleared
35        # in Cr50Test cleanup.
36        self.cr50.set_cap('OpenFromUSB', 'IfOpened')
37
38        # Set the password again while cr50 is open.
39        self.set_ccd_password(self.CCD_PASSWORD)
40        if self.cr50.password_is_reset():
41            raise error.TestFail('Failed to set password')
42
43        # The password can't be changed once it's set.
44        # It needs to be cleared first.
45        self.set_ccd_password(self.NEW_PASSWORD, expect_error=True)
46
47        self.cr50.reboot()
48        if self.cr50.password_is_reset():
49            raise error.TestFail('Password cleared after reboot')
50
51        # Verify ccd can't be opened with the wrong password.
52        try:
53            self.cr50.set_ccd_level('open', self.NEW_PASSWORD)
54            raise error.TestFail('Opened ccd with incorrect password')
55        except error.TestFail as e:
56            logging.info('Cr50 successfully rejected ccd open')
57
58        # Verify ccd can be opened with the correct password.
59        self.cr50.set_ccd_level('open', self.CCD_PASSWORD)
60
61        self.cr50.set_ccd_level('lock')
62        # The password can't be cleared while the console is locked.
63        self.set_ccd_password('clear:' + self.CCD_PASSWORD, expect_error=True)
64
65        if self.cr50.unlock_is_supported():
66            self.cr50.send_command('ccd unlock ' + self.CCD_PASSWORD)
67            # The password can be cleared while the console is unlocked.
68            self.set_ccd_password('clear:' + self.CCD_PASSWORD)
69
70            # Open the console, set the password again.
71            self.cr50.send_command('ccd testlab open')
72            self.set_ccd_password(self.CCD_PASSWORD)
73        else:
74            # Open the console.
75            self.cr50.send_command('ccd testlab open')
76
77        # The password can't be cleared using the wrong password.
78        self.set_ccd_password('clear:' + self.CCD_PASSWORD.lower(),
79                              expect_error=True)
80        # The password can be cleared using the correct password.
81        self.set_ccd_password('clear:' + self.CCD_PASSWORD)
82        if not self.cr50.password_is_reset():
83            raise error.TestFail('Failed to clear password')
84
85        # The password can be set to anything when there isn't one set.
86        self.set_ccd_password(self.NEW_PASSWORD)
87        if self.cr50.password_is_reset():
88            raise error.TestFail('Failed to set password')
89
90
91        self.cr50.send_command('ccd testlab open')
92        self.cr50.ccd_reset()
93
94        if not self.cr50.unlock_is_supported():
95            return
96
97        # Run through the same steps when the password was set with the console
98        # unlocked.
99
100        self.host.run('gsctool -a -U')
101
102        # Set the password when the console is unlocked.
103        self.set_ccd_password(self.CCD_PASSWORD)
104
105        self.cr50.set_ccd_level('lock')
106        # The password can't be cleared while the console is locked.
107        self.set_ccd_password('clear:' + self.CCD_PASSWORD, expect_error=True)
108
109        # Unlock the console.
110        self.ccd_unlock_from_ap(self.CCD_PASSWORD)
111        # The password can be cleared while the console is unlocked.
112        self.set_ccd_password('clear:' + self.CCD_PASSWORD)
113        # Set the password again when the console is unlocked.
114        self.set_ccd_password(self.CCD_PASSWORD)
115
116        self.cr50.send_command('ccd testlab open')
117        # The password can be cleared when the console is open.
118        self.set_ccd_password('clear:' + self.CCD_PASSWORD)
119