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.
44 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
45 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
46 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
47 0x19, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
50 TPQC_INSTANCE *tpqc_create ()
52 TPQC_INSTANCE *tpqc = NULL;
54 if (tpqc = malloc(sizeof(TPQC_INSTANCE)))
55 memset(tpqc, 0, sizeof(TPQC_INSTANCE));
59 /* TBD -- Generate random private key */
60 tpqc->priv_key = tmp_key;
61 tpqc->priv_len = tmp_len;
63 if (NULL == (tpqc->priv_dh = tr_create_dh_params(tpqc->priv_key, tpqc->priv_len))) {
68 fprintf(stderr, "TPQC DH Parameters:\n");
69 DHparams_print_fp(stdout, tpqc->priv_dh);
70 fprintf(stderr, "\n");
75 void tpqc_destroy (TPQC_INSTANCE *tpqc)
81 int tpqc_open_connection (TPQC_INSTANCE *tpqc,
88 err = gsscon_connect(server, TPQ_PORT, &conn);
91 err = gsscon_active_authenticate(conn, NULL, "trustquery", gssctx);
99 int tpqc_send_request (TPQC_INSTANCE *tpqc,
104 TPQC_RESP_FUNC *resp_handler,
112 size_t resp_buflen = 0;
114 /* Create a json TPQ request */
115 if (NULL == (jreq = json_object())) {
116 fprintf(stderr,"Error creating json object.\n");
120 if (0 > (err = json_object_set_new(jreq, "type", json_string("tpq_request")))) {
121 fprintf(stderr, "Error adding type to request.\n");
125 /* Insert realm and coi into the json request */
126 if (0 > (err = json_object_set_new(jreq, "realm", json_string(realm)))) {
127 fprintf(stderr, "Error adding realm to request.\n");
130 if (0 > (err = json_object_set_new(jreq, "coi", json_string(coi)))) {
131 fprintf(stderr, "Error adding coi to request.\n");
135 /* Generate half of a D-H exchange -- TBD */
136 /* Insert D-H information into the request -- TBD */
138 /* Encode the json request */
139 if (NULL == (req_buf = json_dumps(jreq, 0))) {
140 fprintf(stderr, "Error encoding json request.\n");
144 printf("Encoded request:\n%s\n", req_buf);
146 /* Send the request over the connection */
147 if (err = gsscon_write_encrypted_token (conn, gssctx, req_buf,
148 strlen(req_buf) + 1)) {
149 fprintf(stderr, "Error sending request over connection.\n");
155 /* read the response from the connection */
157 if (err = gsscon_read_encrypted_token(conn, gssctx, &resp_buf, &resp_buflen)) {
163 fprintf(stdout, "Response Received, %d bytes.\n", resp_buflen);
165 /* Parse response -- TBD */
167 /* Call the caller's response function */
168 (*resp_handler)(tpqc, NULL, cookie);