Class CustomLoadingKeyManager
- java.lang.Object
-
- javax.net.ssl.X509ExtendedKeyManager
-
- de.xima.fc.certificate.provider.internal.CustomLoadingKeyManager
-
- All Implemented Interfaces:
KeyManager,X509KeyManager
public class CustomLoadingKeyManager extends X509ExtendedKeyManager
A custom implementation of X509ExtendedKeyManager that loads and manages X.509 certificates and their corresponding private keys from a KeyStore.This implementation provides: - Dynamic certificate loading from KeyStore - Caching of server aliases for improved performance - Support for X.509 certificate chains - Thread-safe operations
-
-
Constructor Summary
Constructors Constructor Description CustomLoadingKeyManager(de.xima.fc.certificate.provider.internal.KeyStoreAccess keyStoreAccess, KeyStore ks)Constructs a new CustomLoadingKeyManager and loads certificates from the provided KeyStore backed by fc-certificate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringchooseClientAlias(String[] keyTypes, Principal[] issuers, Socket socket)Chooses a client alias based on the given parameters.StringchooseEngineClientAlias(String[] keyType, Principal[] issuers, SSLEngine engine)As this implementation does not use the SSLEngine parameter, it simply callschooseClientAlias(String[], Principal[], Socket)with a null socket.StringchooseEngineServerAlias(String keyType, Principal[] issuers, SSLEngine engine)Chooses a server alias based on the given parameters.StringchooseServerAlias(String keyType, Principal[] issuers, Socket socket)Chooses a server alias based on the given parameters.X509Certificate[]getCertificateChain(String alias)Returns the certificate chain for the specified alias.String[]getClientAliases(String keyType, Principal[] issuers)Returns the client aliases for a specific key type and set of issuers.PrivateKeygetPrivateKey(String alias)Returns the private key for the specified alias.String[]getServerAliases(String keyType, Principal[] issuers)Returns the server aliases for a specific key type and set of issuers.
-
-
-
Constructor Detail
-
CustomLoadingKeyManager
public CustomLoadingKeyManager(de.xima.fc.certificate.provider.internal.KeyStoreAccess keyStoreAccess, KeyStore ks) throws KeyStoreExceptionConstructs a new CustomLoadingKeyManager and loads certificates from the provided KeyStore backed by fc-certificate.- Parameters:
keyStoreAccess- interface for accessing private keys from the fc-certificate backed KeyStoreks- the KeyStore containing the certificates and private keys- Throws:
KeyStoreException- if there's an error accessing the KeyStore
-
-
Method Detail
-
getClientAliases
public String[] getClientAliases(String keyType, Principal[] issuers)
Returns the client aliases for a specific key type and set of issuers.- Parameters:
keyType- the type of key (e.g., "RSA", "DSA")issuers- the acceptable certificate issuers, or null if any issuer is allowed- Returns:
- an array of matching alias names, or null if none match
-
chooseClientAlias
public String chooseClientAlias(String[] keyTypes, Principal[] issuers, Socket socket)
Chooses a client alias based on the given parameters. Returns the FIRST(!) matching alias for the specified key types and issuers.- Parameters:
keyTypes- array of key types to choose fromissuers- acceptable certificate issuers, or null if any issuer is allowedsocket- this implementation ignores the socket parameter as it does not affect alias selection- Returns:
- the chosen alias, or null if no matching alias exists
-
chooseEngineClientAlias
public String chooseEngineClientAlias(String[] keyType, Principal[] issuers, SSLEngine engine)
As this implementation does not use the SSLEngine parameter, it simply callschooseClientAlias(String[], Principal[], Socket)with a null socket. This allows the implementation to select an alias applicable to any engine.- Overrides:
chooseEngineClientAliasin classX509ExtendedKeyManager- Parameters:
keyType- the key algorithm type name(s), ordered with the most-preferred key type first.issuers- the list of acceptable CA issuer subject names or null if it does not matter which issuers are used.engine- This implementation does not use it for alias selection.- Returns:
- the chosen alias, or null if no matching alias exists
-
getServerAliases
public String[] getServerAliases(String keyType, Principal[] issuers)
Returns the server aliases for a specific key type and set of issuers.- Parameters:
keyType- the key algorithm type nameissuers- the list of acceptable CA issuer subject names or null if it does not matter which issuers are used.- Returns:
- an array of matching alias names, or null if none match
-
chooseServerAlias
public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket)
Chooses a server alias based on the given parameters.- Parameters:
keyType- the key algorithm type name.issuers- the list of acceptable CA issuer subject names or null if it does not matter which issuers are used.socket- this implementation does not use the socket parameter as it does not affect alias selection.- Returns:
- the chosen alias, or null if no matching alias exists
-
chooseEngineServerAlias
public String chooseEngineServerAlias(String keyType, Principal[] issuers, SSLEngine engine)
Chooses a server alias based on the given parameters. This implementation does not use the SSLEngine parameter, so it simply callschooseServerAlias(String, Principal[], Socket)with a null socket.- Overrides:
chooseEngineServerAliasin classX509ExtendedKeyManager- Parameters:
keyType- the key algorithm type name.issuers- the list of acceptable CA issuer subject names or null if it does not matter which issuers are used.engine- This implementation does not use it for alias selection.- Returns:
- the chosen alias, or null if no matching alias exists
-
getCertificateChain
public X509Certificate[] getCertificateChain(String alias)
Returns the certificate chain for the specified alias.- Parameters:
alias- the alias of the certificate- Returns:
- an array of X509Certificates representing the certificate chain, or null if the alias is null or does not exist
-
getPrivateKey
public PrivateKey getPrivateKey(String alias)
Returns the private key for the specified alias.- Parameters:
alias- the alias of the private key- Returns:
- the PrivateKey associated with the alias, or null if the alias is null or does not exist
-
-