File: configure_neo_ndef

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 (33 lines) | stat: -rwxr-xr-x 749 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
#!/usr/bin/env python
"""
Set up a YubiKey NEO NDEF
"""

import sys
import struct
import urllib

import yubico
import yubico.yubikey_neo_usb_hid

if len(sys.argv) != 2:
    sys.stderr.write("Syntax: %s URL\n" % (sys.argv[0]))
    sys.exit(1)

url = sys.argv[1]

try:
    YK = yubico.yubikey_neo_usb_hid.YubiKeyNEO_USBHID(debug=True)
    print "Version : %s " % YK.version()

    ndef = yubico.yubikey_neo_usb_hid.YubiKeyNEO_NDEF(data = url)

    user_input = raw_input('Write configuration to YubiKey? [y/N] : ')
    if user_input in ('y', 'ye', 'yes'):
        YK.write_ndef(ndef)
        print "\nSuccess!"
    else:
        print "\nAborted"
except yubico.yubico_exception.YubicoError as inst:
    print "ERROR: %s" % inst.reason
    sys.exit(1)