Self-managed cryptography¶
Name¶
Self-managed cryptography
Summary¶
The system under development integrates a cryptographic library to perform cryptographic operations but manages the necessary cryptographic keys itself. Consequently, appropriate consideration should be given to ensure the confidentiality and integrity of these managed keys.
Parent¶
Problem¶
See Cryptographic key management
Solution¶
In this pattern implementation the system itself will manage the cryptographic keys, i.e. storage and retrieval when necessary. It is thus the responsibility of the system itself to take the necessary measures to ensure the confidentiality and integrity of the cryptographic keys throughout their lifetime. This involves storage of keys, their distribution as well as their revocation when necessary.
Roles¶
- Application (: Entity) interacts with a cryptographic library and manages the necessary cryptographic keys
- Application <- Cryptographic key management.Entity
- Cryptographer (: Cryptographic
primitive) a cryptographic library through which
Applicationperforms cryptographic operations such as encrypting or signing data elements - Key storage (: Storage) contains the cryptographic key material
- Application <- Cryptographic key management.Entity
Actions¶
- generate_key (: Action) generate a new cryptographic key according to the given configuration, if any
- store_key (: Action) store the given cryptographic key under the given identifier in the
Key storage - get_key (: Action) retrieve the information concerning the cryptographic key(s) as required by the
Cryptographerto function - crypto_action (: Action) request to perform a cryptographic operation, such as encrypt or sign data
Data elements¶
- keyConf (: Data) the configuration by which a key must be generated, e.g. length
- Tags: Untampered
- key (: Data) the cryptographic key to be used by the
Cryptographerfor the requested cryptographic actions- Tags: Untampered, Secret
- key <- Cryptographic key management.keyInfo
- id (: Data) identifies one or more cryptographic keys
- Tags: Untampered
- input (: Data) the data element(s) on which the cryptographic operation should be performed, e.g. the plaintext that has to be encrypted or signed
- output (: Data) the result from the cryptographic operation, e.g. a ciphertext or signed data element
- config (: Data) information necessary to configure the
Cryptographeraccording to the requirements of theApplication, e.g. selected ciphers and key length- Tags: Untampered
Behaviour¶
The generation of a new cryptographic key now also involves actually storing the key somewhere:
- The
Applicationrequests theCryptographerto generate a new key that, if provided, satisfies a given configuration. - The
Cryptographergenerates the requested key and replies it to theApplication. - The
Applicationstores the received inKey storageunder a given identifier.
In order to use a previously generated key the Application must now first retrieve it from Key storage using the identifier chosen when storing the key above.
The behaviour described below is further refined to specific cryptographic actions in the Cryptographic action pattern and its implementations.
- The
Applicationrequests the desired key fromKey storageby providing the corresponding identifier. - The
Key storagereplies toEntitywith the corresponding key, if the received identifier is valid. Otherwise an error is replied. - The
Applicationrequests theCryptographerto perform a cryptographic action and provides at least the input on which the action must be performed as well as the cryptographic key to be used. - The
Cryptographerperforms the requested operation and replies the result to theApplication.

Role considerations¶
Application¶
As the Application does process the used cryptographic keys their possible exposure should be limited.
For instance, one should avoid caching the keys, or any sensitive data for that matter.1
Furthermore, one should never hardcode cryptographic keys in Application or in any of its configuration files.3
Over time cryptographic keys will have to be replaced, e.g. after compromise, due to advances in computing power, or because a key has reached the end of its life cycle.
Consequently, it should be possible to easily replace cryptographic keys in a secure and reliable manner, which is not feasible when they are hardcoded into source code or configuration.
Key generation (Application, Cryptographer)¶
While the Application, along with Key storage, are responsible to manage existing keys, the Cryptographer should be used generate keys.2
Generating good, i.e. random and unpredictable, cryptographic keys is a complex task that should be left to specialised entities.
One should never attempt to design and implement own, custom, methods to generate cryptographic keys but instead use the appropriate function(s) offered by the used cryptographic library (represented by the Cryptographer in this pattern).
In case user provided passwords are used, a suitable key derivation function should be used to derive secure cryptographic keys.
Here too, the appropriate function(s) from the chosen cryptographic library, i.e. the Cryptographer should be used and one should never devise own, custom key derivation algorithms.
Furthermore, one should check whether the cryptographic library at hand uses up-to-date key derivation functions such as argon2, scrypt, or PBKDF2 (if FIPS-140 compliance is required).4
Key storage¶
The Key storage will persistently store cryptographic keys, and possibly associated material, whose confidentiality and integrity should be protected throughout their whole life cycle.
Whenever possible it is advised to take advantage of security features of the underlying platform, such as operating system and hardware, e.g. by storing keys in cryptographic modules.2 5
If such measures are not available access to the used storage medium should be limited through physical means, e.g. located in a protected area, and logical means, i.e. appropriate authentication and authorisation measures.
In order to allow verifying the integrity of cryptographic keys one can use MACs or digital signatures computed from the key.5 2 One should periodically verify the integrity of all keys.5 In order to restore keys after unauthorised modifications one or more copies a each key can be kept in physically separate locations.5
Finally, one should never store cryptographic keys alongside the data on which they where used.3 For example, a encryption key should not be stored together with the ciphertext that where constructed with it.
Data considerations¶
keyConf¶
Specialisation of Cryptographic key management.keyConf
key¶
Specialisation of Cryptographic key management.keyInfo
In this pattern implementation both integrity and confidentiality of the key should be protected while it is transmitted between the entities as well as at rest in Key storage.
Note that the confidentiality requirement can relaxed if it concerns only public keys, e.g. if the Cryptographer is only used to verify digital signatures.
id¶
The id determines which key is used to perform the cryptographic action.
Consequently, any attacker that can tamper with this identifier, e.g. change it to match a known key, can negate any security guarantees.
Appropriate measures should be taken to protect the id from tampering when transmitted over an uncontrolled channel and/or when stored by Application.
config¶
Specialisation of Cryptographic key management.config
Implementations¶
None
References¶
-
OWASP, ‘OWASP Top 10:2021 - A02: Cryptographic Failures'. [Online]. Available: https://owasp.org/Top10/A02_2021-Cryptographic_Failures/ ↩
-
OWASP, ‘Key Management Cheat Sheet’, OWASP Cheat Sheet Series. https://cheatsheetseries.owasp.org/cheatsheets/Key_Management_Cheat_Sheet.html ↩↩↩
-
OWASP, ‘Cryptographic Storage Cheat Sheet’, OWASP Cheat Sheet Series. https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html ↩↩
-
J. Steven, J. Manico, and D. Righetto, ‘Password Storage Cheat Sheet - Password Hashing Algorithms’, OWASP Cheat Sheet Series. https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#password-hashing-algorithms ↩
-
E. Barker, ‘Recommendation for Key Management: Part 1 – General’, NIST, 800–57 Part 1, May 2020. [Online]. Available: https://doi.org/10.6028/NIST.SP.800-57pt1r5 ↩↩↩↩