Uranium
Application Framework
Loading...
Searching...
No Matches
UM.Trust.TrustBasics Class Reference

Public Member Functions

 getHashAlgorithm (cls)
 
str getCentralStorageFilename (cls)
 
str getSignaturesLocalFilename (cls)
 
str getRootSignatureCategory (cls)
 
str getRootSignedManifestKey (cls)
 
str getSignaturePathForFile (cls, str filename)
 
str getRootSignatureEntry (cls)
 
Tuple[str, str] getFilePathInfo (cls, str base_folder_path, str current_full_path, str local_filename)
 
Optional[str] getFileHash (cls, str filename)
 
Optional[str] getSelfSignHash (cls, Dict[str, str] signatures)
 
Optional[str] getHashSignature (cls, str shash, RSAPrivateKey private_key, Optional[str] err_info=None)
 
Optional[str] getFileSignature (cls, str filename, RSAPrivateKey private_key)
 
bool removeCached (cls, str path)
 

Static Public Member Functions

None defaultViolationHandler (str message)
 
Tuple[RSAPrivateKeyWithSerialization, RSAPublicKey] generateNewKeyPair ()
 
Optional[RSAPrivateKey] loadPrivateKey (str private_filename, Optional[str] optional_password)
 
bool saveKeyPair ("RSAPrivateKeyWithSerialization" private_key, str private_path, str public_path, Optional[str] optional_password=None)
 
bool isPathInLocation (str location, str path)
 

Detailed Description

Anything shared between the main code and the (keygen/signing) scripts which does not need state.

See 'Trust' (below) and the 'createkeypair.py', 'signfile.py' and 'signfolder.py' scripts in the 'scripts' folder.

Member Function Documentation

◆ defaultViolationHandler()

None UM.Trust.TrustBasics.defaultViolationHandler ( str message)
static
This violationHandler is called after any other handlers

◆ generateNewKeyPair()

Tuple[RSAPrivateKeyWithSerialization, RSAPublicKey] UM.Trust.TrustBasics.generateNewKeyPair ( )
static
Create a new private-public key-pair.

:return: A tuple of private-key/public key.

◆ getFileHash()

Optional[str] UM.Trust.TrustBasics.getFileHash ( cls,
str filename )
Gets the hash for the provided file.

:param filename: The filename of the file to be hashed.
:return: The hash of the file.

◆ getFilePathInfo()

Tuple[str, str] UM.Trust.TrustBasics.getFilePathInfo ( cls,
str base_folder_path,
str current_full_path,
str local_filename )
'Signed folder' scenario: When walking over directory, it's convenient to have the full path on one hand,
and the 'name' of the file in the signature json file just below the signed directory on the other.

:param base_folder_path: The signed folder(name), where the signature file resides.
:param current_full_path: The full path to the current folder.
:param local_filename: The local filename of the current file.
:return: A tuple with the full path to the file on disk and the 'signed-folder-local' path of that same file.

◆ getFileSignature()

Optional[str] UM.Trust.TrustBasics.getFileSignature ( cls,
str filename,
RSAPrivateKey private_key )
Creates the signature for the (hash of the) provided file, given a private key.

:param filename: The file to be signed.
:param private_key: The private key used for signing.
:return: The signature if successful, 'None' otherwise.

◆ getHashAlgorithm()

UM.Trust.TrustBasics.getHashAlgorithm ( cls)
To ensure the same hash-algorithm is used by every part of this code.

:return: The hash-algorithm used for the entire 'suite'.

◆ getHashSignature()

Optional[str] UM.Trust.TrustBasics.getHashSignature ( cls,
str shash,
RSAPrivateKey private_key,
Optional[str] err_info = None )
 Creates the signature for the provided hash, given a private key.

:param shash: The provided string.
:param private_key: The private key used for signing.
:param err_info: Some optional extra info to be printed on error (for ex.: a filename the data came from).
:return: The signature if successful, 'None' otherwise.

◆ getRootSignatureCategory()

str UM.Trust.TrustBasics.getRootSignatureCategory ( cls)
'Signed folder' scenario: In anticipation of other keys, put the 'master' signature into this category.

:return: The json 'name' for the main signatures category.

◆ getRootSignatureEntry()

str UM.Trust.TrustBasics.getRootSignatureEntry ( cls)
'Single signed file' scenario: In anticipation of other keys, put the 'master' signature into this entry.

:return: The json 'name' for the main signature.

◆ getRootSignedManifestKey()

str UM.Trust.TrustBasics.getRootSignedManifestKey ( cls)
'Signed folder' scenario: This is the (json-)key for the hash that (self-)signs the signing file.

:return: The json 'name' for the key that contains the signature that signs all others' in the file.

◆ getSelfSignHash()

Optional[str] UM.Trust.TrustBasics.getSelfSignHash ( cls,
Dict[str, str] signatures )
 Make a hash for the signature 'file' itself, where the file is represented as a dictionary here.

:param signatures: A dictionary of (filename, file-hash-signature) pairs.
:return: A hash, which can be used for creating or checking against a self-signed manifest.

◆ getSignaturePathForFile()

str UM.Trust.TrustBasics.getSignaturePathForFile ( cls,
str filename )
'Single signed file' scenario: Get the name of the signature-file that should be located next to the file.

:param filename: The file that has (or needs to be) signed.
:return: The path of the signature-file of this file.

◆ getSignaturesLocalFilename()

str UM.Trust.TrustBasics.getSignaturesLocalFilename ( cls)
'Signed folder' scenario: Get the filename the signature file in a folder has.

:return: The filename of the signatures file (not the path).

◆ isPathInLocation()

bool UM.Trust.TrustBasics.isPathInLocation ( str location,
str path )
static
 Whether a path is a sub-folder (or equal) of a given location (path).

:param location: The given path the other path should be a (sub-)folder of.
:param path: The presumptive (sub-)folder.
:return: True if path is equal to or matches but deeper than location, False otherwise.

◆ loadPrivateKey()

Optional[RSAPrivateKey] UM.Trust.TrustBasics.loadPrivateKey ( str private_filename,
Optional[str] optional_password )
static
Load a private key from a file.

:param private_filename: The filename of the file containing the private key.
:param optional_password: The key can be signed with a password as well (or not).
:return: The private key contained in the file.

◆ removeCached()

bool UM.Trust.TrustBasics.removeCached ( cls,
str path )
 Removes any cached files and folders from a (folder) path (like __pycache__ and such).

This not only prevents people from messing with these hardly checkable things, but also makes the code have less
exceptions, since it can be assumed afterwards that the folder is in some sort of 'canonical' state.

:param path: The path to remove any cached files or folders from.
:return: Whether this operation succeeded.

◆ saveKeyPair()

bool UM.Trust.TrustBasics.saveKeyPair ( "RSAPrivateKeyWithSerialization" private_key,
str private_path,
str public_path,
Optional[str] optional_password = None )
static
Save a key-pair to two distinct files.

:param private_key: The private key to save. The public one will be generated from it.
:param private_path: Path to the filename where the private key will be saved.
:param public_path: Path to the filename where the public key will be saved.
:param optional_password: The private key can be signed with a password as well (or not).
:return: True on success.

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