def program_static_password(self, slot, key, keyboard_layout): with self._open_device([OtpConnection]) as conn: session = YubiOtpSession(conn) scan_codes = encode(key, KEYBOARD_LAYOUT[keyboard_layout]) try: session.put_configuration(slot, StaticPasswordSlotConfiguration(scan_codes)) except CommandError as e: logger.debug("Failed to program static password", exc_info=e) return failure("write error") return success()
def test_slot_touch_triggered(self, session, read_config, slot): session.put_configuration(slot, HmacSha1SlotConfiguration(b"a" * 16)) state = read_config() assert state.is_configured(slot) assert not state.is_touch_triggered(slot) session.put_configuration(slot, StaticPasswordSlotConfiguration(b"a")) state = read_config() assert state.is_configured(slot) assert state.is_touch_triggered(slot) session.delete_slot(slot) state = read_config() assert not state.is_configured(slot) assert not state.is_touch_triggered(slot)
def static(ctx, slot, password, generate, length, keyboard_layout, no_enter, force): """ Configure a static password. To avoid problems with different keyboard layouts, the following characters (upper and lower case) are allowed by default: cbdefghijklnrtuv Use the --keyboard-layout option to allow more characters based on preferred keyboard layout. """ session = ctx.obj["session"] if password and len(password) > 38: ctx.fail("Password too long (maximum length is 38 characters).") if generate and not length: ctx.fail("Provide a length for the generated password.") if not password and not generate: password = click_prompt("Enter a static password") elif not password and generate: password = generate_static_pw(length, keyboard_layout) scan_codes = encode(password, keyboard_layout) if not force: _confirm_slot_overwrite(session.get_config_state(), slot) try: session.put_configuration( slot, StaticPasswordSlotConfiguration(scan_codes).append_cr( not no_enter), ctx.obj["access_code"], ctx.obj["access_code"], ) except CommandError as e: _failed_to_write_msg(ctx, e)