java.lang.Object
net.i2p.i2pcontrol.security.KeyStoreProvider
Provider for managing I2PControl keystore operations. Handles loading and accessing SSL certificates for secure connections.
Field Summary
Modifier and TypeFieldDescriptionprivate KeyStoreThe keystore, opened on first use.private static final LogLogger for this class.private final StringDirectory plugins are installed in.static final StringKey algorithm used for a generated I2PControl certificate.static final StringAlias the generated certificate is stored under in the key store.static final StringSubject domain a generated certificate is issued for.static final intKey length in bits for a generated certificate key.private static StringPassword used for generated certificates, set once at startup.static final intLifetime in days of a generated certificate, ten years.static final StringFile name of the key store holding the I2PControl certificate.static final StringPassword protecting the I2PControl key store.Constructor Summary
ConstructorsConstructorDescriptionKeyStoreProvider(String pluginDir) Bind this provider to the plugin directory that holds the shared keystore, without reading or creating anything yet.Method Summary
Modifier and TypeMethodDescriptionstatic StringGet the dynamically generated certificate password.Load the keystore, creating it first if it does not exist yet.Resolve the absolute path of the keystore file this provider reads and writes, named after DEFAULT_KEYSTORE_NAME inside the plugin directory.voidCreate keystore if it does not existprivate static KeyStoreLoad the keystore file into the given empty keystore.static X509CertificateFetch the named certificate and verify it against its own public key, rejecting a certificate that does not check out.
Field Details
DEFAULT_CERTIFICATE_ALGORITHM_STRING
Key algorithm used for a generated I2PControl certificate.- See Also:
DEFAULT_CERTIFICATE_KEY_LENGTH
public static final int DEFAULT_CERTIFICATE_KEY_LENGTHKey length in bits for a generated certificate key.- See Also:
DEFAULT_CERTIFICATE_VALIDITY
public static final int DEFAULT_CERTIFICATE_VALIDITYLifetime in days of a generated certificate, ten years.- See Also:
DEFAULT_CERTIFICATE_DOMAIN
Subject domain a generated certificate is issued for.- See Also:
DEFAULT_CERTIFICATE_ALIAS
Alias the generated certificate is stored under in the key store.- See Also:
DEFAULT_KEYSTORE_NAME
File name of the key store holding the I2PControl certificate.- See Also:
DEFAULT_KEYSTORE_PASSWORD
Password protecting the I2PControl key store.- See Also:
_log
Logger for this class.DEFAULT_CERTIFICATE_PASSWORD
Password used for generated certificates, set once at startup._pluginDir
Directory plugins are installed in._keystore
The keystore, opened on first use.
Constructor Details
KeyStoreProvider
Bind this provider to the plugin directory that holds the shared keystore, without reading or creating anything yet.- Parameters:
pluginDir- path to the plugin directory for keystore storage
Method Details
getCertificatePassword
Get the dynamically generated certificate password.- Returns:
- the certificate password
initialize
public void initialize()Create keystore if it does not existreadCert
Fetch the named certificate and verify it against its own public key, rejecting a certificate that does not check out.- Parameters:
ks- the keystore to read the certificate fromcertAlias- the keystore alias naming the certificate to read- Returns:
- null on failure
getDefaultKeyStore
Load the keystore, creating it first if it does not exist yet. A keystore file that exists but cannot be read - wrong password, truncated or corrupt contents - is never replaced, since that would destroy any credentials it holds. That case, and any failure to create a missing file, is logged at WARN and reported as null. Nothing is cached in the failure case, so a later call retries the load.- Returns:
- the keystore, or null if it could not be read or created
load
private static KeyStore load(KeyStore ks, File keyStoreFile) throws IOException, GeneralSecurityException Load the keystore file into the given empty keystore.- Parameters:
ks- the empty keystore to load intokeyStoreFile- the file to read, which must exist- Returns:
- ks, loaded from keyStoreFile
- Throws:
IOException- if the file cannot be readGeneralSecurityException- if the file is not a valid keystore for the default type
getKeyStoreLocation
Resolve the absolute path of the keystore file this provider reads and writes, named after DEFAULT_KEYSTORE_NAME inside the plugin directory.- Returns:
- full path to the keystore file