1 /* test-parser.c --- Self tests of DIGEST-MD5 parser & printer.
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.
29 #include "digesthmac.h"
32 main (int argc
, char *argv
[])
34 digest_md5_challenge c
;
35 digest_md5_response r
;
43 char *token
= "nonce=4711, foo=bar, algorithm=md5-sess";
45 printf ("challenge `%s': ", token
);
46 rc
= digest_md5_parse_challenge (token
, 0, &c
);
49 printf ("nonce `%s': %s", c
.nonce
,
50 strcmp ("4711", c
.nonce
) == 0 ? "PASS" : "FAILURE");
52 tmp
= digest_md5_print_challenge (&c
);
55 printf ("printed `%s' PASS\n", tmp
);
60 char *token
= "qop=\"auth, auth-conf\", nonce=42, algorithm=md5-sess";
62 printf ("challenge `%s': ", token
);
63 rc
= digest_md5_parse_challenge (token
, 0, &c
);
70 char *token
= "cipher=\"des\", nonce=42, algorithm=md5-sess";
72 printf ("challenge `%s': ", token
);
73 rc
= digest_md5_parse_challenge (token
, 0, &c
);
80 char *token
= "qop=\"auth, auth-conf\", nonce=42, algorithm=md5-sess, "
83 printf ("challenge `%s': ", token
);
84 rc
= digest_md5_parse_challenge (token
, 0, &c
);
87 printf ("qop %02x ciphers %02x: %s\n", c
.qops
, c
.ciphers
,
88 (c
.qops
== 5 && c
.ciphers
== 1) ? "PASS" : "FAILURE");
89 tmp
= digest_md5_print_challenge (&c
);
92 printf ("printed `%s' PASS\n", tmp
);
97 char *token
= "bar=foo, foo=bar";
99 printf ("challenge `%s': ", token
);
100 rc
= digest_md5_parse_challenge (token
, 0, &c
);
107 char *token
= "realm=foo, realm=bar, nonce=42, algorithm=md5-sess";
109 printf ("challenge `%s': ", token
);
110 rc
= digest_md5_parse_challenge (token
, 0, &c
);
115 printf ("realms `%s', `%s': PASS\n", c
.realms
[0], c
.realms
[1]);
116 tmp
= digest_md5_print_challenge (&c
);
119 printf ("printed `%s' PASS\n", tmp
);
126 char *token
= "bar=foo, foo=bar";
128 printf ("response `%s': ", token
);
129 rc
= digest_md5_parse_response (token
, 0, &r
);
136 char *token
= "username=jas, nonce=42, cnonce=4711, nc=00000001, "
137 "digest-uri=foo, response=01234567890123456789012345678901";
139 printf ("response `%s': ", token
);
140 rc
= digest_md5_parse_response (token
, 0, &r
);
143 printf ("username `%s', nonce `%s', cnonce `%s',"
144 " nc %08lx, digest-uri `%s', response `%s': PASS\n",
145 r
.username
, r
.nonce
, r
.cnonce
, r
.nc
, r
.digesturi
, r
.response
);
146 tmp
= digest_md5_print_response (&r
);
149 printf ("printed `%s' PASS\n", tmp
);
153 /* Auth-response, finish. */
156 char *token
= "rspauth=\"6a204da26b9888ee40bb3052ff056a67\"";
158 printf ("finish `%s': ", token
);
159 rc
= digest_md5_parse_finish (token
, 0, &f
);
162 printf ("`%s'? %s\n", f
.rspauth
,
163 strcmp ("6a204da26b9888ee40bb3052ff056a67", f
.rspauth
) == 0
168 char *token
= "bar=foo, foo=bar";
170 printf ("finish `%s': ", token
);
171 rc
= digest_md5_parse_finish (token
, 0, &f
);
174 printf ("invalid? PASS\n", token
);
177 memset (buf16
, 'Q', 16);
179 rc
= digest_md5_hmac (buf32
, buf16
, "nonce", 1, "cnonce",
180 DIGEST_MD5_QOP_AUTH
, "authzid", "digesturi",
181 1, 0, NULL
, NULL
, NULL
, NULL
);
185 if (strcmp (buf32
, "6a204da26b9888ee40bb3052ff056a67") != 0)
187 printf ("digest: `%s': PASS\n", buf32
);
189 rc
= digest_md5_hmac (buf32
, buf16
, "nonce", 1, "cnonce",
190 DIGEST_MD5_QOP_AUTH
, "authzid", "digesturi", 0, 0,
191 NULL
, NULL
, NULL
, NULL
);
195 if (strcmp (buf32
, "6c1f58bfa46e9c225b93745c84204efd") != 0)
197 printf ("digest: `%s': PASS\n", buf32
);