def test_28_yubikey_utils(self): self.assertEquals(modhex_encode(b'\x47'), 'fi') self.assertEquals(modhex_encode(b'\xba\xad\xf0\x0d'), 'nlltvcct') self.assertEquals(modhex_encode(binascii.unhexlify('0123456789abcdef')), 'cbdefghijklnrtuv') self.assertEquals(modhex_encode('Hallo'), 'fjhbhrhrhv') # and the other way around self.assertEquals(modhex_decode('fi'), b'\x47') self.assertEquals(modhex_decode('nlltvcct'), b'\xba\xad\xf0\x0d') self.assertEquals(modhex_decode('cbdefghijklnrtuv'), binascii.unhexlify('0123456789abcdef')) self.assertEquals(modhex_decode('fjhbhrhrhv'), b'Hallo') # now test the crc function self.assertEquals(checksum(b'\x01\x02\x03\x04'), 0xc66e) self.assertEquals(checksum(b'\x01\x02\x03\x04\x919'), 0xf0b8)
def _create_static_password(key_hex): ''' According to yubikey manual 5.5.5 the static-ticket is the same algorithm with no moving factors. The msg_hex that is encoded with the AES key is '000000000000ffffffffffffffff0f2e' ''' msg_hex = "000000000000ffffffffffffffff0f2e" msg_bin = binascii.unhexlify(msg_hex) aes = AES.new(binascii.unhexlify(key_hex), AES.MODE_ECB) password_bin = aes.encrypt(msg_bin) password = modhex_encode(password_bin) return password
def _create_static_password(key_hex): ''' According to yubikey manual 5.5.5 the static-ticket is the same algorithm with no moving factors. The msg_hex that is encoded with the AES key is '000000000000ffffffffffffffff0f2e' ''' msg_hex = "000000000000ffffffffffffffff0f2e" msg_bin = binascii.unhexlify(msg_hex) cipher = Cipher(algorithms.AES(binascii.unhexlify(key_hex)), modes.ECB(), default_backend()) encryptor = cipher.encryptor() password_bin = encryptor.update(msg_bin) + encryptor.finalize() password = modhex_encode(password_bin) return password