1 /* validate.c --- Validate consistency of DIGEST-MD5 tokens.
2 * Copyright (C) 2004, 2006 Simon Josefsson
4 * This file is part of GNU SASL Library.
6 * GNU SASL Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * GNU SASL Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with GNU SASL Library; if not, write to the Free
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
30 /* Get strcmp, strlen. */
34 digest_md5_validate_challenge (digest_md5_challenge
* c
)
36 /* This directive is required and MUST appear exactly once; if
37 not present, or if multiple instances are present, the
38 client should abort the authentication exchange. */
42 /* This directive must be present exactly once if "auth-conf" is
43 offered in the "qop-options" directive */
44 if (c
->ciphers
&& !(c
->qops
& DIGEST_MD5_QOP_AUTH_CONF
))
46 if (!c
->ciphers
&& (c
->qops
& DIGEST_MD5_QOP_AUTH_CONF
))
53 digest_md5_validate_response (digest_md5_response
* r
)
55 /* This directive is required and MUST be present exactly
56 once; otherwise, authentication fails. */
60 /* This directive is required and MUST be present exactly
61 once; otherwise, authentication fails. */
65 /* This directive is required and MUST be present exactly once;
66 otherwise, authentication fails. */
70 /* This directive is required and MUST be present exactly once;
71 otherwise, or if the value is 0, authentication fails. */
75 /* This directive is required and MUST be present exactly
76 once; if multiple instances are present, the client MUST
77 abort the authentication exchange. */
81 /* This directive is required and MUST be present exactly
82 once; otherwise, authentication fails. */
86 if (strlen (r
->response
) != DIGEST_MD5_RESPONSE_LENGTH
)
89 /* This directive MUST appear exactly once if "auth-conf" is
90 negotiated; if required and not present, authentication fails.
91 If the client recognizes no cipher and the server only advertised
92 "auth-conf" in the qop option, the client MUST abort the
93 authentication exchange. */
94 if (r
->qop
== DIGEST_MD5_QOP_AUTH_CONF
&& !r
->cipher
)
96 if (r
->qop
!= DIGEST_MD5_QOP_AUTH_CONF
&& r
->cipher
)
103 digest_md5_validate_finish (digest_md5_finish
* f
)
108 /* A string of 32 hex digits */
109 if (strlen (f
->rspauth
) != DIGEST_MD5_RESPONSE_LENGTH
)
116 digest_md5_validate (digest_md5_challenge
* c
, digest_md5_response
* r
)
118 if (!c
->nonce
|| !r
->nonce
)
121 if (strcmp (c
->nonce
, r
->nonce
) != 0)
127 if (c
->utf8
!= r
->utf8
)
130 if (!((c
->qops
? c
->qops
: DIGEST_MD5_QOP_AUTH
) &
131 (r
->qop
? r
->qop
: DIGEST_MD5_QOP_AUTH
)))
134 if ((r
->qop
& DIGEST_MD5_QOP_AUTH_CONF
) && !(c
->ciphers
& r
->cipher
))
137 /* FIXME: Check more? */