Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_feitian.doctest
blob: 377de1b4abeebbff8bcef47d3204eb0701c304f1 (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
test_feitian.doctest - tests for Feitian PSKC files

Copyright (C) 2016 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 a simple non-encrypted PSKC file from Feitian. The PSKC file
contains two HOTP keys and four TOTP keys.

>>> pskc = PSKC('tests/feitian/file1.pskcxml')
>>> pskc.keys[0].manufacturer
'Feitian Technology Co.,Ltd'
>>> print('\n'.join(key.serial for key in pskc.keys))  #doctest: +REPORT_UDIFF
1000133508267
1000133508255
2600124809778
2600124809787
2600135004012
2600135004013
>>> print('\n'.join(key.algorithm for key in pskc.keys))  #doctest: +REPORT_UDIFF
urn:ietf:params:xml:ns:keyprov:pskc:hotp
urn:ietf:params:xml:ns:keyprov:pskc:hotp
urn:ietf:params:xml:ns:keyprov:pskc:totp
urn:ietf:params:xml:ns:keyprov:pskc:totp
urn:ietf:params:xml:ns:keyprov:pskc:totp
urn:ietf:params:xml:ns:keyprov:pskc:totp
>>> pskc.keys[5].time_interval
60


This tests a sample seed file originally provided by GOOZE for Feitian
c100 / c200 hardware tokens. There is one TOTP key and one HTOP key in
the file.

>>> pskc = PSKC('tests/feitian/20120919-test001-4282.xml')
>>> pskc.keys[0].manufacturer
'FeiTian Technology Co.,Ltd'
>>> print('\n'.join(key.serial for key in pskc.keys))
2600215704919
1000117803294
>>> key = pskc.keys[0]
>>> key.algorithm, key.response_length, key.time_offset, key.time_interval
('urn:ietf:params:xml:ns:keyprov:pskc:totp', 6, 0, 60)
>>> key.policy.start_date
datetime.datetime(2012, 9, 19, 0, 0, tzinfo=tzutc())
>>> key.policy.expiry_date
datetime.datetime(2022, 9, 1, 0, 0, tzinfo=tzutc())
>>> key = pskc.keys[1]
>>> key.algorithm, key.response_length, key.counter
('urn:ietf:params:xml:ns:keyprov:pskc:hotp', 6, 0)
>>> key.policy.start_date
datetime.datetime(2012, 9, 19, 0, 0, tzinfo=tzutc())
>>> key.policy.expiry_date
datetime.datetime(2022, 9, 1, 0, 0, tzinfo=tzutc())