Package org.jivesoftware.openfire.fast
Class FastTokenManager
java.lang.Object
org.jivesoftware.openfire.fast.FastTokenManager
Manages FAST (XEP-0484) authentication tokens.
Tokens are stored per user, client and mechanism in current/new slots. The recoverable token
string is required to verify the initiator HMAC and produce the responder HMAC.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classResult of a successful HT2 token validation, carrying both the rotated token and the responder HMAC that must be sent to the client for mutual authentication. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SystemProperty<Boolean>Enables FAST (XEP-0484), which lets clients re-authenticate with a long-lived token instead of their password.static final StringHT-SHA-256-ENDP: original HT draft, SHA-256, tls-server-end-point channel binding.static final StringHT-SHA-256-EXPR: original HT draft, SHA-256, tls-exporter channel binding.static final StringHT-SHA-256-NONE: original HT draft, SHA-256, no channel binding.static final StringHT-SHA-256-UNIQ: original HT draft, SHA-256, tls-unique channel binding.static final StringHT-SHA-512-ENDP: original HT draft, SHA-512, tls-server-end-point channel binding.static final StringHT-SHA-512-EXPR: original HT draft, SHA-512, tls-exporter channel binding.static final StringHT-SHA-512-NONE: original HT draft, SHA-512, no channel binding.static final StringHT-SHA-512-UNIQ: original HT draft, SHA-512, tls-unique channel binding.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringHT2-SHA-256-ENDP: HT2 draft, SHA-256, tls-server-end-point channel binding.static final StringHT2-SHA-256-EXPR: HT2 draft, SHA-256, tls-exporter channel binding.static final StringHT2-SHA-256-NONE: HT2 draft, SHA-256, no channel binding.static final StringHT2-SHA-256-UNIQ: HT2 draft, SHA-256, tls-unique channel binding.static final StringHT2-SHA-512-ENDP: HT2 draft, SHA-512, tls-server-end-point channel binding.static final StringHT2-SHA-512-EXPR: HT2 draft, SHA-512, tls-exporter channel binding.static final StringHT2-SHA-512-NONE: HT2 draft, SHA-512, no channel binding.static final StringHT2-SHA-512-UNIQ: HT2 draft, SHA-512, tls-unique channel binding.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringXEP-0484 namespacestatic final SystemProperty<Duration>How long an issued FAST token remains valid.static final SystemProperty<Duration>How close to expiry a token must be before a successful authentication issues a replacement. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.dom4j.ElementReturns an XML element advertising FAST as an inline feature for use in SASL2 (XEP-0388) inline feature advertisement.static org.dom4j.ElementfeatureElement(Collection<String> mechanisms) static StringhashAlgorithmForMechanism(String mechanism) Extracts the JCA hash algorithm name from a mechanism name of the formHT-SHA-256-NONE,HT2-SHA-512-UNIQ, etc.static StringhmacAlgorithmForMechanism(String mechanism) Returns the JCA HMAC algorithm name corresponding to the hash used by the given mechanism.static voidinvalidateToken(String username, String mechanism, String clientId) static voidinvalidateTokens(String username) Invalidates all FAST tokens for the given username.static booleanisMechanism(String mechanism) static FastTokenissueToken(String username, String clientId, String mechanism) Issues a new FAST token for the given username, client identifier and mechanism, storing it in the database.static voidPurges all expired FAST tokens from the database.validateTokenHt2(String username, String clientId, String mechanism, byte[] initiatorHashedToken, byte[] cbData, String extraInitiatorValues, String extraResponderValues) Validates an HT2 FAST token presented by a client using HMAC verification (draft-ietf-kitten-sasl-ht).validateTokenHt2(String username, String clientId, String mechanism, byte[] initiatorHashedToken, byte[] cbData, String extraInitiatorValues, String extraResponderValues, Long replayCount)
-
Field Details
-
NAMESPACE
XEP-0484 namespace- See Also:
-
HT_SHA_256_NONE
HT-SHA-256-NONE: original HT draft, SHA-256, no channel binding.- See Also:
-
HT_SHA_256_UNIQ
HT-SHA-256-UNIQ: original HT draft, SHA-256, tls-unique channel binding.- See Also:
-
HT_SHA_256_ENDP
HT-SHA-256-ENDP: original HT draft, SHA-256, tls-server-end-point channel binding.- See Also:
-
HT_SHA_256_EXPR
HT-SHA-256-EXPR: original HT draft, SHA-256, tls-exporter channel binding.- See Also:
-
HT_SHA_512_NONE
HT-SHA-512-NONE: original HT draft, SHA-512, no channel binding.- See Also:
-
HT_SHA_512_UNIQ
HT-SHA-512-UNIQ: original HT draft, SHA-512, tls-unique channel binding.- See Also:
-
HT_SHA_512_ENDP
HT-SHA-512-ENDP: original HT draft, SHA-512, tls-server-end-point channel binding.- See Also:
-
HT_SHA_512_EXPR
HT-SHA-512-EXPR: original HT draft, SHA-512, tls-exporter channel binding.- See Also:
-
HT_SHA3_512_NONE
- See Also:
-
HT_SHA3_512_UNIQ
- See Also:
-
HT_SHA3_512_ENDP
- See Also:
-
HT_SHA3_512_EXPR
- See Also:
-
HT2_SHA_256_NONE
HT2-SHA-256-NONE: HT2 draft, SHA-256, no channel binding.- See Also:
-
HT2_SHA_256_UNIQ
HT2-SHA-256-UNIQ: HT2 draft, SHA-256, tls-unique channel binding.- See Also:
-
HT2_SHA_256_ENDP
HT2-SHA-256-ENDP: HT2 draft, SHA-256, tls-server-end-point channel binding.- See Also:
-
HT2_SHA_256_EXPR
HT2-SHA-256-EXPR: HT2 draft, SHA-256, tls-exporter channel binding.- See Also:
-
HT2_SHA_512_NONE
HT2-SHA-512-NONE: HT2 draft, SHA-512, no channel binding.- See Also:
-
HT2_SHA_512_UNIQ
HT2-SHA-512-UNIQ: HT2 draft, SHA-512, tls-unique channel binding.- See Also:
-
HT2_SHA_512_ENDP
HT2-SHA-512-ENDP: HT2 draft, SHA-512, tls-server-end-point channel binding.- See Also:
-
HT2_SHA_512_EXPR
HT2-SHA-512-EXPR: HT2 draft, SHA-512, tls-exporter channel binding.- See Also:
-
HT2_SHA3_512_NONE
- See Also:
-
HT2_SHA3_512_UNIQ
- See Also:
-
HT2_SHA3_512_ENDP
- See Also:
-
HT2_SHA3_512_EXPR
- See Also:
-
ENABLE_FAST
Enables FAST (XEP-0484), which lets clients re-authenticate with a long-lived token instead of their password. -
TOKEN_EXPIRY
How long an issued FAST token remains valid. This is the window in which a leaked token, or a token belonging to a password changed outside Openfire (as with LDAP), can still be used to authenticate - lower values shorten that exposure at the cost of more frequent full re-authentication. -
TOKEN_ROTATION_THRESHOLD
How close to expiry a token must be before a successful authentication issues a replacement. It must be comfortably longer than the longest interval at which a client is expected to reconnect, or clients will find their token expired and have to re-authenticate with a password. -
MECHANISMS
-
-
Method Details
-
featureElement
public static org.dom4j.Element featureElement()Returns an XML element advertising FAST as an inline feature for use in SASL2 (XEP-0388) inline feature advertisement.- Returns:
- a
<fast/>element in theNAMESPACEnamespace
-
featureElement
-
isMechanism
-
hashAlgorithmForMechanism
Extracts the JCA hash algorithm name from a mechanism name of the formHT-SHA-256-NONE,HT2-SHA-512-UNIQ, etc.The second segment (between the first and second
-) is the hash family (e.g.SHA) and the third segment is the bit length (e.g.256), giving a JCA name ofSHA-256orSHA-512.- Parameters:
mechanism- the FAST SASL mechanism name (cannot be null)- Returns:
- the JCA algorithm name, e.g.
"SHA-256"or"SHA-512" - Throws:
IllegalArgumentException- if the mechanism name does not follow the expected pattern
-
hmacAlgorithmForMechanism
Returns the JCA HMAC algorithm name corresponding to the hash used by the given mechanism. For example,"SHA-256"maps to"HmacSHA256","SHA-512"to"HmacSHA512".- Parameters:
mechanism- the FAST SASL mechanism name (cannot be null)- Returns:
- the JCA HMAC algorithm name
-
issueToken
@Nonnull public static FastToken issueToken(@Nonnull String username, @Nonnull String clientId, @Nonnull String mechanism) Issues a new FAST token for the given username, client identifier and mechanism, storing it in the database. Any unacknowledged new token for the same user, mechanism and client is replaced. The current token remains valid until the client proves possession of this new token. The generated token is a Base64 Unicode string. Its UTF-8 representation is persisted so that both HT families can verify and produce their mutual-authentication HMACs.- Parameters:
username- the local username (cannot be null)clientId- the client identifier (cannot be null)mechanism- the FAST SASL mechanism name (cannot be null)- Returns:
- the newly issued
FastTokencontaining the UTF-8 token bytes and expiry
-
validateTokenHt2
public static FastTokenManager.Ht2ValidationResult validateTokenHt2(@Nonnull String username, @Nonnull String clientId, @Nonnull String mechanism, @Nonnull byte[] initiatorHashedToken, @Nonnull byte[] cbData, @Nonnull String extraInitiatorValues, @Nonnull String extraResponderValues) Validates an HT2 FAST token presented by a client using HMAC verification (draft-ietf-kitten-sasl-ht). The client sendsHMAC(token, "Initiator" || cbData || extraValues)as theinitiator-hashed-token. This method fetches the stored UTF-8 token bytes from the database and recomputes the expected HMAC for comparison. If the new token is valid, it is promoted to current. If a current token is nearing expiry, a replacement is issued into the new slot. The optional replacement is returned together with the responder HMAC. If validation fails,nullis returned.- Parameters:
username- the local username (cannot be null)mechanism- the FAST SASL mechanism name, must start with "HT2-" (cannot be null)initiatorHashedToken- the HMAC bytes presented by the client (cannot be null)cbData- the channel-binding data; empty byte array for NONE variant (cannot be null)extraInitiatorValues- the extra initiator key/value pairs string; empty string if none (cannot be null)extraResponderValues- the extra responder key/value pairs string; empty string if none (cannot be null)- Returns:
- a
FastTokenManager.Ht2ValidationResulton success, ornullon failure
-
validateTokenHt2
public static FastTokenManager.Ht2ValidationResult validateTokenHt2(@Nonnull String username, @Nonnull String clientId, @Nonnull String mechanism, @Nonnull byte[] initiatorHashedToken, @Nonnull byte[] cbData, @Nonnull String extraInitiatorValues, @Nonnull String extraResponderValues, Long replayCount) -
invalidateTokens
Invalidates all FAST tokens for the given username.- Parameters:
username- the local username (cannot be null)
-
invalidateToken
-
purgeExpiredTokens
public static void purgeExpiredTokens()Purges all expired FAST tokens from the database.
-