Ubirch Protocol Python
List of all members
Protocol Class Reference

Detailed Description

Ubirch Protocol: handle signatures and UPP's and create message objects.

Inheritance diagram for Protocol:
Proto

Constructor & Destructor Documentation

◆ __init__()

None __init__ (   self,
dict   signatures = None 
)

Initialize the protocol.

Parameters
signaturesPreviously known signatures

Member Function Documentation

◆ _hash()

bytes _hash (   self,
bytes  message 
)
private

Hash the message before signing.

Override this method if a different hash algorithm is used. Default is SHA512.

Parameters
messageThe message bytes
Returns
The digest in bytes

◆ _sign()

bytes _sign (   self,
UUID  uuid,
bytes  message 
)
private

Sign the request when finished.

Note
IMPORTANT: This function needs to be implemented with the Keystore of choice and its .find_signing_key() and .sign() functions

This function also takes care of the hashing, before signing, depending on the key type.

Parameters
uuidThe uuid of the sender to identify the correct key pair
messageThe bytes to sign
Returns
NotImplementedError

Reimplemented in Proto.

◆ _verify()

def _verify (   self,
UUID  uuid,
bytes  message,
bytes  signature 
)
private

Verify the message.

Note
IMPORTANT: This function needs to be implemented with the Keystore of choice and its .find_verifying_key() and .verify() functions

Throws exception if not verifiable. This function also takes care of the hashing, before verifying, depending on the key type.

Parameters
uuidThe uuid of the sender to identify the correct key pair
messageThe message bytes to verify
signatureThe signature to use for verification
Returns
NotImplementedError

Reimplemented in Proto.

◆ get_saved_signatures()

dict get_saved_signatures (   self)

Get the saved signatures to store them persistently.

Returns
A dictionary of signatures (uuid -> bytes)

◆ get_unpacked_index()

int get_unpacked_index (   self,
int  versionByte,
int  targetField 
)

Get the index of a given target field for a UPP with the given version byte Throws a ValueError if the version byte (lower four bits) is invalid.

Parameters
versionByteThe first byte of an unpacked upp (first element of the list)
targetFieldOne off "UNPACKED_UPP_*"
Returns
The index of the field on success

◆ keyreg_jsonstr_signed()

str keyreg_jsonstr_signed (   self,
UUID  uuid,
dict  keyinfo_dict 
)

Takes a keyinfo-json-str and embeds into a signed json keyreg message.

:param uuid: the uuid of the device the keyinfo belongs to :param keyinfo_dict: the public key info object :return: the keyreg json as string

◆ message_chained()

bytes message_chained (   self,
UUID  uuid,
int  type,
any  payload 
)

Create a new chained ubirch-protocol message.

Stores the context, the last signature, to be included in the next message.

Parameters
uuidThe uuid of the device that sends the message, part of the envelope
typeA hint of the type of message sent (0-255)
payloadThe actual message payload
Returns
The encoded and signed message

◆ message_signed()

bytes message_signed (   self,
UUID  uuid,
int  type,
any  payload,
bool   save_signature = False 
)

Create a new signed ubirch-protocol message.

Parameters
uuidThe uuid of the device that sends the message, part of the envelope
typeA hint of the type of message sent (0-255)
payloadThe actual message payload
save_signatureSave the signature of the created message so the next chained message contains it
Returns
The encoded and signed message

◆ reset_signature()

None reset_signature (   self,
UUID  uuid 
)

Reset the last saved signature for this UUID.

Parameters
uuidThe UUID to reset

◆ set_saved_signatures()

None set_saved_signatures (   self,
dict  signatures 
)

Set known signatures from devices we have talked to.

Parameters
signaturesThe saved signatures as a dictionary (uuid -> bytes)

◆ unpack_upp()

list unpack_upp (   self,
bytes  msgpackUPP 
)

Unpack a UPP (msgpack) Throws an exception if the UPP can't be unpacked Returns The unpacked upp as a list.

Parameters
msgpackUPPThe msgpack encoded message
Returns
The unpacked message

◆ upp_msgpack_split_signature()

(bytes, bytes) upp_msgpack_split_signature (   self,
  msgpackUPP 
)

Separate the signature from the msgpack.

Parameters
msgpackUPPThe msgpack encoded upp
Returns
A tuple consisting of the message without the signature and the signature

◆ verify_signature()

bool verify_signature (   self,
UUID  uuid,
bytes  msgpackUPP 
)

Verify the integrity of the message and decode the contents Raises an value error when the message is too short.

Parameters
uuidThe uuid of the sender of the message
msgpackUPPThe msgpack encoded message
Returns
The decoded message

The documentation for this class was generated from the following file: