pub struct SecurityManager { /* private fields */ }Expand description
High-level NDN security manager.
Owns a key store and certificate cache, and provides operations for:
- Key pair generation
- Self-signed certificate issuance (trust-anchor certificates)
- Certificate issuance (signing a key Data packet with another key)
- Trust anchor registration
- Retrieving a signer for a key name
For production use, replace MemKeyStore with a file-backed store.
Implementations§
Source§impl SecurityManager
impl SecurityManager
pub fn new() -> Self
Sourcepub fn generate_ed25519(&self, key_name: Name) -> Result<Name, TrustError>
pub fn generate_ed25519(&self, key_name: Name) -> Result<Name, TrustError>
Generate a new Ed25519 key pair using a cryptographically random seed and store it in the in-memory key store.
key_name should follow NDN key naming convention:
/<identity>/KEY/<key-id>.
Returns the key name on success.
Sourcepub fn generate_ed25519_from_seed(
&self,
key_name: Name,
seed: &[u8; 32],
) -> Result<Name, TrustError>
pub fn generate_ed25519_from_seed( &self, key_name: Name, seed: &[u8; 32], ) -> Result<Name, TrustError>
Generate a new Ed25519 key from explicit raw seed bytes (for testing).
Sourcepub fn issue_self_signed(
&self,
key_name: &Name,
public_key_bytes: Bytes,
validity_ms: u64,
) -> Result<Certificate, TrustError>
pub fn issue_self_signed( &self, key_name: &Name, public_key_bytes: Bytes, validity_ms: u64, ) -> Result<Certificate, TrustError>
Issue a self-signed certificate (trust anchor).
The certificate is inserted into both the cert cache and the anchor set.
validity_ms is the certificate lifetime in milliseconds; pass u64::MAX
for non-expiring anchors.
Sourcepub async fn certify(
&self,
subject_key_name: &Name,
subject_public_key: Bytes,
issuer_key_name: &Name,
validity_ms: u64,
) -> Result<Certificate, TrustError>
pub async fn certify( &self, subject_key_name: &Name, subject_public_key: Bytes, issuer_key_name: &Name, validity_ms: u64, ) -> Result<Certificate, TrustError>
Issue a certificate for subject_key signed by issuer_key.
Both keys must already exist in the key store. The issuer signs a
complete NDN certificate Data packet (TLV-encoded) whose Content
carries the subject’s public key and validity period. The resulting
Certificate is stored in the cert cache; the full wire-format Data
packet is stored in Certificate::wire.
Sourcepub fn add_trust_anchor(&self, cert: Certificate)
pub fn add_trust_anchor(&self, cert: Certificate)
Register a pre-existing certificate as a trust anchor.
Sourcepub fn trust_anchor(&self, key_name: &Name) -> Option<Certificate>
pub fn trust_anchor(&self, key_name: &Name) -> Option<Certificate>
Look up a trust anchor by key name.
Sourcepub fn trust_anchor_names(&self) -> Vec<Arc<Name>>
pub fn trust_anchor_names(&self) -> Vec<Arc<Name>>
List all trust anchor names.
Sourcepub async fn get_signer(
&self,
key_name: &Name,
) -> Result<Arc<dyn Signer>, TrustError>
pub async fn get_signer( &self, key_name: &Name, ) -> Result<Arc<dyn Signer>, TrustError>
Retrieve a signer for the given key name.
Sourcepub fn get_signer_sync(
&self,
key_name: &Name,
) -> Result<Arc<dyn Signer>, TrustError>
pub fn get_signer_sync( &self, key_name: &Name, ) -> Result<Arc<dyn Signer>, TrustError>
Retrieve a signer synchronously (for use in non-async contexts).
Sourcepub fn cert_cache(&self) -> &CertCache
pub fn cert_cache(&self) -> &CertCache
Access the certificate cache (e.g., to pass to a Validator).
Sourcepub fn from_pib(pib: &FilePib, identity: &Name) -> Result<Self, TrustError>
pub fn from_pib(pib: &FilePib, identity: &Name) -> Result<Self, TrustError>
Build a SecurityManager by loading an identity from a FilePib.
- Loads the signing key for
identityfrom the PIB. - If a certificate is present for that identity, inserts it into the cert cache.
- Loads all trust anchors stored in the PIB.
Sourcepub fn auto_init(
identity: &Name,
pib_path: &Path,
) -> Result<(Self, bool), TrustError>
pub fn auto_init( identity: &Name, pib_path: &Path, ) -> Result<(Self, bool), TrustError>
Auto-initialize security state from a PIB directory.
If the PIB has no keys, generates a new Ed25519 identity with a self-signed certificate and stores it. If keys already exist, loads the first identity found.
Returns (SecurityManager, bool) where the bool is true if a
new identity was generated (useful for logging).