2 * Copyright (c) 2012, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
45 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
46 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
47 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
48 0x19, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
53 TIDC_INSTANCE *tidc_create ()
55 TIDC_INSTANCE *tidc = NULL;
57 if (tidc = malloc(sizeof(TIDC_INSTANCE)))
58 memset(tidc, 0, sizeof(TIDC_INSTANCE));
62 if (NULL == (tidc->priv_dh = tr_create_dh_params(NULL, 0))) {
67 fprintf(stderr, "TIDC DH Parameters:\n");
68 DHparams_print_fp(stdout, tidc->priv_dh);
69 fprintf(stderr, "\n");
74 void tidc_destroy (TIDC_INSTANCE *tidc)
80 int tidc_open_connection (TIDC_INSTANCE *tidc,
87 err = gsscon_connect(server, TID_PORT, &conn);
90 err = gsscon_active_authenticate(conn, NULL, "trustquery", gssctx);
98 int tidc_send_request (TIDC_INSTANCE *tidc,
104 TIDC_RESP_FUNC *resp_handler,
112 size_t resp_buflen = 0;
116 /* Create and populate a TID msg structure */
117 if ((!(msg = malloc(sizeof(TR_MSG)))) ||
118 (!(tid_req = malloc(sizeof(TID_REQ)))))
121 memset(tid_req, 0, sizeof(tid_req));
123 msg->msg_type = TID_REQUEST;
125 msg->tid_req = tid_req;
127 tid_req->conn = conn;
129 /* TBD -- error handling */
130 tid_req->rp_realm = tr_new_name(rp_realm);
131 tid_req->realm = tr_new_name(realm);
132 tid_req->coi = tr_new_name(coi);
134 tid_req->tidc_dh = tidc->priv_dh;
136 tid_req->resp_func = resp_handler;
137 tid_req->cookie = cookie;
139 /* Encode the request into a json string */
140 if (!(req_buf = tr_msg_encode(msg))) {
141 printf("Error encoding TID request.\n");
145 printf ("Sending TID request:\n");
146 printf ("%s\n", req_buf);
148 /* Send the request over the connection */
149 if (err = gsscon_write_encrypted_token (conn, gssctx, req_buf,
151 fprintf(stderr, "Error sending request over connection.\n");
155 /* TBD -- should queue request on instance, resps read in separate thread */
156 /* Read the response from the connection */
158 if (err = gsscon_read_encrypted_token(conn, gssctx, &resp_buf, &resp_buflen)) {
164 fprintf(stdout, "Response Received, %d bytes.\n", resp_buflen);
166 /* Parse response -- TBD */
168 /* Call the caller's response function */
169 (*resp_handler)(tidc, NULL, cookie);