Library Internals¶
This document describes the internals of the library. It is intended for developers who want to contribute to the library.
ukey2¶
For some reason, Sphinx cannot seem to resolve some of the typehints from the protobuf generated code. That’s why some typehints may look odd.
Decode a GenericPublicKey as an EllipticCurvePublicKey.
- Parameters:
generic_key (securemessage_pb2.GenericPublicKey) – The public key to decode
- Raises:
ValueError – If the key is not EC_P256
- Returns:
The decoded public key
- Return type:
ec.EllipticCurvePublicKey
Derive the keys for a session.
- Parameters:
- Returns:
The derived keys
- Return type:
Perform a client key exchange.
- Parameters:
reader (asyncio.StreamReader) – The reader
writer (asyncio.StreamWriter) – The writer
- Returns:
The keychain, or None if the exchange failed
- Return type:
Keychain | None
Perform a server key exchange.
- Parameters:
reader (asyncio.StreamReader) – The reader
writer (asyncio.StreamWriter) – The writer
- Returns:
The keychain, or None if the exchange failed
- Return type:
Keychain | None
Encode an EllipticCurvePublicKey as a GenericPublicKey.
- Parameters:
public_key (ec.EllipticCurvePublicKey) – The public key to encode
- Returns:
The encoded public key
- Return type:
securemessage_pb2.GenericPublicKey
Convert a two’s complement byte array to an integer.
Construct an alert message.
- Parameters:
alert_type (ukey_pb2.Ukey2Alert.AlertType) – The alert type
error_message (str) – The error message
- Returns:
The constructed alert message
- Return type:
ukey_pb2.Ukey2Message
Parse a CLIENT_FINISH message.
- Parameters:
raw_message (bytes) – The raw CLIENT_FINISH message
commitment (ukey_pb2.Ukey2ClientInit.CipherCommitment) – The cipher commitment from the client
writer (asyncio.StreamWriter) – The writer to send alerts to
- Returns:
The client’s public key, or None if the message is invalid
- Return type:
ec.EllipticCurvePublicKey | None
Parse a CLIENT_INIT message.
- Parameters:
ukey_client_init (ukey_pb2.Ukey2ClientInit) – The CLIENT_INIT message
writer (asyncio.StreamWriter) – The writer to send alerts to
- Returns:
The next protocol and cipher commitment, or None if the message is invalid
- Return type:
tuple[str, ukey_pb2.Ukey2ClientInit.CipherCommitment] | None
Send a SERVER_INIT message.
- Parameters:
private_key (ec.EllipticCurvePrivateKey) – The server’s private key
cipher_commitment (ukey_pb2.Ukey2ClientInit.CipherCommitment) – The cipher commitment from the client
writer (asyncio.StreamWriter) – The writer to send the message to
- Returns:
The serialized SERVER_INIT message (for key derivation)
- Return type:
Swap the perspective of a keychain.
Convert an integer to a two’s complement byte array.
Send an alert message and close the connection.
- Parameters:
alert_type (ukey_pb2.Ukey2Alert.AlertType) – The alert type
alert_message (str) – The alert message
writer (asyncio.StreamWriter) – The writer to send the alert to
- Return type:
None
mdns¶
The mdns
module provides an interface to the mDNS implementation on the system.
It also handles BLE advertisement.
Communication with the mDNS implementation and BlueZ is done via D-Bus.
- Return type:
None
- Parameters:
timeout (float)
- Return type:
Queue[AsyncServiceInfo]
- Return type:
None