File: yubikey-inventory

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 (36 lines) | stat: -rwxr-xr-x 823 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
#!/usr/bin/env python
"""
Example of how to access more than one connected YubiKey.
"""

import sys
import yubico

def get_all_yubikeys(debug):
    """
    Look for YubiKey with ever increasing `skip' value until an error is returned.

    Return all instances of class YubiKey we got before failing.
    """
    res = []
    try:
        skip = 0
        while skip < 255:
            YK = yubico.find_yubikey(debug = debug, skip = skip)
            res.append(YK)
            skip += 1
    except yubico.yubikey.YubiKeyError:
        return res

debug = False
if len(sys.argv) > 1:
    debug = (sys.argv[1] == '-v')
keys = get_all_yubikeys(debug)

if not keys:
    print "No YubiKey found."
else:
    n = 1
    for this in keys:
        print "YubiKey #%02i : %s %s" % (n, this.description, this.status())
        n += 1