Encryption and keys
This security layer manages system secrets. That includes encryption keys, signing key pairs and identity certificates.
Key manager and key providers
File: hierachain/security/key_manager.py, key_provider.py
This code creates and uses key pairs:
- Ed25519 support uses Ed25519 for fast and secure digital signatures.
-
Pluggable providers support several key sources:
LocalKeyProviderkeeps keys in local memory.FileVaultProviderkeeps encrypted data on disk with Fernet, using AES-128-CBC with HMAC.
-
The API server's
KeyManager.revoke_key()persists API key revocation through SQLite or a configured shared Redis backend. Revocation checks bypass cached key permissions.
Certificate and identity (MSP)
File: hierachain/security/msp.py (Certificate, CertificateAuthority, HierarchicalMSP)
This code manages lightweight internal identities, not X.509:
- Internal certificate is the
Certificatedataclass withcert_id,subject,public_key,signature(Ed25519 via_sign_certificate) andis_valid()time check. There is no X.509 ASN.1 and no mTLS. - CA operations are
CertificateAuthority.issue_certificate(),revoke_certificate()andverify_certificate()with an in-memoryissued_certificatesdictionary andrevoked_certificatesset.HierarchicalMSPuses this for org and entity registration. - Limitation: MSP certificate revocation lives only in memory. There is no CRL distribution, no X.509 chain validation and no mutual TLS between components. TLS is expected at the reverse proxy per architecture rules.
Key backup and recovery
Files: hierachain/cli/key.py, hierachain/security/key_provider.py (FileVaultProvider)
Operators manage backups through external tooling. The available key-file mechanisms are:
- Generation runs
hrc key generate --output validator_key.json(CLI) to create an Ed25519 pair viaEd25519PrivateKey.generate()and write{private_key, public_key}hex JSON. The new file has mode0600on POSIX systems; generation refuses to overwrite an existing file. Theshowandverifycommands inspect the result. - Encrypted vault (dev and test only) uses
FileVaultProviderto encrypt the vault file withPBKDF2HMAC(SHA256, 310_000 iter)andFernet(AES-128-CBC+HMAC). Its password is passed to the provider constructor. Production HSM or KMS support requires an application-specificKeyProvider; no built-in master-key provider exists.HRC_VAULT_TOKENandHRC_VAULT_PATHconfigure the separateSecretManagerVault backend. - There is no multi-location backup, no SHA-512 integrity check and no auto distribution or cleanup. Operators must copy
validator_key.jsonor.vaultwith external backup tooling.
Key scope
- Block signing loads a complete node identity through
HRC_VALIDATOR_IDENTITY, including an Ed25519 signing pair and transport keys. The CLI file containing onlyprivate_keyandpublic_keyis a provider file, not that complete identity. Back up the identity andHRC_BLOCK_TRUSTED_KEYS_FILEtogether; see Key Backup.HRC_MASTER_KEY_SOURCE=envis only a compatibility alias; other values and nonemptyHRC_MASTER_KEY_FILEare rejected because no master-key provider is implemented. - API keys are managed by
KeyManager(create, revoke, permission, cached viaKeyStorage/KeyCacheManager), not per-entity signing keys. - There is no built-in hierarchy like Master to Domain to Entity. Domain isolation relies on Sub-Chain separation and MSP roles.
Certificate initialization flow
graph LR
A[Generate Ed25519 Key Pair<br/>cli/key.py] --> B[HierarchicalMSP.register_entity<br/>msp.py]
B --> C[CA.issue_certificate<br/>Ed25519 sign]
C --> D[Store in issued_certificates]
D --> E[verify_certificate / revoke_certificate]