Class RefreshTokenCipher
java.lang.Object
com.kingsrook.qqq.backend.core.modules.authentication.implementations.RefreshTokenCipher
Authenticated encryption (AES-256-GCM) of OAuth2 refresh tokens at rest
(#1048), so a copy of the refresh-token table (a backup, a replica, an
over-broad DB role) does not hand out live credentials.
Stored values look like: v1::invalid input: '<'base64(nonce | ciphertext | tag)>
with a random 96-bit nonce per value. The associated data binds each value
to its session (uuid + userId), so a ciphertext copied to another row will
not decrypt. The keyId names the key that encrypted the value, so keys can
be rotated: values under a previous key still decrypt, and are re-encrypted
under the current key the next time they are written.
Keys come from configuration (OAuth2AuthenticationMetaData), never from the
database; they may be given as ${env.X} / ${prop.X} references. Messages
from this class never include key or token material.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildAssociatedData(String sessionUuid, String userId) Build the associated data that binds a stored value to its session.Decrypt a stored value.Encrypt a refresh token under the current key.static RefreshTokenCipherfromMetaData(OAuth2AuthenticationMetaData metaData) Build a cipher from the OAuth2 meta-data's key settings.Getter for currentKeyIdbooleanneedsReEncryption(String storedValue) Whether a stored value should be re-written under the current key (i.e., it was not encrypted with the current key id).
-
Field Details
-
VERSION
- See Also:
-
DEFAULT_KEY_ID
- See Also:
-
-
Method Details
-
fromMetaData
public static RefreshTokenCipher fromMetaData(OAuth2AuthenticationMetaData metaData) throws QException Build a cipher from the OAuth2 meta-data's key settings. Returns null if no current key is configured (refreshTokenEncryptionKey is unset). Throws if any configured key or key id is invalid (the message names the setting, never the key).- Throws:
QException
-
buildAssociatedData
-
encrypt
Encrypt a refresh token under the current key.- Throws:
QException
-
decrypt
Decrypt a stored value. Throws (with a short, token-free reason as the message) if the value is malformed, names an unknown key, or fails authentication (wrong key, tampered, or bound to a different session).- Throws:
QException
-
needsReEncryption
Whether a stored value should be re-written under the current key (i.e., it was not encrypted with the current key id). -
getCurrentKeyId
Getter for currentKeyId
-