java.lang.Object
net.i2p.router.KeyManager

public class KeyManagerextends Object
Manages all router cryptographic key pairs including persistent storage of router keys and in-memory management of LeaseSet keys for secure communications.
  • Field Details

    • _log

      private final Log _log
      Logger for the key manager.
    • _context

      private final RouterContext _context
      The router context.
    • _privateKey

      private PrivateKey _privateKey
      Our router's private key.
    • _publicKey

      private PublicKey _publicKey
      Our router's public key.
    • _signingPrivateKey

      private SigningPrivateKey _signingPrivateKey
      Our router's signing private key.
    • _signingPublicKey

      private SigningPublicKey _signingPublicKey
      Our router's signing public key.
    • _leaseSetKeys

      private final Map<Hash, LeaseSetKeys> _leaseSetKeys
      The lease set keys, by destination hash.
    • PROP_KEYDIR

      public static final String PROP_KEYDIR
      Property key for keydir.
      See Also:
    • DEFAULT_KEYDIR

      public static final String DEFAULT_KEYDIR
      Default keydir.
      See Also:
    • KEYFILE_PRIVATE_ENC

      public static final String KEYFILE_PRIVATE_ENC
      Path to the private enc key file.
      See Also:
    • KEYFILE_PUBLIC_ENC

      public static final String KEYFILE_PUBLIC_ENC
      Path to the public enc key file.
      See Also:
    • KEYFILE_PRIVATE_SIGNING

      public static final String KEYFILE_PRIVATE_SIGNING
      Path to the private signing key file.
      See Also:
    • KEYFILE_PUBLIC_SIGNING

      public static final String KEYFILE_PUBLIC_SIGNING
      Path to the public signing key file.
      See Also:
  • Constructor Details

    • KeyManager

      public KeyManager(RouterContext context)
      Create a key manager.
      Parameters:
      context - the router context
  • Method Details

    • setKeys

      public void setKeys(PublicKey key1, PrivateKey key2, SigningPublicKey key3, SigningPrivateKey key4)
      Configure the router's keys.
      Parameters:
      key1 - the router's public encryption key, published to peers and clients
      key2 - the router's private encryption key
      key3 - the router's signing public key, which certifies the router's identity
      key4 - the router's signing private key
    • getPrivateKey

      public PrivateKey getPrivateKey()
      Router key.
      Returns:
      will be null on error or before startup() or setKeys(PublicKey, PrivateKey, SigningPublicKey, SigningPrivateKey) is called
    • getPublicKey

      public PublicKey getPublicKey()
      Router key.
      Returns:
      will be null on error or before startup() or setKeys() is called
    • getSigningPrivateKey

      public SigningPrivateKey getSigningPrivateKey()
      Router key.
      Returns:
      will be null on error or before startup() or setKeys() is called
    • getSigningPublicKey

      public SigningPublicKey getSigningPublicKey()
      Router key.
      Returns:
      will be null on error or before startup() or setKeys() is called
    • registerKeys

      public void registerKeys(Destination dest, SigningPrivateKey leaseRevocationPrivateKey, PrivateKey endpointDecryptionKey)
      Client with a single key.
      Parameters:
      dest - the destination these keys belong to
      leaseRevocationPrivateKey - unused, may be null
      endpointDecryptionKey - the key that decrypts transport messages to the destination
    • registerKeys

      public void registerKeys(Destination dest, SigningPrivateKey leaseRevocationPrivateKey, List<PrivateKey> endpointDecryptionKeys)
      Client with multiple keys.
      Parameters:
      dest - the destination these keys belong to
      leaseRevocationPrivateKey - unused, may be null
      endpointDecryptionKeys - the keys that decrypt transport messages to the destination
    • queueWrite

      private void queueWrite()
      Queue a background job to synchronize keys to disk. This method is called internally after key modifications.
    • unregisterKeys

      public LeaseSetKeys unregisterKeys(Destination dest)
      Unregister keys for a destination, removing them from memory. Does not delete backup files from disk.
      Parameters:
      dest - the destination whose keys should be unregistered
      Returns:
      the LeaseSetKeys that were removed, or null if not found
    • getKeys

      public LeaseSetKeys getKeys(Destination dest)
      The keys registered for a destination.
      Parameters:
      dest - the destination to look up
      Returns:
      the LeaseSetKeys for the destination, or null if not found
    • getKeys

      public LeaseSetKeys getKeys(Hash dest)
      Client session lease set keys.
      Parameters:
      dest - the hash of the destination to look up
      Returns:
      the LeaseSetKeys registered for the destination, or null if there are none