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.
41 TPQC_INSTANCE *tpqc_create ()
43 TPQC_INSTANCE *tpqc = NULL;
45 if (tpqc = malloc(sizeof(TPQC_INSTANCE)))
46 memset(tpqc, 0, sizeof(TPQC_INSTANCE));
51 int tpqc_open_connection (TPQC_INSTANCE *tpqc,
58 err = gsscon_connect(server, TPQ_PORT, &conn);
61 err = gsscon_active_authenticate(conn, NULL, "trustquery", gssctx);
69 int tpqc_send_request (TPQC_INSTANCE *tpqc,
74 TPQC_RESP_FUNC *resp_handler,
82 size_t resp_buflen = 0;
84 /* Create a json TPQ request */
85 if (NULL == (jreq = json_object())) {
86 fprintf(stderr,"Error creating json object.\n");
90 if (0 > (err = json_object_set_new(jreq, "type", json_string("tpq_request")))) {
91 fprintf(stderr, "Error adding type to request.\n");
95 /* Insert realm and coi into the json request */
96 if (0 > (err = json_object_set_new(jreq, "realm", json_string(realm)))) {
97 fprintf(stderr, "Error adding realm to request.\n");
100 if (0 > (err = json_object_set_new(jreq, "coi", json_string(coi)))) {
101 fprintf(stderr, "Error adding coi to request.\n");
105 /* Generate half of a D-H exchange -- TBD */
106 /* Insert D-H information into the request -- TBD */
108 /* Encode the json request */
109 if (NULL == (req_buf = json_dumps(jreq, 0))) {
110 fprintf(stderr, "Error encoding json request.\n");
114 printf("Encoded request:\n%s\n", req_buf);
116 /* Send the request over the connection */
117 if (err = gsscon_write_encrypted_token (conn, gssctx, req_buf,
118 strlen(req_buf) + 1)) {
119 fprintf(stderr, "Error sending request over connection.\n");
125 /* read the response from the connection */
127 if (err = gsscon_read_encrypted_token(conn, gssctx, &resp_buf, &resp_buflen)) {
133 fprintf(stdout, "Response Received, %d bytes.\n", resp_buflen);
135 /* Parse response -- TBD */
137 /* Call the caller's response function */
138 (*resp_handler)(tpqc, NULL, cookie);
146 void tpqc_destroy (TPQC_INSTANCE *tpqc)