def add_slot_credential(self, slot, key, touch): dev = self._descriptor.open_device(TRANSPORT.OTP) key = parse_b32_key(key) try: dev.driver.program_chalresp(int(slot), key, touch) except Exception as e: return str(e)
def ccid_add_credential( self, name, secret, issuer, oath_type, algo, digits, period, touch, overwrite=False): secret = parse_b32_key(secret) with self._open_oath() as oath_controller: try: self._unlock(oath_controller) cred_data = CredentialData( secret, issuer, name, OATH_TYPE[oath_type], ALGO[algo], int(digits), int(period), 0, touch ) if not overwrite: key = cred_data.make_key() if key in [cred.key for cred in oath_controller.list()]: return failure('credential_already_exists') oath_controller.put(cred_data) except APDUError as e: # NEO doesn't return a no space error if full, # but a command aborted error. Assume it's because of # no space in this context. if e.sw in (SW.NO_SPACE, SW.COMMAND_ABORTED): return failure('no_space') else: raise return success()
def add_credential(self, name, key, oath_type, digits, algo, touch, 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)) try: key = parse_b32_key(key) except Exception as e: return str(e) try: controller.put(key, name, oath_type, digits, algo=algo, require_touch=touch) except APDUError as e: # NEO doesn't return a no space error if full, # but a command aborted error. Assume it's because of # no space in this context. if e.sw == SW.NO_SPACE or e.sw == SW.COMMAND_ABORTED: return 'No space' else: raise
def add_slot_credential(self, slot, key, touch): key = parse_b32_key(key) with self._descriptor.open_device(TRANSPORT.OTP) as dev: controller = OtpController(dev.driver) try: controller.program_chalresp(int(slot), key, touch) except Exception as e: return str(e)
def add_slot_credential(self, slot, key, touch): dev = self._descriptor.open_device(TRANSPORT.OTP) key = parse_b32_key(key) if len(key) > 64: # Keys longer than 64 bytes are hashed. key = hashlib.sha1(key).digest() if len(key) > 20: return 'Over 20 bytes' key += b'\x00' * (20 - len(key)) # Keys must be padded to 20 bytes. dev.driver.program_chalresp(int(slot), key, touch)
def add_slot_credential(self, slot, key, touch): try: key = parse_b32_key(key) with self._descriptor.open_device(TRANSPORT.OTP) as dev: controller = OtpController(dev.driver) controller.program_chalresp(int(slot), key, touch) return {'success': True, 'error': None} except Exception as e: if str(e) == 'Incorrect padding': return {'success': False, 'error': 'wrong padding'} if str(e) == 'key lengths >20 bytes not supported': return {'success': False, 'error': 'too large key'} return {'success': False, 'error': str(e)}
def add_credential(self, name, key, oath_type, digits, algo, touch, 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)) try: key = parse_b32_key(key) except Exception as e: return str(e) controller.put(key, name, oath_type, digits, algo=algo, require_touch=touch)
def add_credential(self, name, secret, issuer, oath_type, algo, digits, period, touch): dev = self._descriptor.open_device(TRANSPORT.CCID) controller = OathController(dev.driver) self._unlock(controller) try: secret = parse_b32_key(secret) except Exception as e: return str(e) try: controller.put( CredentialData(secret, issuer, name, OATH_TYPE[oath_type], ALGO[algo], int(digits), int(period), 0, touch)) except APDUError as e: # NEO doesn't return a no space error if full, # but a command aborted error. Assume it's because of # no space in this context. if e.sw in (SW.NO_SPACE, SW.COMMAND_ABORTED): return 'No space' else: raise
def add_credential( self, name, secret, issuer, oath_type, algo, digits, period, touch): dev = self._descriptor.open_device(TRANSPORT.CCID) controller = OathController(dev.driver) self._unlock(controller) try: secret = parse_b32_key(secret) except Exception as e: return str(e) try: controller.put(CredentialData( secret, issuer, name, OATH_TYPE[oath_type], ALGO[algo], int(digits), int(period), 0, touch )) except APDUError as e: # NEO doesn't return a no space error if full, # but a command aborted error. Assume it's because of # no space in this context. if e.sw in (SW.NO_SPACE, SW.COMMAND_ABORTED): return 'No space' else: raise
def otp_add_credential(self, slot, key, touch): key = parse_b32_key(key) with self._open_otp() as otp_controller: otp_controller.program_chalresp(int(slot), key, touch) return success()