Interface KeyStoreService
-
@ProviderType public interface KeyStoreService
Provides secure access toKeyManagerinstances for accessing private keys and the system-wideTrustManagerfor validating signatures and certificates.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringNAMEName of the KeyStoreService service
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddKeyStoreKeyEntry(ResourceResolver resolver, java.lang.String userId, java.lang.String alias, java.security.Key key, java.security.cert.Certificate[] chain)Adds a private key entry with a certificate chain to the key store owned by the user with the user id equal touserId.voidaddKeyStoreKeyPair(ResourceResolver resolver, java.lang.String userId, java.security.KeyPair keyPair, java.lang.String alias)Saves aKeyPairin theKeyStoreowned by the user whose user id isuserId, under the specified alias.voidchangeKeyStorePassword(ResourceResolver resolver, java.lang.String userId, char[] currentPassword, char[] newPassword)Changes the password used to protect a user's key store.voidchangeTrustStorePassword(ResourceResolver resolver, char[] currentPassword, char[] newPassword)Changes the password used to protect the global trust store.java.security.KeyStorecreateKeyStore(ResourceResolver resolver, char[] password)Creates and returns a rawKeyStorefor the user identified by theresolver.java.security.KeyStorecreateKeyStore(ResourceResolver resolver, java.lang.String userId, char[] password)Creates and returns a rawKeyStorefor the user whose user id isuserId.java.security.KeyStorecreateTrustStore(ResourceResolver resolver, char[] password)Creates and returns the global trust store.javax.net.ssl.KeyManagergetKeyManager(ResourceResolver resolver)Returns the privateKeyManagerof the user identified by the givenResourceResolver.java.security.KeyStoregetKeyStore(ResourceResolver resolver)Returns the rawKeyStoreowned by the user identified by theResourceResolver.java.security.KeyStoregetKeyStore(ResourceResolver resolver, java.lang.String userId)Returns the rawKeyStoreowned by the user whose user id isuserId.java.security.KeyStore.EntrygetKeyStoreEntry(ResourceResolver resolver, java.lang.String userId, java.lang.String alias)Retrieves a protected entry from the key store owned by the user with the user id equal touserIdfor entries stored using the key store's password (seeaddKeyStoreKeyEntry(org.apache.sling.api.resource.ResourceResolver, String, String, java.security.Key, java.security.cert.Certificate[]).java.security.KeyPairgetKeyStoreKeyPair(ResourceResolver resolver, java.lang.String userId, java.lang.String alias)Retrieve aKeyPairfrom theKeyStoreowned by the user whose user id isuserId, stored under the specified alias.javax.net.ssl.TrustManagergetTrustManager(ResourceResolver resolver)Returns the system wideTrustManager.java.security.KeyStoregetTrustStore(ResourceResolver resolver)Returns the global trust store if it's accessible to the user identified by theResourceResolver.booleankeyStoreExists(ResourceResolver resolver, java.lang.String userId)Checks if a key store was created for the user whose user id isuserId.booleantrustStoreExists(ResourceResolver resolver)Checks if the global trust store was created.
-
-
-
Field Detail
-
NAME
static final java.lang.String NAME
Name of the KeyStoreService service- See Also:
- Constant Field Values
-
-
Method Detail
-
getKeyManager
javax.net.ssl.KeyManager getKeyManager(ResourceResolver resolver) throws SlingIOException, java.lang.SecurityException, java.lang.IllegalArgumentException, KeyStoreNotInitialisedException
Returns the privateKeyManagerof the user identified by the givenResourceResolver.- Parameters:
resolver- a resolver identifying the user whoseKeyStoreis used for building theKeyManager- Returns:
- the private key manager of the user identified by the given resolver; this method does not return
null - Throws:
SlingIOException- if an error occurs instantiating theKeyManagerwith data from persistencejava.lang.SecurityException- if the underlying key store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are nullKeyStoreNotInitialisedException- if the key store has not been created (seecreateKeyStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
getKeyStore
java.security.KeyStore getKeyStore(ResourceResolver resolver) throws SlingIOException, java.lang.SecurityException, java.lang.IllegalArgumentException, KeyStoreNotInitialisedException
Returns the raw
KeyStoreowned by the user identified by theResourceResolver. This key store allows managing the keys in the store.The
loadandstoremethods of the returnedKeyStoreinstance always throw aKeyStoreExceptionbecause the actual storage is managed by theKeyStoreServiceservice behind the scenes.The
ResourceResolverhas to be open as long as write operations are performed with theKeyStore.- Parameters:
resolver- a resolver identifying the user for which theKeyStorewill be obtained- Returns:
- the key store owned by the user identified by the given resolver; this method does not return
null - Throws:
SlingIOException- if an error occurs loading theKeyStoredata from persistencejava.lang.SecurityException- if the key store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are nullKeyStoreNotInitialisedException- if the key store has not been created (seecreateKeyStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
getKeyStore
java.security.KeyStore getKeyStore(ResourceResolver resolver, java.lang.String userId) throws SlingIOException, java.lang.SecurityException, java.lang.IllegalArgumentException, KeyStoreNotInitialisedException
Returns the raw
KeyStoreowned by the user whose user id isuserId. The given resource resolver must have the proper access rights in order to access the given user's key store. This key store allows managing the keys in the store.The
loadandstoremethods of the returnedKeyStoreinstance always throw aKeyStoreExceptionbecause the actual storage is managed by theKeyStoreServiceservice behind the scenes.The
ResourceResolverhas to be open as long as write operations are performed with theKeyStore.- Parameters:
resolver- the resource resolver to use for accessing the key store owned by the user given as parameteruserId- the ID of the user who owns the returned key store- Returns:
- the key store owned by the user identified by the given user ID.
nullis never returned. - Throws:
SlingIOException- if an error occurs loading theKeyStoredata from persistencejava.lang.SecurityException- if the key store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are nullKeyStoreNotInitialisedException- if the key store has not been created (seecreateKeyStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
getTrustManager
javax.net.ssl.TrustManager getTrustManager(ResourceResolver resolver) throws SlingIOException, java.lang.SecurityException, KeyStoreNotInitialisedException
Returns the system wideTrustManager.- Parameters:
resolver- a resolver identifying a user allowed to access theTrustManager- Returns:
- the global trust manager; this method does not return
null - Throws:
SlingIOException- if an error occurs instantiating theTrustManagerwith data from persistencejava.lang.SecurityException- if theResourceResolveris not allowed to access the global trust storejava.lang.IllegalArgumentException- if theresolverisnullKeyStoreNotInitialisedException- if the trust store has not been created (seecreateTrustStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
getTrustStore
java.security.KeyStore getTrustStore(ResourceResolver resolver) throws SlingIOException, java.lang.SecurityException, java.lang.IllegalArgumentException, KeyStoreNotInitialisedException
Returns the global trust store if it's accessible to the user identified by the
ResourceResolver. This key store allows managing the keys in the store.The
loadandstoremethods of the returnedKeyStoreinstance always throw aKeyStoreExceptionbecause the actual storage is managed by theKeyStoreServiceservice behind the scenes.The
ResourceResolverhas to be open as long as write operations are performed with theKeyStore.- Parameters:
resolver- a resolver identifying a user allowed to access the global trust store- Throws:
SlingIOException- if an error occurs loading theKeyStoredata from persistencejava.lang.SecurityException- if theResourceResolveris not allowed access to the global trust store or if the store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are nullKeyStoreNotInitialisedException- if the trust store has not been created (seecreateTrustStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
changeKeyStorePassword
void changeKeyStorePassword(ResourceResolver resolver, java.lang.String userId, char[] currentPassword, char[] newPassword) throws SlingIOException, java.lang.SecurityException, KeyStoreNotInitialisedException
Changes the password used to protect a user's key store. For security reasons the password char arrays parameters should be cleaned after successfully calling this method (seeArrays.fill(char[], char)).- Parameters:
resolver- a resource resolver to use for accessing the key store owned by the user given as parameteruserId- the ID of the user who owns the key storecurrentPassword- the key store's current password; please make sure to clean this array after calling this method for security purposesnewPassword- the key store's new password; please make sure to clean this array after calling this method for security purposes- Throws:
SlingIOException- if an error occurs loading theKeyStoredata from persistencejava.lang.SecurityException- if thecurrentPassworddoesn't match the key store's password or if the key store cannot be instantiated due to security errorsKeyStoreNotInitialisedException- if the key store has not been created (seecreateKeyStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
changeTrustStorePassword
void changeTrustStorePassword(ResourceResolver resolver, char[] currentPassword, char[] newPassword) throws SlingIOException, java.lang.SecurityException, KeyStoreNotInitialisedException
Changes the password used to protect the global trust store. For security reasons the password char arrays parameters should be cleaned after successfully calling this method (seeArrays.fill(char[], char)).- Parameters:
resolver- a resource resolver with write access to the trust storecurrentPassword- the trust store's current password; please make sure to clean this array after calling this method for security purposesnewPassword- the trust store's new password; please make sure to clean this array after calling this method for security purposes- Throws:
SlingIOException- if an error occurs loading the trust store data from persistencejava.lang.SecurityException- if thecurrentPassworddoesn't match the key store's password or if the passed resolver doesn't have enough rights to modify the trust storeKeyStoreNotInitialisedException- if the trust store has not been created (seecreateTrustStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
addKeyStoreKeyPair
void addKeyStoreKeyPair(ResourceResolver resolver, java.lang.String userId, java.security.KeyPair keyPair, java.lang.String alias) throws SlingIOException, java.lang.SecurityException, KeyStoreNotInitialisedException
Saves aKeyPairin theKeyStoreowned by the user whose user id isuserId, under the specified alias. The given resource resolver must have the proper access rights in order to access the given user's key store. If an entry already exists for the specified alias, it is overridden.- Parameters:
resolver- the resource resolver to use for accessing the key store owned by the user given as parameteruserId- the id of the user who owns the key storekeyPair- theKeyPairto savealias- save theKeyPairunder this alias- Throws:
SlingIOException- if an error occurs loading theKeyStoredata from persistencejava.lang.SecurityException- if the key store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are nullKeyStoreNotInitialisedException- if the key store has not been created (seecreateKeyStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
getKeyStoreKeyPair
java.security.KeyPair getKeyStoreKeyPair(ResourceResolver resolver, java.lang.String userId, java.lang.String alias) throws SlingIOException, java.lang.SecurityException, KeyStoreNotInitialisedException
Retrieve aKeyPairfrom theKeyStoreowned by the user whose user id isuserId, stored under the specified alias. The given resource resolver must have the proper access rights in order to access the given user's key store.- Parameters:
resolver- the resource resolver to use for accessing the key store owned by the user given as parameteruserId- the id of the user who owns the key storealias- retrieve theKeyPairstored under this alias- Returns:
- the
KeyPairornullif noKeyPairwas stored with the given alias. - Throws:
SlingIOException- if an error occurs loading theKeyStoredata from persistencejava.lang.SecurityException- if the key store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are nullKeyStoreNotInitialisedException- if the key store has not been created (seecreateKeyStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
createKeyStore
java.security.KeyStore createKeyStore(ResourceResolver resolver, java.lang.String userId, char[] password) throws SlingIOException, java.lang.SecurityException, java.lang.IllegalArgumentException
Creates and returns a raw
KeyStorefor the user whose user id isuserId. For security reasons the password char array parameter should be cleaned after successfully calling this method (seeArrays.fill(char[], char)).The
loadandstoremethods of the returnedKeyStoreinstance always throw aKeyStoreExceptionbecause the actual storage is managed by theKeyStoreServiceservice behind the scenes.The
Calling this method several times with the same parameters has no effect on an already created key store. However, calling this method with a different password will throw aResourceResolverhas to be open as long as write operations are performed with theKeyStore. Also, it must have the proper access rights in order to create the given user's key store.SlingIOException.- Parameters:
resolver- a resolver that will be used to create theKeyStoreuserId- the user for which theKeyStorewill be createdpassword- the password used for protecting the returnedKeyStore; please make sure to clean this array after calling this method for security purposes- Returns:
- the key store owned by the user whose user id is
userId; this method does not returnnull - Throws:
SlingIOException- if an error occurs storing theKeyStoredata to the persistence layerjava.lang.SecurityException- if the key store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are null
-
createKeyStore
java.security.KeyStore createKeyStore(ResourceResolver resolver, char[] password) throws SlingIOException, java.lang.SecurityException, java.lang.IllegalArgumentException
Creates and returns a raw
KeyStorefor the user identified by theresolver. For security reasons the password char array parameter should be cleaned after successfully calling this method (seeArrays.fill(char[], char)).The
loadandstoremethods of the returnedKeyStoreinstance always throw aKeyStoreExceptionbecause the actual storage is managed by theKeyStoreServiceservice behind the scenes.The
ResourceResolverhas to be open as long as write operations are performed with theKeyStore.Calling this method several times with the same parameters has no effect on an already created key store. However, calling this method with a different password will throw a
SlingIOException.- Parameters:
resolver- a resolver identifying the user for which theKeyStorewill be createdpassword- the password used for protecting the returnedKeyStore; please make sure to clean this array after calling this method for security purposes- Returns:
- key store owned by the user identified by the given resolver; this method does not return
null - Throws:
SlingIOException- if an error occurs storing theKeyStoredata to the persistence layerjava.lang.SecurityException- if the key store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are null
-
createTrustStore
java.security.KeyStore createTrustStore(ResourceResolver resolver, char[] password) throws SlingIOException, java.lang.SecurityException, java.lang.IllegalArgumentException
Creates and returns the global trust store. The
resolverprovided should have enough access rights in order to successfully create the trust store. For security reasons the password char array parameter should be cleaned after successfully calling this method (seeArrays.fill(char[], char)).The
loadandstoremethods of the returnedKeyStoreinstance always throw aKeyStoreExceptionbecause the actual storage is managed by theKeyStoreServiceservice behind the scenes.The
ResourceResolverhas to be open as long as write operations are performed with theKeyStore.Calling this method several times with the same parameters has no effect on an already created trust store. However, calling this method with a different password will throw a
SlingIOException.- Parameters:
resolver- a resolver identifying a user allowed to create the global trust storepassword- the password used for protecting the returnedKeyStore; please make sure to clean this array after calling this method for security purposes- Returns:
- the global trust store; this method does not return
null - Throws:
SlingIOException- if an error occurs storing theKeyStoredata to the persistence layerjava.lang.SecurityException- if theResourceResolveris not allowed access to the global trust store location or if the store cannot be instantiated due to security errorsjava.lang.IllegalArgumentException- if any of the parameters are null
-
keyStoreExists
boolean keyStoreExists(ResourceResolver resolver, java.lang.String userId)
Checks if a key store was created for the user whose user id isuserId. The given resource resolver must have the proper access rights in order to check the existence of the given user's key store.- Parameters:
resolver- the resource resolver to use for checking the existence of a key store for the user whose user id isuserIduserId- the id of the user who owns the checked key store- Returns:
trueif the key store exists,falseotherwise
-
trustStoreExists
boolean trustStoreExists(ResourceResolver resolver)
Checks if the global trust store was created.- Parameters:
resolver- the resolver used for checking the trust store's existence- Returns:
trueif the trust store exists,falseotherwise
-
addKeyStoreKeyEntry
void addKeyStoreKeyEntry(ResourceResolver resolver, java.lang.String userId, java.lang.String alias, java.security.Key key, java.security.cert.Certificate[] chain) throws java.lang.SecurityException, KeyStoreNotInitialisedException
Adds a private key entry with a certificate chain to the key store owned by the user with the user id equal touserId. This method makes sure the entries are protected with the store's password for ease of use instead of requiring a password for each key.- Parameters:
resolver- a resource resolver to use for accessing the key store owned by the user given as parameteruserId- the id of the user who owns the key storealias- the alias under which the key entry will be saved in the key storekey- the private key that will be added to the key storechain- the private key's certificate chain- Throws:
java.lang.SecurityException- if the underlying key store cannot be instantiated due to security errorsKeyStoreNotInitialisedException- if the key store has not been created (seecreateKeyStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
getKeyStoreEntry
java.security.KeyStore.Entry getKeyStoreEntry(ResourceResolver resolver, java.lang.String userId, java.lang.String alias) throws java.lang.SecurityException, KeyStoreNotInitialisedException
Retrieves a protected entry from the key store owned by the user with the user id equal touserIdfor entries stored using the key store's password (seeaddKeyStoreKeyEntry(org.apache.sling.api.resource.ResourceResolver, String, String, java.security.Key, java.security.cert.Certificate[]).- Parameters:
resolver- a resource resolver to use for accessing the key store owned by the user given as parameteruserId- the id of the user who owns the key storealias- the alias under which the key entry will be saved in the key store- Returns:
- the entry stored in the key store under
alias - Throws:
java.lang.SecurityException- if the underlying key store cannot be instantiated due to security errorsKeyStoreNotInitialisedException- if the key store has not been created (seecreateKeyStore(org.apache.sling.api.resource.ResourceResolver, char[]))
-
-