File: configure_neo_ndef

package info (click to toggle)
python-yubico 1.3.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 460 kB
  • sloc: python: 2,367; ansic: 128; xml: 20; makefile: 7
file content (37 lines) | stat: -rwxr-xr-x 819 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python
"""
Set up a YubiKey NEO NDEF
"""

import sys
import struct

import six

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]

if sys.version_info >= (3, 0):
    url = url.encode('utf-8')

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 = six.moves.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)