K - The type of the secret keys.@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public interface KeyProvider<K>
KeyManager.
Note that neither the protected resources nor their encryption/decryption
operations are modelled by this interface.
Clients are assumed to use this interface for the following purposes:
getWriteKey() retrieves the secret key for encrypting
a protected resource.
This implies that the secret key does not need to get authenticated.
getReadKey(boolean) retrieves the secret key for decrypting
a protected resource.
This implies that the secret key needs to get authenticated by the
component which actually performs the decryption.
setKey(K) sets the secret key.
This can be used after a call to getReadKey(boolean) in order to update
some properties of the secret key after it has been authenticated by
the component which actually performs the decryption.
equal, but is not necessarily the same.
Following are some typical use cases:
getWriteKey() needs to get called.
getWriteKey() needs to get called.
getReadKey(boolean) needs to get called.
getReadKey(boolean) needs to get called.
getReadKey(boolean) and then getWriteKey()
need to get called.
getWriteKey() returns a secret
key which compares equal to the secret key returned by
getReadKey(boolean) or returns a completely different secret key.
Ideally, a brave provider implementation would allow the user to control
this.
Implementations must be safe for multi-threading.
KeyManager| Modifier and Type | Method and Description |
|---|---|
K |
getReadKey(boolean invalid)
Retrieves the secret key for the decryption of a protected resource.
|
K |
getWriteKey()
Retrieves the secret key for the encryption of a protected resource.
|
void |
setKey(K key)
Sets the secret key programmatically.
|
K getWriteKey() throws UnknownKeyException
Subsequent calls to this method return an object which at least compares
equal to any previously returned object, but is
not necessarily the same.
UnknownKeyException - if the secret key is unknown for some
reason, e.g. if prompting for the secret key has been disabled
or cancelled by the user.K getReadKey(boolean invalid) throws UnknownKeyException
Unless invalid is true, subsequent calls to this method
return an object which at least compares equal to
any previously returned object, but is not necessarily the same.
Important: From an application's perspective, a
KeyProvider is not trustworthy!
Hence, the key returned by this method must not only get authenticated,
but the application should also throttle the pace for the return from a
subsequent call to this method if the key is invalid in order to protect
the client application from an exhaustive search for the correct key.
As a rule of thumb, at least three seconds should pass between two
consecutive calls to this method by the same thread.
"Safe" implementations of this interface should enforce this
behaviour in order to protect client applications which do not obey
these considerations against abuses of the key provider implementation.
invalid - true iff a previous call to this method resulted
in an invalid key.UnknownKeyException - if the secret key is unknown for some
reason, e.g. if prompting for the secret key has been disabled
or cancelled by the user.void setKey(@CheckForNull
K key)
key - the secret key.
If this is null, this key provider is set to a state
as if prompting for the secret key had been cancelled.Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.