SecureNotes API¶
-
class
securenotes_api.AESKey(key=None, iv=None, logger=None)¶ Wrapper for AES key
This object is a convenience wrapper for
Crypto.Cipher.AESParameters: - key (byte) – bytes-representation of the AES key.
- iv (byte) – byte-representation of the initialization vector
- logger (
logging.Logger) – A logging instance
-
AES_KEYSIZE= 32¶
-
AES_SEGMENTSIZE= 128¶
-
decrypt(text)¶ Decrypt
text- Resets the AES key
- decodes the supplied text with Base64
- decrypts the the decoded and encrypted text
Parameters: text (byte) – base64-encoded and encrypted text Returns: decoded and decrypted text Return type: byte
-
encrypt(text)¶ Encrypt
text- Resets the AES key
- encrypts the supplied text with the AES key
- encodes the encrypted text with Base64
Parameters: text (byte) – bytestring to be encoded Returns: Base64-encoded and encrypted text Return type: byte
-
get_secret()¶ Return key and initialization vector :return: bytestring consisting of iv and key :rtype: byte
-
reset()¶ Reset to mint condition
-
class
securenotes_api.NotesAPIClient(username, password, rsa_password=None, logger=None)¶ API client for the Secure Notes service
-
RSA_KEYSIZE= 2048¶
-
add_note(title, content)¶ Upload an encrypted note
Parameters: - title (str) – Title that is saved unencrypted
- content (str) – Content that is saved encrypted
Returns: 0if successful, otherwise1
-
base_url= 'http://localhost:8000/notes/'¶
-
change_note(pk, title, content)¶ Change contents of note with ID
pkParameters: - pk – ID of the note on the server
- title – new title
- content – new content (will be encrypted)
Returns: 0if successful, otherwise1
-
create_rsa_key()¶ Upload private/public key.
Note
If replacing the upstream keys, ensure that encrypted data is re-crypted!
Hint
The generated RSA private and public keys are ready for use e.g. with the OpenSSL command line tool.
Returns: Crypto.PublicKey.RSA._RSAobjorNone
-
delete_note(pk)¶ Delete note from server
Parameters: pk (int) – ID of the note to be deleted Returns: 0if successful, otherwise1
-
download_aes_key(pk)¶ Download AES key for note with id
pkParameters: pk – ID of the note on server Returns: AES key or NoneReturn type: AESKey
-
get_note(pk)¶ Get note with unencrypted content from server
Parameters: pk – ID of the note on the server Returns: list of dict or None
-
get_rsa_key(username=None)¶ Retrieve private/public RSA key for user
username.Note
The private key is only returned for you!
Parameters: username – Name of user for which keys are to be retrieved. Returns: Crypto.PublicKey.RSA._RSAobjorNone
-
list_notes(page=1)¶ Get a list of notes
Parameters: page (int) – Page which shall be returned Returns: list of notes or None
Show all users that have been granted acces to note with ID
pkParameters: - pk – ID of the note to be queried
- page – If results are paginated, show this page
Returns: list or None
Share AES key with user
usernameParameters: - pk – ID of the note to be shared
- username – username of the receiving user
Returns: 0if successful, otherwise1
Revoke key to deny access for user
usernameParameters: - pk – ID of the note to be unshared
- username – username of the revoked user
Returns: 0if successful, otherwise1
-
upload_aes_key(aeskey, pk, username=None)¶ Upload AES key
aeskeythat was used to encrypt note with idpkParameters: - aeskey (
AESKey) – AES key that was used to encrypt data - pk (int) – ID for the encrypted content that was given by the server
- username – Name of the user whose public RSA key is used to encrypt the AES key
Returns: 0if successful, otherwise1- aeskey (
-