File: nist_challenge_response

package info (click to toggle)
python-yubico 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 288 kB
  • ctags: 434
  • sloc: python: 1,893; ansic: 128; sh: 67; makefile: 4
file content (43 lines) | stat: -rwxr-xr-x 1,190 bytes parent folder | download
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
#!/usr/bin/env python
"""
Test challenge-response, assumes a NIST PUB 198 A.2
20 bytes test vector in Slot 2 (variable input)
"""

import sys
import yubico

expected = \
    '\x09\x22\xd3\x40\x5f\xaa\x3d\x19\x4f\x82' + \
    '\xa4\x58\x30\x73\x7d\x5c\xc6\xc7\x5d\x24'

# turn on YubiKey debug if -v is given as an argument
debug = False
if len(sys.argv) > 1:
    debug = (sys.argv[1] == '-v')

# Look for and initialize the YubiKey
try:
    YK = yubico.find_yubikey(debug=debug)
    print "Version : %s " % YK.version()
    print "Serial  : %i" % YK.serial()
    print ""

    # Do challenge-response
    secret = 'Sample #2'.ljust(64, chr(0x0))
    print "Sending challenge : %s\n" % repr(secret)

    response = YK.challenge_response(secret, slot=2)
except yubico.yubico_exception.YubicoError as inst:
    print "ERROR: %s" % inst.reason
    sys.exit(1)

print "Response :\n%s\n" % yubico.yubico_util.hexdump(response)

# Check if the response matched the expected one
if response == expected:
    print "OK! Response matches the NIST PUB 198 A.2 expected response."
    sys.exit(0)
else:
    print "ERROR! Response does NOT match the NIST PUB 198 A.2 expected response."
    sys.exit(1)