1. Peter Sagerson
  2. yubiotp

Commits

Peter Sagerson  committed da5ea91

Fix bin/yubikey to match change in OTP.uid type.

  • Participants
  • Parent commits 08ca067
  • Branches default

Comments (0)

Files changed (1)

File bin/yubikey

View file
 from os.path import expanduser
 from optparse import OptionParser, OptionGroup, Option, OptionValueError
 from ConfigParser import SafeConfigParser
-from ConfigParser import NoSectionError, NoOptionError, DuplicateSectionError
+from ConfigParser import NoSectionError, DuplicateSectionError
 from random import choice
 from binascii import hexlify, unhexlify
 
         make_option('-p', '--public', dest='public_id', type='hex', default='', help=u'A hex-encoded public ID (up to 16 bytes)'),
         make_option('-P', '--public-ascii', dest='public_id', help=u'An ASCII public ID (up to 16 characters).'),
         make_option('-k', '--key', dest='key', type='hex', help='A hex-encoded 16-byte AES key. If omitted, one will be generated.'),
-        make_option('-u', '--uid', dest='uid', type='hex', default='', help='A hex-encoded private ID.'),
+        make_option('-u', '--uid', dest='uid', type='int', default=0, help='A private ID.'),
         make_option('-s', '--session', dest='session', type='int', default=0, help='The initial session counter. [%default]'),
     ]
     description = u'Initialize a new virtual YubiKey.'
                 else:
                     print u'public_id: {0}'.format(hexlify(public_id))
 
-                print u'uid: {0}'.format(hexlify(otp.uid))
+                print u'uid: 0x{0:x}'.format(otp.uid)
                 print u'session: {0}'.format(otp.session)
                 print u'timestamp: {0}'.format(hex(otp.timestamp))
                 print u'counter: {0}'.format(otp.counter)
         else:
             self.set_config('public_id', public_id, binary=True)
             self.set_config('key', key, binary=True)
-            self.set_config('uid', uid, binary=True)
+            self.set_config('uid', uid)
             self.set_config('session', session)
 
     def delete(self):
     def ensure_yubikey(self):
         if self.yubikey is None:
             try:
-                uid = self.get_config('uid', binary=True)
+                uid = int(self.get_config('uid'))
                 session = int(self.get_config('session'))
 
                 self.get_config('key', binary=True)
-            except (NoSectionError, NoOptionError):
+            except StandardError:
                 usage(u'The device named "{0}" does not exist or is corrupt.'.format(self.name))
             else:
                 self.yubikey = YubiKey(uid=uid, session=session)