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
25 client (Shishi
* handle
, struct arguments arg
)
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
)
42 asprintf (&p
, "host/www");
44 if (arg
.sname
== NULL
)
45 error (1, 0, "Could not allocate server name.");
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
);
58 printf ("Cannot get ticket for server `%s'.\n", arg
.sname
);
62 key
= shishi_tkt_key (tkt
);
65 printf ("Cannot get key for ticket for server `%s'.\n", arg
.sname
);
69 res
= shishi_ap_tktoptions (handle
, &ap
, tkt
, arg
.apoptions
);
72 printf ("Could not create AP: %s\n", shishi_strerror (res
));
76 res
= shishi_ap_req_build (ap
);
79 printf ("Could not build AP-REQ: %s\n", shishi_strerror (res
));
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
)))
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");
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
));
112 res
= shishi_safe_set_user_data (handle
, shishi_safe_safe (safe
),
114 if (res
!= SHISHI_OK
)
116 printf ("Could not set application data in SAFE: %s\n",
117 shishi_strerror (res
));
121 res
= shishi_safe_build (safe
, key
);
122 if (res
!= SHISHI_OK
)
124 printf ("Could not build SAFE: %s\n", shishi_strerror (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
));