1 /* client.c --- Sample client with authentication using Shishi.
2 * Copyright (C) 2003, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28 #define SERVICE "sample"
31 const char *program_name
= "client";
34 auth (Shishi
* h
, int verbose
, const char *cname
, const char *sname
)
38 Shishi_tkts_hint hint
;
41 printf ("Client: %s\n", cname
);
42 printf ("Server: %s\n", sname
);
44 /* Get a ticket for the server. */
46 memset (&hint
, 0, sizeof (hint
));
47 hint
.client
= (char *) cname
;
48 hint
.server
= (char *) sname
;
49 tkt
= shishi_tkts_get (shishi_tkts_default (h
), &hint
);
52 printf ("cannot find ticket for \"%s\"\n", sname
);
57 shishi_tkt_pretty_print (tkt
, stderr
);
59 /* Create Authentication context */
61 rc
= shishi_ap_tktoptions (h
, &ap
, tkt
, SHISHI_APOPTIONS_MUTUAL_REQUIRED
);
64 printf ("cannot create authentication context\n");
68 /* Build Authentication request */
70 rc
= shishi_ap_req_build (ap
);
73 printf ("cannot build authentication request: %s\n",
74 shishi_strerror (rc
));
79 shishi_authenticator_print (h
, stderr
, shishi_ap_authenticator (ap
));
81 /* Authentication ourself to server */
83 shishi_apreq_print (h
, stdout
, shishi_ap_req (ap
));
84 /* Note: to get the binary blob to send, use:
86 * char *out; int outlen;
88 * rc = shishi_ap_req_der (ap, &out, &outlen);
90 * write(fd, out, outlen);
93 /* For mutual authentication, wait for server reply. */
95 if (shishi_apreq_mutual_required_p (h
, shishi_ap_req (ap
)))
99 printf ("Cut'n'paste AP-REP from server...\n");
101 rc
= shishi_aprep_parse (h
, stdin
, &aprep
);
104 printf ("Cannot parse AP-REP from server: %s\n",
105 shishi_strerror (rc
));
109 rc
= shishi_ap_rep_verify_asn1 (ap
, aprep
);
111 printf ("AP-REP verification OK...\n");
114 if (rc
== SHISHI_APREP_VERIFY_FAILED
)
115 printf ("AP-REP verification failed...\n");
117 printf ("AP-REP verification error: %s\n", shishi_strerror (rc
));
121 /* The server is authenticated. */
122 printf ("Server authenticated.\n");
125 /* We are now authenticated. */
126 printf ("User authenticated.\n");
132 main (int argc
, char *argv
[])
139 printf ("sample-client (shishi " SHISHI_VERSION
")\n");
141 if (!shishi_check_version (SHISHI_VERSION
))
143 printf ("shishi_check_version() failed:\n"
144 "Header file incompatible with shared library.\n");
148 rc
= shishi_init (&h
);
151 printf ("error initializing shishi: %s\n", shishi_strerror (rc
));
158 sname
= shishi_server_for_local_service (h
, SERVICE
);
160 ap
= auth (h
, 1, shishi_principal_default (h
), sname
);
164 printf ("Authentication done...\n");