Branch data Line data Source code
1 : : /* nonce.c --- Shishi nonce handling regression self tests.
2 : : * Copyright (C) 2006, 2007 Simon Josefsson
3 : : *
4 : : * This file is part of Shishi.
5 : : *
6 : : * Shishi is free software; you can redistribute it and/or modify
7 : : * it under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation; either version 3 of the License, or
9 : : * (at your option) any later version.
10 : : *
11 : : * Shishi 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
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 : : * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 : : * Floor, Boston, MA 02110-1301, USA
20 : : *
21 : : */
22 : :
23 : : const char *asreq =
24 : : "aoGQMIGNoQMCAQWiAwIBCqSBgDB+oAcDBQAAAAAAoRAwDqADAgEAoQcwBRsDamFzog8bDUpPU0VGU1NPTi5PUkejIjAgoAMCAQGhGTAXGwZrcmJ0Z3QbDUpPU0VGU1NPTi5PUkelERgPMjAwNjExMDEyMDMwMDVapwYCBAlXUoOoETAPAgESAgEQAgEDAgECAgEB";
25 : : const char *asreppart =
26 : : "eYGYMIGVoCMwIaADAgEQoRoEGPSJH0z06kWoouBUejc+L566tgEBAQEZDqECMACiBgIEf////6QHAwUAAEAAAKURGA8yMDA2MTEwMTEyMDkyNVqnERgPMjAwNjExMDEyMDA5MjVaqQ8bDUpPU0VGU1NPTi5PUkeqIjAgoAMCAQGhGTAXGwZrcmJ0Z3QbDUpPU0VGU1NPTi5PUkc=";
27 : :
28 : : #include "utils.c"
29 : :
30 : : #include <base64.h>
31 : :
32 : : void
33 : 1 : test (Shishi * handle)
34 : : {
35 : : Shishi_asn1 req, rep;
36 : : char *reqder, *repder;
37 : : size_t reqderlen, repderlen;
38 : : int rc;
39 : : uint32_t nonce;
40 : :
41 [ - + ]: 1 : if (!base64_decode_alloc (asreq, strlen (asreq), &reqder, &reqderlen))
42 : 0 : fail ("base64 req\n");
43 : :
44 [ - + ]: 1 : if (!base64_decode_alloc
45 : : (asreppart, strlen (asreppart), &repder, &repderlen))
46 : 0 : fail ("base64 rep\n");
47 : :
48 : 1 : req = shishi_der2asn1_asreq (handle, reqder, reqderlen);
49 [ - + ]: 1 : if (!req)
50 : 0 : fail ("der2asn1 req\n");
51 : :
52 : 1 : rep = shishi_der2asn1_encasreppart (handle, repder, repderlen);
53 [ - + ]: 1 : if (!rep)
54 : 0 : fail ("der2asn1 rep\n");
55 : :
56 [ - + ]: 1 : if (debug)
57 : : {
58 : 0 : shishi_kdcreq_print (handle, stdout, req);
59 : 0 : shishi_enckdcreppart_print (handle, stdout, rep);
60 : : }
61 : :
62 : : /* Read and check req */
63 : :
64 : 1 : rc = shishi_asn1_read_uint32 (handle, req, "req-body.nonce", &nonce);
65 [ - + ]: 1 : if (rc)
66 : 0 : fail ("shishi_asn1_read_uint32\n");
67 : :
68 : 1 : printf ("req nonce: %x\n", nonce);
69 : :
70 [ - + ]: 1 : if (nonce != 0x09575283)
71 : 0 : fail ("nonce mismatch low\n");
72 : :
73 : 1 : rc = shishi_kdcreq_nonce (handle, req, &nonce);
74 [ - + ]: 1 : if (rc)
75 : 0 : fail ("shishi_kdcreq_nonce\n");
76 : :
77 : 1 : printf ("req nonce: %x\n", nonce);
78 : :
79 [ - + ]: 1 : if (nonce != 0x09575283)
80 : 0 : fail ("nonce mismatch high");
81 : :
82 : : /* Read and check rep */
83 : :
84 : 1 : rc = shishi_asn1_read_uint32 (handle, rep, "nonce", &nonce);
85 [ - + ]: 1 : if (rc)
86 : 0 : fail ("read rep uint32");
87 : :
88 : 1 : printf ("old rep nonce: %x\n", nonce);
89 : :
90 [ - + ]: 1 : if (nonce != 0x7fffffff)
91 : 0 : fail ("nonce mismatch high");
92 : :
93 : : /* Copy nonce. */
94 : :
95 : 1 : rc = shishi_kdc_copy_nonce (handle, req, rep);
96 [ - + ]: 1 : if (rc)
97 : 0 : fail ("shishi_kdc_copy_nonce\n");
98 : :
99 : : /* Read and check rep */
100 : :
101 : 1 : rc = shishi_asn1_read_uint32 (handle, rep, "nonce", &nonce);
102 [ - + ]: 1 : if (rc)
103 : 0 : fail ("read rep uint32");
104 : :
105 : 1 : printf ("new rep nonce: %x\n", nonce);
106 : :
107 [ - + ]: 1 : if (nonce != 0x09575283)
108 : 0 : fail ("nonce mismatch high");
109 : :
110 : 1 : free (reqder);
111 : 1 : free (repder);
112 : :
113 : 1 : shishi_asn1_done (handle, req);
114 : 1 : shishi_asn1_done (handle, rep);
115 : 1 : }
|