Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_yubico.doctest
blob: d3ed4e5f7e993b3dd94757fb1dd2327be249b30b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
test_yubico.doctest - tests for Yubico PSKC files

Copyright (C) 2017 Arthur de Jong

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA


>>> from binascii import a2b_hex, b2a_hex
>>> def tostr(x):
...     return str(x.decode())
>>> def decode(f):
...     return lambda x: tostr(f(x))
>>> b2a_hex = decode(b2a_hex)

>>> from pskc import PSKC


This tests the first example from draft-josefsson-keyprov-pskc-yubikey-00.

>>> pskc = PSKC('tests/yubico/example1.pskcxml')
>>> pskc.id
'yk-pskc-283599'
>>> len(pskc.keys)
1
>>> key = pskc.keys[0]
>>> key.manufacturer
'oath.UB'
>>> key.serial
'283599'
>>> key.start_date
datetime.datetime(2009, 1, 22, 0, 25, 11, tzinfo=tzutc())
>>> key.crypto_module
'1'
>>> key.id
'283599:1'
>>> key.algorithm
'http://www.yubico.com/#yubikey-aes'
>>> key.issuer
'ACME Inc.'
>>> key.response_encoding
'ALPHANUMERIC'
>>> key.response_length
44
>>> b2a_hex(key.secret)
'2b7e151628aed2a6abf7158809cf4f3c'
>>> key.key_userid
'CN=ekhgjhbctrgn, UID=ca62baca62ba'


This tests the second example from draft-josefsson-keyprov-pskc-yubikey-00.

>>> pskc = PSKC('tests/yubico/example2.pskcxml')
>>> pskc.id
'yk-pskc-283598'
>>> len(pskc.keys)
2
>>> key = pskc.keys[0]  # first key
>>> key.manufacturer
'oath.UB'
>>> key.serial
'283598'
>>> key.start_date
datetime.datetime(2009, 1, 22, 0, 25, 10, tzinfo=tzutc())
>>> key.crypto_module
'1'
>>> key.id
'283598:1'
>>> key.algorithm
'http://www.yubico.com/#yubikey-aes'
>>> key.issuer
'ACME Inc.'
>>> key.response_encoding
'ALPHANUMERIC'
>>> key.response_length
44
>>> b2a_hex(key.secret)
'5698356d30868c4201e26f66c582bb45'
>>> key.key_userid
'CN=ekhgjhbctrgn, UID=ca62baca62ba'
>>> key = pskc.keys[1]  # second key
>>> key.manufacturer
'oath.UB'
>>> key.serial
'283598'
>>> key.start_date
datetime.datetime(2009, 1, 22, 0, 25, 10, tzinfo=tzutc())
>>> key.crypto_module
'2'
>>> key.id
'283598:2'
>>> key.algorithm
'http://www.yubico.com/#yubikey-aes'
>>> key.issuer
'ACME Inc.'
>>> key.response_encoding
'ALPHANUMERIC'
>>> key.response_length
44
>>> b2a_hex(key.secret)
'38892b82abf1807788458fc5a5165c80'
>>> key.key_userid
'CN=ekhgjhbctrgn, UID=ca62baca62ba'


This tests the third example from draft-josefsson-keyprov-pskc-yubikey-00.

>>> pskc = PSKC('tests/yubico/example3.pskcxml')
>>> pskc.id
'yk-pskc-283597'
>>> len(pskc.keys)
1
>>> key = pskc.keys[0]
>>> key.manufacturer
'oath.UB'
>>> key.serial
'283597'
>>> key.start_date
datetime.datetime(2009, 1, 22, 0, 25, 9, tzinfo=tzutc())
>>> key.crypto_module
'1'
>>> key.id
'283597:1'
>>> key.algorithm
'http://www.yubico.com/#yubikey-aes'
>>> key.issuer
'ACME Inc.'
>>> key.response_encoding
'ALPHANUMERIC'
>>> key.response_length
40
>>> b2a_hex(key.secret)
'2b7e151628aed2a6abf7158809cf4f3c'
>>> key.key_userid
'CN=ekhgjhbctrgn, UID=ca62baca62ba'

# TODO: support extensions