Remove asn1 junk.
[shishi.git] / src / client.c
blob9d20eacadfe6c2e83796360f04ebe398329f72d0
1 /* client.c sample network client using shishi
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
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 2 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "data.h"
24 int
25 client (Shishi * handle, struct arguments arg)
27 Shishi_tkt *tkt;
28 Shishi_key *key;
29 Shishi_ap *ap;
30 Shishi_safe *safe;
31 int res;
33 if (arg.cname == NULL)
34 arg.cname = shishi_principal_default (handle);
36 if (arg.realm == NULL)
37 arg.realm = shishi_realm_default (handle);
39 if (arg.sname == NULL)
41 char *p;
42 asprintf (&p, "host/www");
43 arg.sname = p;
44 if (arg.sname == NULL)
45 error (1, 0, "Could not allocate server name.");
48 if (arg.verbose)
50 printf ("Client name: `%s'\n", arg.cname);
51 printf ("Realm: `%s'\n", arg.realm);
52 printf ("Service name: `%s'\n", arg.sname);
55 tkt = shishi_tkts_get_for_server (shishi_tkts_default (handle), arg.sname);
56 if (tkt == NULL)
58 printf ("Cannot get ticket for server `%s'.\n", arg.sname);
59 return !SHISHI_OK;
62 key = shishi_tkt_key (tkt);
63 if (key == NULL)
65 printf ("Cannot get key for ticket for server `%s'.\n", arg.sname);
66 return !SHISHI_OK;
69 res = shishi_ap_tktoptions (handle, &ap, tkt, arg.apoptions);
70 if (res != SHISHI_OK)
72 printf ("Could not create AP: %s\n", shishi_strerror (res));
73 return res;
76 res = shishi_ap_req_build (ap);
77 if (res != SHISHI_OK)
79 printf ("Could not build AP-REQ: %s\n", shishi_strerror (res));
80 return res;
83 if (arg.verbose)
84 shishi_authenticator_print (handle, stdout, shishi_ap_authenticator (ap));
86 shishi_apreq_print (handle, stdout, shishi_ap_req (ap));
88 if (shishi_apreq_mutual_required_p (handle, shishi_ap_req (ap)))
90 ASN1_TYPE aprep;
92 printf ("Waiting for AP-REP from server...\n");
94 res = shishi_aprep_parse (handle, stdin, &aprep);
96 res = shishi_ap_rep_verify_asn1 (ap, aprep);
97 if (res == SHISHI_APREP_VERIFY_FAILED)
98 printf ("AP-REP verification failed...\n");
99 else if (res == SHISHI_OK)
100 printf ("AP-REP verification OK...\n");
101 else
102 printf ("AP-REP verification error: %s\n", shishi_strerror (res));
105 res = shishi_safe (handle, &safe);
106 if (res != SHISHI_OK)
108 printf ("Could not build SAFE: %s\n", shishi_strerror (res));
109 return res;
112 res = shishi_safe_set_user_data (handle, shishi_safe_safe (safe),
113 "foo", 0);
114 if (res != SHISHI_OK)
116 printf ("Could not set application data in SAFE: %s\n",
117 shishi_strerror (res));
118 return res;
121 res = shishi_safe_build (safe, key);
122 if (res != SHISHI_OK)
124 printf ("Could not build SAFE: %s\n", shishi_strerror (res));
125 return res;
128 res = shishi_safe_print (handle, stdout, shishi_safe_safe(safe));
129 if (res != SHISHI_OK)
131 printf ("Could not print SAFE: %s\n", shishi_strerror (res));
132 return res;
135 return SHISHI_OK;