nitrokey.nk3.secrets_app

Oath Authenticator client

Used through CTAPHID transport, via the custom vendor command. Can be used directly over CCID as well.

exception nitrokey.nk3.secrets_app.SecretsAppException

Bases: Exception

SecretsAppException(code: str, context: str)

__init__(code, context)
Parameters:
  • code (str)

  • context (str)

Return type:

None

to_id()
Return type:

SecretsAppExceptionID

to_string()
Return type:

str

code: str
context: str
exception nitrokey.nk3.secrets_app.SecretsAppHealthCheckException

Bases: Exception

class nitrokey.nk3.secrets_app.Algorithm

Bases: Enum

Sha1 = 1
Sha256 = 2
Sha512 = 3
class nitrokey.nk3.secrets_app.CCIDInstruction

Bases: Enum

Select = 164
class nitrokey.nk3.secrets_app.Instruction

Bases: Enum

Calculate = 162
CalculateAll = 164
ChangePIN = 179
Delete = 2
GetCredential = 181
List = 161
Put = 1
Reset = 4
SendRemaining = 165
SetCode = 3
SetPIN = 180
UpdateCredential = 183
Validate = 163
VerifyCode = 177
VerifyPIN = 178
class nitrokey.nk3.secrets_app.Kind

Bases: Enum

classmethod from_attribute_byte(attribute_byte)
Parameters:

attribute_byte (bytes)

Return type:

str

classmethod from_attribute_byte_type(a)
Parameters:

a (int)

Return type:

Kind

Hmac = 64
Hotp = 16
HotpReverse = 48
NotSet = 240
Totp = 32
class nitrokey.nk3.secrets_app.ListItem

Bases: object

ListItem(kind: ‘Kind’, algorithm: ‘Algorithm’, label: bytes, properties: nitrokey.nk3.secrets_app.ListItemProperties)

__init__(kind, algorithm, label, properties)
Parameters:
Return type:

None

classmethod get_type_name(x)
Parameters:

x (Any)

Return type:

str

algorithm: Algorithm
kind: Kind
label: bytes
properties: ListItemProperties
class nitrokey.nk3.secrets_app.ListItemProperties

Bases: object

ListItemProperties(touch_required: bool, secret_encryption: bool, pws_data_exist: bool)

__init__(touch_required, secret_encryption, pws_data_exist)
Parameters:
  • touch_required (bool)

  • secret_encryption (bool)

  • pws_data_exist (bool)

Return type:

None

classmethod from_byte(b)
Parameters:

b (int)

Return type:

ListItemProperties

pws_data_exist: bool
secret_encryption: bool
touch_required: bool
class nitrokey.nk3.secrets_app.PasswordSafeEntry

Bases: object

PasswordSafeEntry(login: Optional[bytes], password: Optional[bytes], metadata: Optional[bytes], properties: Optional[bytes] = None, name: Optional[bytes] = None)

__init__(login, password, metadata, properties=None, name=None)
Parameters:
  • login (bytes | None)

  • password (bytes | None)

  • metadata (bytes | None)

  • properties (bytes | None)

  • name (bytes | None)

Return type:

None

tlv_encode()
Return type:

list[Entry]

login: bytes | None
metadata: bytes | None
name: bytes | None = None
password: bytes | None
properties: bytes | None = None
class nitrokey.nk3.secrets_app.RawBytes

Bases: object

RawBytes(data: list[int])

__init__(data)
Parameters:

data (list[int])

Return type:

None

data: list[int]
class nitrokey.nk3.secrets_app.SecretsApp

Bases: object

This is a Secrets App client https://github.com/Nitrokey/trussed-secrets-app

__init__(dev, logfn=None)
Parameters:
  • dev (NK3)

  • logfn (Callable[[str], Any] | None)

calculate(cred_id, challenge=None)

Calculate the OTP code for the credential named cred_id, and with challenge challenge.

Parameters:
  • cred_id (bytes) – The name of the credential

  • challenge (int | None) – Challenge for the calculations (TOTP only). Should be equal to: timestamp/period. The commonly used period value is 30.

Returns:

OTP code as a byte string

Return type:

bytes

change_pin_raw(password, new_password)
Parameters:
  • password (str)

  • new_password (str)

Return type:

None

clear_code()

Clear the passphrase used to authenticate to other commands.

Return type:

None

delete(cred_id)

Delete credential with the given id. Does not fail, if the given credential does not exist. :param credid: Credential ID

Parameters:

cred_id (bytes)

Return type:

None

classmethod encode_properties_to_send(touch_button_required, pin_based_encryption, tlv=False)

Encode properties structure into a single byte @param touch_button_required: whether the touch button use is required @param pin_based_encryption: whether the PIN-encryption is requested (only during registration) @param tlv: set True, if this should be encoded as TLV, as opposed to the default “TV”, w/o L

Parameters:
  • touch_button_required (bool)

  • pin_based_encryption (bool)

  • tlv (bool)

Return type:

RawBytes

feature_active_PIN_authentication()
Return type:

bool

feature_challenge_response_support()
Return type:

bool

feature_extended_list()
Return type:

bool

feature_old_application_version()
Return type:

bool

feature_pws_support()
Return type:

bool

get_credential(cred_id)
Parameters:

cred_id (bytes)

Return type:

PasswordSafeEntry

get_feature_status_cached()
Return type:

SelectResponse

get_response_for_secret(challenge, secret)
Parameters:
  • challenge (bytes)

  • secret (bytes)

Return type:

bytes

get_secret_for_passphrase(passphrase)
Parameters:

passphrase (str)

Return type:

bytes

is_pin_healthy()
Return type:

bool

list(extended=False)

Return a list of the registered credentials :return: List of bytestrings, or tuple of bytestrings, if “extended” switch is provided @deprecated

Parameters:

extended (bool)

Return type:

list[Tuple[bytes, bytes] | bytes]

list_with_properties(version=1)

Return a list of the registered credentials with properties :return: List of ListItems

Parameters:

version (int)

Return type:

List[ListItem]

protocol_v2_confirm_all_requests_with_pin()
Return type:

bool

protocol_v3_separate_pin_and_no_pin_space()
Return type:

bool

register(credid, secret=b'00000000000000000000', digits=6, kind=Kind.NotSet, algo=Algorithm.Sha1, initial_counter_value=0, touch_button_required=False, pin_based_encryption=False, login=None, password=None, metadata=None)

Register new OTP Credential :param credid: Credential ID :param secret: The shared key :param digits: Digits of the produced code :param kind: OTP variant - HOTP or TOTP :param algo: The hash algorithm to use - SHA1, SHA256 or SHA512 :param initial_counter_value: The counter’s initial value for the HOTP Credential (HOTP only) :param touch_button_required: User Presence confirmation is required to use this Credential :param pin_based_encryption: User preference for additional PIN-based encryption :param login: Login field for Password Safe :param password: Password field for Password Safe :param metadata: Metadata field for Password Safe :return: None

Parameters:
  • credid (bytes)

  • secret (bytes)

  • digits (int)

  • kind (Kind)

  • algo (Algorithm)

  • initial_counter_value (int)

  • touch_button_required (bool)

  • pin_based_encryption (bool)

  • login (bytes | None)

  • password (bytes | None)

  • metadata (bytes | None)

Return type:

None

register_yk_hmac(slot, secret)

Register a Yubikey-compatible challenge-response slot. @param slot: challenge-response slot @param secret: the secret

Parameters:
  • slot (int)

  • secret (bytes)

Return type:

None

rename_credential(cred_id, new_name)

Rename credential. An alias for the update_credential() call. @param cred_id: The credential ID to modify @param new_name: New ID for the credential

Parameters:
  • cred_id (bytes)

  • new_name (bytes)

Return type:

None

reset()

Remove all credentials from the database

Return type:

None

select()

Execute SELECT command, which returns details about the device, including the challenge needed for the authentication. :return SelectResponse Status structure. Challenge and Algorithm fields are None, if the passphrase is not set.

Return type:

SelectResponse

set_code(passphrase)

Set the code with the defaults as suggested in the protocol specification: - https://developers.yubico.com/OATH/YKOATH_Protocol.html

Parameters:

passphrase (str)

Return type:

None

set_code_raw(key, challenge, response)

Set or clear the passphrase used to authenticate to other commands. Raw interface. :param key: User passphrase processed through PBKDF2(ID,1000), and limited to the first 16 bytes. :param challenge: The current challenge taken from the SELECT command. :param response: The data calculated on the client, as a proof of a correct setup.

Parameters:
  • key (bytes)

  • challenge (bytes)

  • response (bytes)

Return type:

None

set_pin_raw(password)
Parameters:

password (str)

Return type:

None

update_credential(cred_id, new_name=None, login=None, password=None, metadata=None, touch_button=None)

Update credential fields - name, attributes, and PWS fields. Unpopulated fields will not be encoded and used during the update process (won’t change the current value). @param cred_id: The credential ID to modify @param new_name: New ID for the credential @param login: New login field content @param password: New password field content @param metadata: New metadata field content @param touch_button: Set if the touch button use should be required

Parameters:
  • cred_id (bytes)

  • new_name (bytes | None)

  • login (bytes | None)

  • password (bytes | None)

  • metadata (bytes | None)

  • touch_button (bool | None)

Return type:

None

validate(passphrase)

Authenticate using a passphrase

Parameters:

passphrase (str)

Return type:

None

validate_raw(challenge, response)

Authenticate using a passphrase. Raw interface. :param challenge: The current challenge taken from the SELECT command. :param response: The response calculated against the challenge and the secret

Parameters:
  • challenge (bytes)

  • response (bytes)

Return type:

bytes

verify_code(cred_id, code)

Proceed with the incoming OTP code verification (aka reverse HOTP). :param cred_id: The name of the credential :param code: The HOTP code to verify. u32 representation. :return: fails with OTPAppException error; returns True if code matches the value calculated internally.

Parameters:
  • cred_id (bytes)

  • code (int)

Return type:

bool

verify_pin_raw(password)
Parameters:

password (str)

Return type:

None

dev: NK3
log: Logger
logfn: Callable[[str], Any]
write_corpus_fn: Callable[[Instruction | CCIDInstruction, bytes], Any] | None
class nitrokey.nk3.secrets_app.SecretsAppExceptionID

Bases: IntEnum

__new__(value)
ClassNotSupported = 28160
CommandChainingNotSupported = 26756
ConditionsOfUseNotSatisfied = 27013
FunctionNotSupported = 27265
IncorrectDataParameter = 27264
IncorrectP1OrP2Parameter = 27270
InstructionNotSupportedOrInvalid = 27904
KeyReferenceNotFound = 27272
LogicalChannelNotSupported = 26753
MoreDataAvailable = 25087
NotEnoughMemory = 27268
NotFound = 27266
OperationBlocked = 27011
SecureMessagingNotSupported = 26754
SecurityStatusNotSatisfied = 27010
Success = 36864
UnspecifiedCheckingError = 28416
UnspecifiedNonpersistentExecutionError = 25600
UnspecifiedPersistentExecutionError = 25856
VerificationFailed = 25344
WrongLength = 26368
class nitrokey.nk3.secrets_app.SelectResponse

Bases: object

SelectResponse(version: Optional[bytes], pin_attempt_counter: Optional[int], salt: Optional[bytes], challenge: Optional[bytes], algorithm: Optional[bytes], serial_number: Optional[bytes])

__init__(version, pin_attempt_counter, salt, challenge, algorithm, serial_number)
Parameters:
  • version (bytes | None)

  • pin_attempt_counter (int | None)

  • salt (bytes | None)

  • challenge (bytes | None)

  • algorithm (bytes | None)

  • serial_number (bytes | None)

Return type:

None

version_str()
Return type:

str

algorithm: bytes | None
challenge: bytes | None
pin_attempt_counter: int | None
salt: bytes | None
serial_number: bytes | None
version: bytes | None
class nitrokey.nk3.secrets_app.Tag

Bases: Enum

Algorithm = 123
Challenge = 116
CredentialId = 113
InitialCounter = 122
Key = 115
NameList = 114
NewPassword = 129
PINCounter = 130
Password = 128
Properties = 120
PwsLogin = 131
PwsMetadata = 133
PwsPassword = 132
Response = 117
SerialNumber = 143
Version = 121