Encryption & 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 AES-256-GCM.
-
API key lifecycle covers the full API key lifecycle from creation to revocation.
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_certificatesset andrevoked_certificatesset.HierarchicalMSPuses this for org and entity registration. - Limitation: 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)
There is no dedicated key_backup_manager.py. The actual mechanism is minimal:
- Generation runs
python -m hierachain key generate --output validator_key.json(CLI) to create an Ed25519 pair viaEd25519PrivateKey.generate()and write{private_key, public_key}hex JSON. 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). This is suitable for dev and test and is documented as not for production. For production use HSM or KMS through theKeyProviderinterface andHRC_VAULT_*. - 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 (actual)
- Validator and node key is a single Ed25519
KeyPairper node (viaLocalKeyProviderorFileVaultProvider), referenced byHRC_VALIDATOR_IDENTITYandHRC_MASTER_KEY_FILE/HRC_MASTER_KEY_SOURCE. - 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 (actual)
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]