Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_nagraid.doctest
blob: a36c74e4fb632e330f0aabbf13c40672546740ec (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
test_vendors.doctest - tests for NagraID 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 PSKC file from NagraID which is protected by a pre-shared
key. The file contains three OCRA keys.

>>> pskc = PSKC('tests/nagraid/file1.pskcxml')
>>> print('\n'.join(key.serial for key in pskc.keys))  #doctest: +REPORT_UDIFF
306EUO4-00960
306EUO4-00954
306EUO4-00958
>>> key = pskc.keys[0]
>>> bool(key.secret)  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
DecryptionError: No key available
>>> pskc.encryption.key_name
'Pre-shared-key'
>>> pskc.encryption.key = a2b_hex('4A057F6AB6FCB57AB5408E46A9835E68')
>>> bool(key.secret)
True
>>> key.check()
True
>>> print('\n'.join(key.algorithm_suite for key in pskc.keys))  #doctest: +REPORT_UDIFF
OCRA-1:HOTP-SHA1-6:C-QN08-PSHA1
OCRA-1:HOTP-SHA1-6:C-QN08-PSHA1
OCRA-1:HOTP-SHA1-6:C-QN08-PSHA1