public abstract class AbstractKeyManager extends com.google.common.util.concurrent.AbstractIdleService implements KeyManager
KeyManager.DigestId| Modifier and Type | Field and Description |
|---|---|
protected KeyIdentifier |
currentKey |
protected String |
keyAlgo |
protected long |
keyExpirationPeriod
Time duration (in milliseconds) after which an active secret key should be retired.
|
protected KeyGenerator |
keyGenerator |
protected int |
keyLength |
protected ThreadLocal<Mac> |
threadLocalMac |
| Constructor and Description |
|---|
AbstractKeyManager(CConfiguration conf)
An AbstractKeyManager that has common functionality of all keymanagers.
|
AbstractKeyManager(String keyAlgo,
int keyLength) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
addKey(KeyIdentifier key)
Adds a given key instance.
|
protected abstract void |
doInit()
Extended classes must override this method to initialize/read the key(s) used for signing tokens.
|
protected KeyIdentifier |
generateKey()
Generates a new KeyIdentifier and sets that to be the current key being used.
|
KeyManager.DigestId |
generateMAC(byte[] message)
Computes a digest for the given input message, using the current secret key.
|
protected byte[] |
generateMAC(int keyId,
byte[] message)
Computes a digest for the given input message, using the key identified by the given ID.
|
protected byte[] |
generateMAC(SecretKey key,
byte[] message) |
protected abstract KeyIdentifier |
getKey(int id)
Returns the key instance matching a given unique ID.
|
protected abstract boolean |
hasKey(int id)
Returns whether or not a key exists for the given unique ID.
|
void |
startUp() |
<T> void |
validateMAC(Codec<T> codec,
Signed<T> signedMessage)
Recomputes the digest for the given message and verifies that it matches the provided value.
|
addListener, executor, isRunning, shutDown, start, startAndWait, state, stop, stopAndWait, toStringprotected ThreadLocal<Mac> threadLocalMac
protected KeyGenerator keyGenerator
protected volatile KeyIdentifier currentKey
protected final String keyAlgo
protected final int keyLength
protected long keyExpirationPeriod
public AbstractKeyManager(CConfiguration conf)
conf - public AbstractKeyManager(String keyAlgo, int keyLength)
public final void startUp()
throws NoSuchAlgorithmException,
IOException
startUp in class com.google.common.util.concurrent.AbstractIdleServiceNoSuchAlgorithmExceptionIOExceptionprotected abstract void doInit()
throws IOException
IOExceptionprotected abstract boolean hasKey(int id)
protected abstract KeyIdentifier getKey(int id)
protected abstract void addKey(KeyIdentifier key)
protected final KeyIdentifier generateKey()
public final <T> void validateMAC(Codec<T> codec, Signed<T> signedMessage) throws InvalidDigestException, InvalidKeyException
KeyManagervalidateMAC in interface KeyManagercodec - The serialization utility to use in serializing the message when recomputing the digestsignedMessage - The message and digest to validate.InvalidDigestExceptionInvalidKeyExceptionpublic final KeyManager.DigestId generateMAC(byte[] message) throws InvalidKeyException
KeyManagergenerateMAC in interface KeyManagermessage - The data over which we should generate a digest.InvalidKeyException - If the internal Mac implementation does not accept the given key.protected final byte[] generateMAC(int keyId,
byte[] message)
throws InvalidKeyException
keyId - Identifier of the secret key to use.message - The data over which we should generate a digest.InvalidKeyException - If the input keyId does not match a known key or the key is not accepted
by the internal Mac implementation.protected final byte[] generateMAC(SecretKey key, byte[] message) throws InvalidKeyException
InvalidKeyExceptionCopyright © 2016 Cask Data, Inc. Licensed under the Apache License, Version 2.0.