pub struct LongTermCredentials { /* private fields */ }Expand description
A client’s long-term credentials for one server, and what the server’s challenges added to them. See the module documentation.
Implementations§
Source§impl LongTermCredentials
impl LongTermCredentials
Sourcepub fn new(username: &str, password: &str) -> Result<Self>
pub fn new(username: &str, password: &str) -> Result<Self>
Credentials that support the SHA-256 and MD5 password algorithms.
§Errors
RFC 8489 section 14.3: the user name is OpaqueString-processed; one the profile does not allow is refused, as is such a password (section 9.2.2).
Sourcepub fn with_username_anonymity_required(self, required: bool) -> Self
pub fn with_username_anonymity_required(self, required: bool) -> Self
With required, the user name never goes in a USERNAME attribute: a challenge whose
nonce cookie does not offer username anonymity (RFC 8489 section 9.2.5, USERHASH) is
refused as ChallengeError::Unusable, and nothing with the credential is sent. For a
user name that reveals the user, over a transport that is not (D)TLS: RFC 8656 section
21.1.6, “If the username reveals the identity of the user, the client MUST use the
USERHASH attribute … or use (D)TLS”.
Sourcepub fn with_password_algorithms(self, supported: &[u16]) -> Self
pub fn with_password_algorithms(self, supported: &[u16]) -> Self
Restricts the password algorithms this client accepts from a server’s
PASSWORD-ALGORITHMS, for instance to SHA-256 alone (RFC 8489 section 18.5.1.1 keeps
MD5 for legacy systems). Numbers other than
PASSWORD_ALGORITHM_SHA256 and PASSWORD_ALGORITHM_MD5 are dropped: there is no
key derivation for them.
A server that sends no PASSWORD-ALGORITHMS is an RFC 5389 server, which has MD5 only;
a client that left MD5 out refuses its challenge
(ChallengeError::NoSupportedAlgorithm).
Sourcepub fn password_algorithm(&self) -> Option<&PasswordAlgorithm>
pub fn password_algorithm(&self) -> Option<&PasswordAlgorithm>
The password algorithm sent in PASSWORD-ALGORITHM, when the server offered a list.
Sourcepub fn uses_userhash(&self) -> bool
pub fn uses_userhash(&self) -> bool
Whether requests carry USERHASH in place of USERNAME.
Sourcepub fn integrity(&self) -> Option<IntegrityAlgorithm>
pub fn integrity(&self) -> Option<IntegrityAlgorithm>
The integrity attribute requests carry and responses must carry, once challenged: MESSAGE-INTEGRITY-SHA256 alone after a challenge with PASSWORD-ALGORITHMS (RFC 8489 section 9.2.5), MESSAGE-INTEGRITY otherwise.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Forgets the server’s challenge: the next request is a first request again.
Sourcepub fn challenge(
&mut self,
request: &Message,
response: &Message,
crypto: &dyn RTCCrypto,
) -> Result<(), ChallengeError>
pub fn challenge( &mut self, request: &Message, response: &Message, crypto: &dyn RTCCrypto, ) -> Result<(), ChallengeError>
Takes the 401 (Unauthenticated) or 438 (Stale Nonce) error response to request and
prepares the retry (RFC 8489 section 9.2.5).
On Ok, the realm, nonce, algorithm and key are replaced by the response’s, and the
request is to be sent again in a new transaction with setter.
§Errors
The ChallengeError that says why there is no retry. The state is unchanged then.
Sourcepub fn setter<'a>(
&'a self,
crypto: &'a dyn RTCCrypto,
) -> LongTermAuthentication<'a>
pub fn setter<'a>( &'a self, crypto: &'a dyn RTCCrypto, ) -> LongTermAuthentication<'a>
A Setter that adds the authentication attributes to a request. It goes after the
request’s own attributes and ahead of FINGERPRINT.
Before the first challenge it adds nothing: the first request carries no USERNAME, USERHASH, REALM, NONCE, PASSWORD-ALGORITHMS, PASSWORD-ALGORITHM or integrity attribute (RFC 8489 section 9.2.3.1).
Sourcepub fn check_response(
&self,
response: &Message,
validator: &Validator<'_>,
crypto: &dyn RTCCrypto,
) -> Result<LongTermResponse, Rejection>
pub fn check_response( &self, response: &Message, validator: &Validator<'_>, crypto: &dyn RTCCrypto, ) -> Result<LongTermResponse, Rejection>
Checks a response to a request that was sent with setter after a
challenge, by the rules of RFC 8489 section 9.2.5. validator carries the usage’s own
checks (FINGERPRINT, known attributes).
- A 401 or 438 error response is a
LongTermResponse::Challenge: such a response need not be signed. - Any other response must carry the integrity attribute the request carried, valid
under the client’s key; then it is
LongTermResponse::Authenticated.
§Errors
The response is to be discarded as if it had never been received, so that the
request’s retransmissions continue: Rejection::IntegrityMissing (which is what a
400 without integrity attribute gets) or Rejection::IntegrityMismatch, and, for a
response whose NONCE has a cookie with the “Password algorithms” bit but which has no
PASSWORD-ALGORITHMS, Rejection::IntegrityMissing as well: it is to be ignored.
When every response to a request was discarded this way, the transaction’s failure is
an integrity violation, not a timeout; over a reliable transport it fails at once.