1 /* client.c --- Sample client with authentication using Shishi.
2 * Copyright (C) 2003, 2004, 2007 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify it
7 * 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.
11 * Shishi is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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, 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
29 #define SERVICE "sample"
32 const char *program_name
= "client";
35 auth (Shishi
* h
, int verbose
, const char *cname
, const char *sname
)
39 Shishi_tkts_hint hint
;
42 printf ("Client: %s\n", cname
);
43 printf ("Server: %s\n", sname
);
45 /* Get a ticket for the server. */
47 memset (&hint
, 0, sizeof (hint
));
48 hint
.client
= (char *) cname
;
49 hint
.server
= (char *) sname
;
50 tkt
= shishi_tkts_get (shishi_tkts_default (h
), &hint
);
53 printf ("cannot find ticket for \"%s\"\n", sname
);
58 shishi_tkt_pretty_print (tkt
, stderr
);
60 /* Create Authentication context */
62 rc
= shishi_ap_tktoptions (h
, &ap
, tkt
, SHISHI_APOPTIONS_MUTUAL_REQUIRED
);
65 printf ("cannot create authentication context\n");
69 /* Build Authentication request */
71 rc
= shishi_ap_req_build (ap
);
74 printf ("cannot build authentication request: %s\n",
75 shishi_strerror (rc
));
80 shishi_authenticator_print (h
, stderr
, shishi_ap_authenticator (ap
));
82 /* Authentication ourself to server */
84 shishi_apreq_print (h
, stdout
, shishi_ap_req (ap
));
85 /* Note: to get the binary blob to send, use:
87 * char *out; int outlen;
89 * rc = shishi_ap_req_der (ap, &out, &outlen);
91 * write(fd, out, outlen);
94 /* For mutual authentication, wait for server reply. */
96 if (shishi_apreq_mutual_required_p (h
, shishi_ap_req (ap
)))
100 printf ("Cut'n'paste AP-REP from server...\n");
102 rc
= shishi_aprep_parse (h
, stdin
, &aprep
);
105 printf ("Cannot parse AP-REP from server: %s\n",
106 shishi_strerror (rc
));
110 rc
= shishi_ap_rep_verify_asn1 (ap
, aprep
);
112 printf ("AP-REP verification OK...\n");
115 if (rc
== SHISHI_APREP_VERIFY_FAILED
)
116 printf ("AP-REP verification failed...\n");
118 printf ("AP-REP verification error: %s\n", shishi_strerror (rc
));
122 /* The server is authenticated. */
123 printf ("Server authenticated.\n");
126 /* We are now authenticated. */
127 printf ("User authenticated.\n");
133 main (int argc
, char *argv
[])
140 printf ("sample-client (shishi " SHISHI_VERSION
")\n");
142 if (!shishi_check_version (SHISHI_VERSION
))
144 printf ("shishi_check_version() failed:\n"
145 "Header file incompatible with shared library.\n");
149 rc
= shishi_init (&h
);
152 printf ("error initializing shishi: %s\n", shishi_strerror (rc
));
159 sname
= shishi_server_for_local_service (h
, SERVICE
);
161 ap
= auth (h
, 1, shishi_principal_default (h
), sname
);
165 printf ("Authentication done...\n");