File: update_cfg_remove_cr

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 (44 lines) | stat: -rwxr-xr-x 1,153 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
44
#!/usr/bin/env python
"""
Set up a YubiKey for standard OTP with CR, then remove it.
"""

import sys
import struct
import yubico

slot=2

try:
    YK = yubico.find_yubikey(debug=True)
    print "Version : %s " % YK.version()
    print "Status  : %s " % YK.status()

    Cfg = YK.init_config()
    Cfg.extended_flag('ALLOW_UPDATE', True)
    Cfg.ticket_flag('APPEND_CR', True)
    Cfg.extended_flag('SERIAL_API_VISIBLE', True)
    Cfg.uid = '010203040506'.decode('hex')
    Cfg.fixed_string("m:ftccftbbftdd")
    Cfg.aes_key('h:' + 32 * 'a')

    user_input = raw_input('Write configuration to slot %i of YubiKey? [y/N] : ' % slot )
    if user_input in ('y', 'ye', 'yes'):
        YK.write_config(Cfg, slot=slot)
        print "\nSuccess!"
        print "Status  : %s " % YK.status()
    else:
        print "\nAborted"
        sys.exit(0)

    raw_input("Press enter to update...")

    Cfg = YK.init_config(update=True)
    Cfg.ticket_flag('APPEND_CR', False)

    print ("Updating...");
    YK.write_config(Cfg, slot=slot)
    print "\nSuccess!"
except yubico.yubico_exception.YubicoError as inst:
    print "ERROR: %s" % inst.reason
    sys.exit(1)