Class KeyStoreManager

java.lang.Object
net.vincent.communidirect.common.crypto.KeyStoreManager

public class KeyStoreManager extends Object
Loads the local identity keys and all trusted peer public keys as described in ~/.communidirect/keys.toml.

On first run, if keys.toml is absent, delegates to KeyGenerator.generate() to create a fresh identity before loading.

Peer public-key discovery uses a *.pub glob over the configured peers.public_keys_dir. Each file must contain either 32 raw Ed25519 bytes or the full 44-byte SubjectPublicKeyInfo DER encoding; both forms are accepted transparently. The map key is the filename stripped of its .pub extension (e.g. "vincent" for vincent.pub).

  • Constructor Details

    • KeyStoreManager

      public KeyStoreManager()
  • Method Details

    • load

      public void load() throws Exception
      Loads keys from disk. Generates a fresh identity if no keys.toml is found.
      Throws:
      Exception - on any IO or JCA error
    • getPrivateKey

      public PrivateKey getPrivateKey()
      Returns the local Ed25519 private key.
      Returns:
      this system's Ed25519 private key for signing outbound messages
    • getPrivateKey

      public PrivateKey getPrivateKey(String alias)
    • getOwnPublicKeyRaw

      public byte[] getOwnPublicKeyRaw()
      Returns the server's own 32-byte raw Ed25519 public key, loaded from keys/self.pub. Required by CdirMessage.decode(java.io.InputStream, java.security.PrivateKey, byte[]).
      Returns:
      the local 32-byte raw Ed25519 public key
    • getOwnPublicKeyRaw

      public byte[] getOwnPublicKeyRaw(String alias)
    • getActivePrivateKeyAlias

      public String getActivePrivateKeyAlias()
    • setActivePrivateKey

      public boolean setActivePrivateKey(String alias)
    • getAllPrivateKeys

      public Map<String, PrivateKey> getAllPrivateKeys()
    • getAllPrivateKeyAliases

      public List<String> getAllPrivateKeyAliases()
    • getPeerKey

      public PublicKey getPeerKey(String alias)
      Returns the public key for a peer alias, or null if unknown.
      Parameters:
      alias - peer alias (filename without .pub)
      Returns:
      the PublicKey for the alias, or null if not found
    • getAllPeerKeys

      public Map<String, PublicKey> getAllPeerKeys()
      Returns an unmodifiable view of all loaded peer public keys, keyed by alias.
      Returns:
      an immutable map of peer aliases to their Ed25519 public keys