Debian Codegraph @

tests/device/test_reset.py

raw
1 # Copyright 2016-2018 Yubico AB
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from . import DEFAULT_KEY
16 from yubihsm.defs import OBJECT, CAPABILITY, ALGORITHM, ORIGIN
17 from yubihsm.objects import Opaque
18 import time
19
20
21 def test_reset(hsm, session, connect_hsm):
22 Opaque.put(
23 session,
24 0,
25 "Test opaque data",
26 1,
27 CAPABILITY.NONE,
28 ALGORITHM.OPAQUE_DATA,
29 b"dummyobject",
30 )
31 session.reset_device()
32 hsm.close()
33
34 time.sleep(5) # Wait for device to reboot
35
36 with connect_hsm() as hsm: # Re-connect since device restarted.
37 with hsm.create_session_derived(1, DEFAULT_KEY) as session:
38 assert len(session.list_objects()) == 1
39 auth_key = session.get_object(1, OBJECT.AUTHENTICATION_KEY)
40
41 # Check details of default key
42 info = auth_key.get_info()
43
44 assert info.capabilities & CAPABILITY.ALL == CAPABILITY.ALL
45 assert info.id == 1
46 assert info.size == 40
47 assert info.domains == 0xFFFF
48 assert info.object_type == OBJECT.AUTHENTICATION_KEY
49 assert info.algorithm == ALGORITHM.AES128_YUBICO_AUTHENTICATION
50 assert info.sequence == 0
51 assert info.origin == ORIGIN.IMPORTED
52 assert info.label == "DEFAULT AUTHKEY CHANGE THIS ASAP"
53 assert info.capabilities == info.delegated_capabilities