io.undertow.security.api.NonceManager implementation to provide reasonable single host management of nonces.
This io.undertow.security.api.NonceManager manages nonces in two groups, the first is the group that are allocated to new requests, this group
is a problem as we want to be able to limit how many we distribute so we don't have a DOS storing too many but we also don't
a high number of requests to to push the other valid nonces out faster than they can be used.
The second group is the set of nonces actively in use - these should be maintained as we can also maintain the nonce count
and even track the next nonce once invalid.
Maybe group one should be a timestamp and private key hashed together, if used with a nonce count they move to be tracked to
ensure the same count is not used again - if successfully used without a nonce count add to a blacklist until expiration? A
nonce used without a nonce count will essentially be single use with each request getting a new nonce.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class | |
| private static class | SimpleNonceManager.
The state associated with a nonce. |
| private static class | SimpleNonceManager.
A simple wrapper around a nonce to allow it to be used as a key in a weak map. |
| Modifier and Type | Field and Description |
|---|---|
| private static final long | cacheTimePostExpiry
A previously used nonce will be allowed to remain in the knownNonces list for up to 5 minutes. |
| private static final String | |
| private static final long | firstUseTimeOut
After a nonce is issued the first authentication response MUST be received within 5 minutes. |
| private final Map | forwardMapping
A WeakHashMap to map expired nonces to their replacement nonce. |
| private final String | |
| private final int | |
| private final Set | invalidNonces
List of invalid nonces, this list contains the nonces that have been used without a nonce count. |
| private final Map | knownNonces
Map of known currently valid nonces, a SortedMap is used to order the nonces by their creation time stamp allowing a simple iteration over the keys to identify expired nonces. |
| private static final long | overallTimeOut
Overall a nonce is valid from 15 minutes from first being issued, if used after this then a new nonce will be issued. |
| private static final Random | rand
Create a static instance of SecureRandom, so it can be actually reused by all instances of this class. |
| private final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| public void | associateHash(String
- The nonce the hash is to be associated with. nonce, byte[] - The hash to associate. hash)Implements io. Associate the supplied hash with the nonce specified. |
| private SimpleNonceManager. | |
| private String | |
| private String | |
| private byte[] | |
| private MessageDigest | |
| public byte[] | lookupHash(String
- The nonce the hash is required for. nonce)Implements io. Retrieve the existing hash associated with the nonce specified. |
| public String | nextNonce(String
- The last valid nonce received from the client or null if we don't already have a nonce. lastNonce, HttpServerExchange exchange)Implements io. Select the next nonce to be sent from the server taking into account the last valid nonce. |
| public boolean | validateNonce(String
- The nonce received from the client. nonce, int - The nonce count from the client or -1 of none specified. nonceCount, HttpServerExchange exchange)Implements io. Validate that a nonce can be used. |
| private boolean | |
| private SimpleNonceManager. | verifyUnknownNonce(final String
- nonce, final int nonceCount)Verify a previously unknown nonce and return the |
| cacheTimePostExpiry | back to summary |
|---|---|
| private static final long cacheTimePostExpiry A previously used nonce will be allowed to remain in the knownNonces list for up to 5 minutes. The nonce will be accepted during this 5 minute window but will immediately be replaced causing any additional requests to be forced to use the new nonce. This is primarily for session based digests where loosing the cached session key would be bad. | |
| DEFAULT_HASH_ALG | back to summary |
|---|---|
| private static final String DEFAULT_HASH_ALG | |
| firstUseTimeOut | back to summary |
|---|---|
| private static final long firstUseTimeOut After a nonce is issued the first authentication response MUST be received within 5 minutes. | |
| forwardMapping | back to summary |
|---|---|
| private final Map<SimpleNonceManager. A WeakHashMap to map expired nonces to their replacement nonce. For an item to be added to this Collection the value will have been removed from the knownNonces map. A replacement nonce will have been added to knownNonces that references the key used here - once the replacement nonce is removed from knownNonces then the key will be eligible for garbage collection allowing it to be removed from this map as well. The value in this Map is a plain String, this is to avoid inadvertently creating a long term reference to the key we expect to be garbage collected at some point in the future. | |
| hashAlg | back to summary |
|---|---|
| private final String hashAlg | |
| hashLength | back to summary |
|---|---|
| private final int hashLength | |
| invalidNonces | back to summary |
|---|---|
| private final Set<String> invalidNonces List of invalid nonces, this list contains the nonces that have been used without a nonce count. In that situation they are considered single use and must not be used again. | |
| knownNonces | back to summary |
|---|---|
| private final Map<String, SimpleNonceManager. Map of known currently valid nonces, a SortedMap is used to order the nonces by their creation time stamp allowing a simple iteration over the keys to identify expired nonces. | |
| overallTimeOut | back to summary |
|---|---|
| private static final long overallTimeOut Overall a nonce is valid from 15 minutes from first being issued, if used after this then a new nonce will be issued. | |
| rand | back to summary |
|---|---|
| private static final Random rand Create a static instance of SecureRandom, so it can be actually reused by all instances of this class. This should also increase the randomness of generated numbers. | |
| secret | back to summary |
|---|---|
| private final String secret | |
| SimpleNonceManager | back to summary |
|---|---|
| public SimpleNonceManager() | |
| SimpleNonceManager | back to summary |
|---|---|
| public SimpleNonceManager(final String hashAlg) | |
| addInvalidNonce | back to summary |
|---|---|
| private boolean addInvalidNonce(final SimpleNonceManager. | |
| associateHash | back to summary |
|---|---|
| public void associateHash(String nonce, byte[] hash) Implements io. Doc from io. Associate the supplied hash with the nonce specified.
| |
| createNewNonce | back to summary |
|---|---|
| private SimpleNonceManager. | |
| createNewNonceString | back to summary |
|---|---|
| private String createNewNonceString() | |
| createNonce | back to summary |
|---|---|
| private String createNonce(final byte[] prefix, final byte[] timeStamp) | |
| generateHash | back to summary |
|---|---|
| private byte[] generateHash(final byte[] prefix, final byte[] timeStamp) | |
| getDigest | back to summary |
|---|---|
| private MessageDigest getDigest(final String hashAlg) | |
| lookupHash | back to summary |
|---|---|
| public byte[] lookupHash(String nonce) Implements io. Doc from io. Retrieve the existing hash associated with the nonce specified. If there is no association then null should be returned.
| |
| nextNonce | back to summary |
|---|---|
| public String nextNonce(String lastNonce, HttpServerExchange exchange) Implements io. Doc from io. Select the next nonce to be sent from the server taking into account the last valid nonce. It is both possible and likely that the nonce last used by the client will still be valid, in that case the same nonce will be returned.
| |
| validateNonce | back to summary |
|---|---|
| public boolean validateNonce(String nonce, int nonceCount, HttpServerExchange exchange) Implements io. Doc from io. Validate that a nonce can be used. If the nonce can not be used but the related digest was correct then a new nonce should be returned to the client indicating that the nonce was stale. For implementations of this interface this method is not expected by be idempotent, i.e. once a nonce is validated with a specific nonceCount it is not expected that this method will return true again if the same combination is presented. This method is expected to ONLY be called if the users credentials are valid as a storage overhead could be incurred this overhead must not be accessible to unauthenticated clients.
| |
| validateNonceWithCount | back to summary |
|---|---|
| private boolean validateNonceWithCount(SimpleNonceManager. | |
| verifyUnknownNonce | back to summary |
|---|---|
| private SimpleNonceManager. Verify a previously unknown nonce and return the
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| nonce | back to summary |
|---|---|
| private final String nonce | |
| InvalidNonceCleaner | back to summary |
|---|---|
| private InvalidNonceCleaner(final String nonce) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| nonce | back to summary |
|---|---|
| private final String nonce | |
| KnownNonceCleaner | back to summary |
|---|---|
| private KnownNonceCleaner(final String nonce) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation. | |
| Modifier and Type | Field and Description |
|---|---|
| private XnioExecutor. | |
| private int | |
| private final String | |
| private final SimpleNonceManager. | |
| private byte[] | |
| private final long |
| Access | Constructor and Description |
|---|---|
| private | |
| private | |
| private | |
| private | Nonce(final String nonce, final long timeStamp, final int initialNC, final SimpleNonceManager.
|
| Modifier and Type | Method and Description |
|---|---|
| pack-priv int | |
| pack-priv byte[] | |
| pack-priv void | |
| pack-priv void |
| executorKey | back to summary |
|---|---|
| private XnioExecutor. | |
| maxNonceCount | back to summary |
|---|---|
| private int maxNonceCount | |
| nonce | back to summary |
|---|---|
| private final String nonce | |
| previousNonce | back to summary |
|---|---|
private final SimpleNonceManager.
| |
| sessionKey | back to summary |
|---|---|
| private byte[] sessionKey | |
| timeStamp | back to summary |
|---|---|
| private final long timeStamp | |
| Nonce | back to summary |
|---|---|
| private Nonce(final String nonce) | |
| Nonce | back to summary |
|---|---|
| private Nonce(final String nonce, final long timeStamp, final int initialNC) | |
| Nonce | back to summary |
|---|---|
| private Nonce(final String nonce, final long timeStamp, final SimpleNonceManager. | |
| Nonce | back to summary |
|---|---|
| private Nonce(final String nonce, final long timeStamp, final int initialNC, final SimpleNonceManager. | |
| getMaxNonceCount | back to summary |
|---|---|
| pack-priv int getMaxNonceCount() | |
| getSessionKey | back to summary |
|---|---|
| pack-priv byte[] getSessionKey() | |
| setMaxNonceCount | back to summary |
|---|---|
| pack-priv void setMaxNonceCount(int maxNonceCount) | |
| setSessionKey | back to summary |
|---|---|
| pack-priv void setSessionKey(final byte[] sessionKey) | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. Indicates whether some other object is "equal to" this one. |
| public int |
| nonce | back to summary |
|---|---|
| private final String nonce | |
| NonceHolder | back to summary |
|---|---|
| private NonceHolder(final String nonce) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |