Package org.jivesoftware.openfire.net
Class SASLAuthentication
java.lang.Object
org.jivesoftware.openfire.net.SASLAuthentication
SASLAuthentication is responsible for returning the available SASL mechanisms to use and for
actually performing the SASL authentication.
The list of available SASL mechanisms is determined by:
- The type of
UserProviderbeing used since some SASL mechanisms require the server to be able to retrieve user passwords - Whether anonymous logins are enabled or not.
- Whether shared secret authentication is enabled or not.
- Whether the underlying connection has been secured or not.
- Author:
- Hao Chen, Gaston Dombiak
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SystemProperty<List<String>>static final StringSession Data property name used to store which channel bindings were advertised by the server to the peer as being available for the session that is performing SASL authentication.static final StringSession Data property name used to store which SASL mechanisms were advertised by the server to the peer as being available for the session that is performing SASL authentication.static final SystemProperty<Boolean>Enable (or disable) SASL2.static final SystemProperty<Boolean>Require the peer to provide an authorization identity through SASL (typically in the Initial Response) when authenticating an inbound S2S connection that uses the EXTERNAL SASL mechanism.static final SystemProperty<Boolean>Send an authorization identity in the Initial Response when attempting to authenticate using the SASL EXTERNAL mechanism with a remote XMPP domain.static final SystemProperty<Boolean>static final SystemProperty<String>static final Stringstatic final StringJava's SaslServer does not allow for null values.static final Stringstatic final Stringstatic final SystemProperty<Boolean>Require TLS for SASL2.static final SystemProperty<Boolean>Controls whether the SCRAM mechanisms that are advertised to a client are tailored to the user that is expected to authenticate.static final SystemProperty<Boolean>static final SystemProperty<Boolean>Controls if the SASL SCRAM Downgrade Protection feature, as specified in XEP-0474, is enabled. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddSupportedMechanism(String mechanismName) Adds a new SASL mechanism to the list of supported SASL mechanisms by the server.static voidappendSASLFeatures(LocalSession session, List<org.dom4j.Element> features) Adds the SASL-related stream features for the given session, and records what was advertised.static List<org.dom4j.Element>asSASLMechanisms(LocalSession session, Set<String> advertisableMechanismNames, Set<String> advertisableChannelBindingTypes) Returns a list of XML elements representing the SASL mechanism features that are applicable to the given session.Returns a Set of SASL mechanism names are applicable to advertise to the given session.Returns the set of channel binding types that has previously been advertised for/to the given session as being available for use for that session.getAdvertisedSASLMechanisms(LocalSession session) Returns the set of SASL mechanism names that has previously been advertised for/to the given session as being available for use for that session.Returns a collection of SASL mechanism names that forms the source pool from which the mechanisms that are eventually being offered to peers are obtained.Returns a collection of mechanism names for which the JVM has an implementation available.Returns the list of supported SASL mechanisms by the server.static SASLAuthentication.Statushandle(LocalSession session, org.dom4j.Element doc, boolean usingSASL2) Handles the SASL authentication packet.static voidremoveSupportedMechanism(String mechanismName) Removes a SASL mechanism from the list of supported SASL mechanisms by the server.static voidsetAdvertisedChannelBindingTypes(LocalSession session, Set<String> advertisedChannelBindingTypes) Records a set of channel binding types as having been advertised for/to the given session.static voidsetAdvertisedSASLMechanisms(LocalSession session, Set<String> advertisedMechanisms) Records a set of SASL mechanism names as having been advertised for/to the given session.static voidsetEnabledMechanisms(List<String> mechanisms) Sets the collection of mechanism names that the system administrator allows to be used.static booleanverifyCertificate(X509Certificate trustedCert, String hostname) Verifies that the given X.509 certificate is valid for the specified hostname.static booleanverifyCertificates(Certificate[] chain, String hostname, boolean isS2S) Verifies that the end-entity certificate in the given certificate chain is trusted and valid for the specified hostname.
-
Field Details
-
REALM
-
APPROVED_REALMS
-
PROXY_AUTH
-
SKIP_PEER_CERT_REVALIDATION_CLIENT
-
SSDP_ENABLED
Controls if the SASL SCRAM Downgrade Protection feature, as specified in XEP-0474, is enabled. When enabled, Openfire will add a hash value to the optionalhattribute ofserver-first-messagethat is sent to peers when they perform SCRAM-based authentication. This can help them prevent downgrade attacks. -
EXTERNAL_S2S_REQUIRE_AUTHZID
Require the peer to provide an authorization identity through SASL (typically in the Initial Response) when authenticating an inbound S2S connection that uses the EXTERNAL SASL mechanism. This is not required by the XMPP protocol specification, but it was required by Openfire versions prior to release 4.8.0. This configuration option is added to allow for backwards compatibility. -
EXTERNAL_S2S_SKIP_SENDING_AUTHZID
Send an authorization identity in the Initial Response when attempting to authenticate using the SASL EXTERNAL mechanism with a remote XMPP domain. Sending the authzid in this manner is not required by the XMPP protocol specification, but is recommended in XEP-0178 for compatibility with older server implementations. -
ENABLE_SASL2
Enable (or disable) SASL2. This is currently off by default, and means that SASL2 is not advertised in features, primarily.- See Also:
-
SASL2_REQUIRE_TLS
Require TLS for SASL2. This is currently on by default, and means that SASL2 is not advertised in features without TLS.- See Also:
-
SASL_NAMESPACE
- See Also:
-
SASL2_NAMESPACE
- See Also:
-
SASL_CHANNEL_BINDING_NAMESPACE
- See Also:
-
SASL_LAST_RESPONSE_WAS_PROVIDED_BUT_EMPTY
Java's SaslServer does not allow for null values. This makes it hard to distinguish between an empty (initial) responses (represented in XMPP as a single equals sign character '=', as per RFC-6120 section 6.4.2), and a missing/absent response. This can be problematic when a SASL mechanism implementation is to act differently on each scenario (like the EXTERNAL mechanism, that is to challenge for an authzid when no initial response is provided, but which is to use the stream's 'from' attribute value when the initial response is empty). To work around this shortcoming in Java's SASL implementation, this class will add a session attribute using a key that has the name of this constant's value when it detects a Sasl response that is present, but empty. -
AVAILABLE_MECHANISMS_FOR_SESSION
Session Data property name used to store which SASL mechanisms were advertised by the server to the peer as being available for the session that is performing SASL authentication. The value is expected to be a Set of Strings, if any mechanisms were advertised from Openfire to the peer. Instead of using this value directly, consider usinggetAdvertisableSASLMechanisms(LocalSession),setAdvertisedSASLMechanisms(LocalSession, Set), orgetAdvertisedSASLMechanisms(LocalSession)which encapsulate the business-logic related to this constant.- See Also:
-
AVAILABLE_CHANNEL_BINDING_TYPES_FOR_SESSION
Session Data property name used to store which channel bindings were advertised by the server to the peer as being available for the session that is performing SASL authentication. The value is expected to be a Set of Strings, if any bindings were advertised from Openfire to the peer. Instead of using this value directly, consider usinggetAdvertisedChannelBindingTypes(LocalSession)orsetAdvertisedChannelBindingTypes(LocalSession, Set)which encapsulate the business-logic related to this constant.- See Also:
-
SCRAM_MECHANISMS_PER_USER
Controls whether the SCRAM mechanisms that are advertised to a client are tailored to the user that is expected to authenticate. When enabled, the identity that a client claims in the 'from' attribute of its stream header is used to look up which SCRAM mechanisms that user has credentials for, so that no mechanism is offered that cannot succeed. When disabled, every session is offered the mechanisms that any user can be assumed to hold, and no per-user lookup is performed. This removes both the (small) signal that the tailored response gives an unauthenticated peer about which users exist, and the credential lookup that such a peer can otherwise trigger. The cost is that a user holding credentials for a stronger mechanism is not offered it unless every user holds it.
-
-
Constructor Details
-
SASLAuthentication
public SASLAuthentication()
-
-
Method Details
-
getAdvertisableSASLMechanisms
Returns a Set of SASL mechanism names are applicable to advertise to the given session. When the session is already authenticated, SASL mechanisms are no longer to be advertised. An empty collection is returned for these sessions.- Parameters:
session- the local session for which to determine applicable SASL mechanisms (cannot be null)- Returns:
- a set of SASL mechanism names; never null, possibly empty
-
setAdvertisedSASLMechanisms
public static void setAdvertisedSASLMechanisms(@Nonnull LocalSession session, Set<String> advertisedMechanisms) Records a set of SASL mechanism names as having been advertised for/to the given session. Some SASL mechanism implementations depend on this information. Notably, the SASL-SCRAM-SHA* mechanisms depend on it to detect channel binding downgrades. Implementations ofLocalSessionshould call this method when SASL mechanisms are advertised to a session.- Parameters:
session- the session for which to record advertised SASL mechanisms (cannot be null).advertisedMechanisms- the advertised SASL mechanism names
-
getAdvertisedSASLMechanisms
Returns the set of SASL mechanism names that has previously been advertised for/to the given session as being available for use for that session. When advertisement has not (yet) happened when this method is invoked, an empty Optional is returned.- Parameters:
session- the session for which to obtain SASL mechanism names (cannot be null).- Returns:
- a set of mechanism names that have been advertised for/to the session.
-
setAdvertisedChannelBindingTypes
public static void setAdvertisedChannelBindingTypes(@Nonnull LocalSession session, Set<String> advertisedChannelBindingTypes) Records a set of channel binding types as having been advertised for/to the given session. Some SASL mechanism implementations depend on this information. Notably, the SASL-SCRAM-SHA* mechanisms depend on it to detect channel binding downgrades. Implementations ofLocalSessionshould call this method when channel bindings are advertised to a session.- Parameters:
session- the session for which to record advertised channel bindings (cannot be null).advertisedChannelBindingTypes- the advertised channel binding types
-
getAdvertisedChannelBindingTypes
Returns the set of channel binding types that has previously been advertised for/to the given session as being available for use for that session. When advertisement has not (yet) happened when this method is invoked, an empty Optional is returned.- Parameters:
session- the session for which to obtain channel binding types (cannot be null).- Returns:
- a set of channel binding types that have been advertised for/to the session.
-
asSASLMechanisms
public static List<org.dom4j.Element> asSASLMechanisms(@Nonnull LocalSession session, @Nonnull Set<String> advertisableMechanismNames, @Nonnull Set<String> advertisableChannelBindingTypes) Returns a list of XML elements representing the SASL mechanism features that are applicable to the given session. The returned elements are suitable for inclusion in the stream features element sent to the peer. Both SASL (RFC 6120) and SASL2 (XEP-0388) feature elements may be included, depending on configuration. An empty list is returned if the session is already authenticated or if the session type is not recognized.- Parameters:
session- the local session for which to determine applicable SASL mechanism feature elements (cannot be null)advertisableMechanismNames- The set of SASL mechanism names that are to be advertised.advertisableChannelBindingTypes- The set of channel binding types that are to be advertised.- Returns:
- a list of XML elements representing SASL mechanism features; never null, possibly empty
-
handle
public static SASLAuthentication.Status handle(LocalSession session, org.dom4j.Element doc, boolean usingSASL2) Handles the SASL authentication packet. The entity may be sending an initial authentication request or a response to a challenge made by the server. The returned value indicates whether the authentication has finished either successfully or not or if the entity is expected to send a response to a challenge.- Parameters:
session- the session that is authenticating with the server.doc- the stanza sent by the authenticating entity.usingSASL2-trueif the authentication is being performed using SASL2 (XEP-0388);falseif using standard SASL (RFC 6120)- Returns:
- value that indicates whether the authentication has finished either successfully or not or if the entity is expected to send a response to a challenge.
-
verifyCertificate
Verifies that the given X.509 certificate is valid for the specified hostname. The certificate's server identities are checked against the hostname, with support for wildcard certificates. A wildcard identity (e.g.*.example.com) matches any direct subdomain of the base domain.- Parameters:
trustedCert- the X.509 certificate to verify (cannot be null)hostname- the hostname to verify the certificate against (cannot be null)- Returns:
trueif the certificate is valid for the given hostname;falseotherwise
-
verifyCertificates
Verifies that the end-entity certificate in the given certificate chain is trusted and valid for the specified hostname. The appropriate trust store is selected based on whether this is a server-to-server (S2S) or client-to-server (C2S) connection.- Parameters:
chain- the certificate chain to verify; the end-entity certificate will be extracted and checked against the trust store (may be null or empty, in which case verification will fail)hostname- the hostname that the certificate must be valid for (cannot be null)isS2S-trueif this is a server-to-server connection (uses the S2S trust store);falseif this is a client-to-server connection (uses the C2S trust store)- Returns:
trueif a trusted end-entity certificate is found in the chain and it is valid for the given hostname;falseotherwise
-
addSupportedMechanism
Adds a new SASL mechanism to the list of supported SASL mechanisms by the server. The new mechanism will be offered to clients and connection managers as stream features.Note: this method simply registers the SASL mechanism to be advertised as a supported mechanism by Openfire. Actual SASL handling is done by Java itself, so you must add the provider to Java.
- Parameters:
mechanismName- the name of the new SASL mechanism (cannot be null or an empty String).
-
removeSupportedMechanism
Removes a SASL mechanism from the list of supported SASL mechanisms by the server.- Parameters:
mechanismName- the name of the SASL mechanism to remove (cannot be null or empty, not case-sensitive).
-
getSupportedMechanisms
Returns the list of supported SASL mechanisms by the server. Note that Java may have support for more mechanisms but some of them may not be returned since a special setup is required that might be missing. UseaddSupportedMechanism(String)to add new SASL mechanisms.- Returns:
- the set of supported SASL mechanisms by the server.
-
getImplementedMechanisms
Returns a collection of mechanism names for which the JVM has an implementation available.Note that this need not (and likely will not) correspond with the list of mechanisms that is offered to XMPP peer entities, which is provided by #getSupportedMechanisms.
- Returns:
- a collection of SASL mechanism names (never null, possibly empty)
-
getEnabledMechanisms
Returns a collection of SASL mechanism names that forms the source pool from which the mechanisms that are eventually being offered to peers are obtained. When a mechanism is not returned by this method, it will never be offered, but when a mechanism is returned by this method, there is no guarantee that it will be offered. Apart from being returned in this method, an implementation must be available (seegetImplementedMechanisms()and configuration or other characteristics of this server must not prevent a particular mechanism from being used (see @{linkgetSupportedMechanisms()}.- Returns:
- A collection of mechanisms that are considered for use in this instance of Openfire.
-
setEnabledMechanisms
Sets the collection of mechanism names that the system administrator allows to be used.- Parameters:
mechanisms- A collection of mechanisms that are considered for use in this instance of Openfire. Null to reset the default setting.- See Also:
-
appendSASLFeatures
public static void appendSASLFeatures(@Nonnull LocalSession session, @Nonnull List<org.dom4j.Element> features) Adds the SASL-related stream features for the given session, and records what was advertised. This method is the single place where the SASL mechanisms and the XEP-0440 channel-binding types that a session is offered are determined. Both are recorded on the session as they are rendered, because SASL mechanism implementations need to know exactly what the peer was shown: the SCRAM implementations use the mechanism names to detect channel-binding downgrades, and use both sets to compute the XEP-0474 downgrade protection hash. A hash taken over anything other than what the peer actually received will not match the one the peer computes, and authentication will fail for every user.- Parameters:
session- the session for which to advertise SASL features (cannot be null).features- the collection of stream features to add to (cannot be null).
-