|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface KeyProvider
A general purpose interface used by client applications to retrieve a
key which is required to create or open a protected resource.
Both the key and the protected resources may be virtually anything:
The minimum requirement for a key is just that it's an Object
.
Protected resources are not even explicitly modelled in this interface.
So in order to use it, an instance must be associated with a protected
resource by a third party - this is the job of the KeyManager
class.
Because the protected resource is not modelled within this interface,
it is at the discretion of the provider implementation whether its
instances may or may not be shared among protected resources.
If they do, then all associated protected resources share the same key.
For the following examples, it helps if you think of the protected resource being an encrypted file and the key being a password. Of course, this interface also works with certificate based encryption.
Once an instance has been associated to a protected resource, the client application is assumed to use the key for two basic operations:
getCreateKey()
.
getOpenKey()
,
followed by a call to invalidOpenKey()
if the authentication of
the returned key failed for some reason.
equal
,
but is not necessarily the same.
In fact, the standard implementations in this package try to return a
clone of the key wherever possible for maximum security.
Failing that, the same key is returned.
From a client application's perspective, the two basic operations may be executed in no particular order. Following are some typical use cases:
getCreateKey()
returns a key which compares
equal to the key returned by getOpenKey()
or returns a completely
different (new) key.
Ideally, a brave provider implementation would allow the user to control this.
In fact, this is the behaviour of the PromptingKeyProvider
in
this package and its user interface class(es).
Note that provider implementations must be thread safe. This allows clients to use the same provider by multiple threads concurrently.
KeyManager
Field Summary | |
---|---|
static int |
MIN_KEY_RETRY_DELAY
The minimum delay between subsequent attempts to authenticate a key in milliseconds. |
Method Summary | |
---|---|
Object |
getCreateKey()
Returns the key which may be used to create a new protected resource or entirely replace the contents of an already existing protected resource. |
Object |
getOpenKey()
Returns the key which may be used to open an existing protected resource in order to access its contents. |
void |
invalidOpenKey()
Called to indicate that authentication of the key returned by getOpenKey() has failed and to request an entirely different
key. |
Field Detail |
---|
static final int MIN_KEY_RETRY_DELAY
invalidOpenKey()
and a subsequent getOpenKey()
by the
same thread.
Method Detail |
---|
Object getCreateKey() throws UnknownKeyException
For each call to this method an object is returned which compares
equal
to the previously returned object, but is
not necessarily the same.
null
is never returned.
UnknownKeyException
- If the required key is unknown.
At the provider implementation's discretion, this may mean that
prompting for the key has been disabled or cancelled by the user.Object getOpenKey() throws UnknownKeyException
invalidOpenKey()
must be called
immediately to indicate this situation.
Unless invalidOpenKey()
is called, on each call to this method
an object is returned which compares equal
to
the previously returned object, but is not necessarily the same.
Important: From a client application's perspective, a
KeyProvider
is not trustworthy!
Hence, the key returned by this method must not only get authenticated,
but the client 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 the
immediate call to invalidOpenKey()
and the return from the
subsequent call to this method.
"Friendly" implementations of this interface should duplicate this
behaviour in order to protect client applications which do not obeye
these considerations against abuses of the key provider implementation.
Note that invalidOpenKey()
must still be called
immediately by the client application, so that other threads are not
negatively affected by the suspension penalty.
For the same reason, "friendly" implementations should enforce the
suspension penalty for the local thread only.
null
is never returned.
UnknownKeyException
- If the required key is unknown.
At the provider implementation's discretion, this may mean that
prompting for the key has been disabled or cancelled by the user.MIN_KEY_RETRY_DELAY
void invalidOpenKey()
getOpenKey()
has failed and to request an entirely different
key.
Whether or not an entirely different key is provided on the next call
to getOpenKey()
is at the discretion of the provider's
implementation and its instance's state.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |