def test_derive_key(self): self.assertEqual( b'\xb0}\xa1\xe7\xde\x87\xf8\x9a\x87\xa2\xb5\x98\xea\xa2\x18\x8c', derive_key(b'\0\0\0\0\0\0\0\0', u'foobar')) self.assertEqual( b'\xda\x81\x8ek,\xf0\xa2\xd0\xbf\x19\xb3\xdd\xd3K\x83\xf5', derive_key(b'12345678', u'Hallå världen!')) self.assertEqual( b'\xf3\xdf\xa7\x81T\xc8\x102\x99E\xfb\xc4\xb55\xe57', derive_key(b'saltsalt', u'Ťᶒśƫ ᵽĥřӓşḛ'))
def set_password(self, new_password, password_key): dev = self._descriptor.open_device(TRANSPORT.CCID) controller = OathController(dev.driver) if controller.locked and password_key is not None: controller.validate(a2b_hex(password_key)) if new_password is not None: key = derive_key(controller.id, new_password) controller.set_password(key) else: controller.clear_password()
def derive_key(self, password): dev = self._descriptor.open_device(TRANSPORT.CCID) controller = OathController(dev.driver) key = derive_key(controller.id, password) return b2a_hex(key).decode('utf-8')