int main (int argc, char *argv[]) { TIDC_INSTANCE *tidc; int conn = 0; int rc; gss_ctx_id_t gssctx; struct cmdline_args opts; /* parse the command line*/ /* set defaults */ opts.server=NULL; opts.rp_realm=NULL; opts.target_realm=NULL; opts.community=NULL; opts.port=TID_PORT; argp_parse(&argp, argc, argv, 0, 0, &opts); /* TBD -- validity checking, dealing with quotes, etc. */ print_version_info(); /* Use standalone logging */ tr_log_open(); /* set logging levels */ talloc_set_log_stderr(); tr_log_threshold(LOG_CRIT); tr_console_threshold(LOG_DEBUG); printf("TIDC Client:\nServer = %s, rp_realm = %s, target_realm = %s, community = %s, port = %i\n", opts.server, opts.rp_realm, opts.target_realm, opts.community, opts.port); /* Create a TID client instance & the client DH */ tidc = tidc_create(); if (NULL == (tidc->client_dh = tr_create_dh_params(NULL, 0))) { printf("Error creating client DH params.\n"); return 1; } /* Set-up TID connection */ if (-1 == (conn = tidc_open_connection(tidc, opts.server, opts.port, &gssctx))) { /* Handle error */ printf("Error in tidc_open_connection.\n"); return 1; }; /* Send a TID request */ if (0 > (rc = tidc_send_request(tidc, conn, gssctx, opts.rp_realm, opts.target_realm, opts.community, &tidc_resp_handler, NULL))) { /* Handle error */ printf("Error in tidc_send_request, rc = %d.\n", rc); return 1; } /* Clean-up the TID client instance, and exit */ tidc_destroy(tidc); return 0; }
bool tr_init(void) { if (global_tidc) return true; global_tidc = tidc_create(); if (!global_tidc) { DEBUG2( "tr_init: Error creating global TIDC instance.\n"); return false; } if (!tidc_set_dh(global_tidc, tr_create_dh_params(NULL, 0))) { DEBUG2( "tr_init: Error creating client DH params.\n"); return false; } return true; }
int main (int argc, const char *argv[]) { DH *c_dh = NULL; DH *s_dh = NULL; unsigned char *c_keybuf = NULL; unsigned char *s_keybuf = NULL; int c_keylen = 0, s_keylen = 0, i = 0; const BIGNUM *pub_key; /* TBD -- Generate random private keys */ /* Generate initial DH params on the client side */ if (NULL == (c_dh = tr_create_dh_params(NULL, 0))) { printf("Error: Can't create client DH params, exiting.\n"); exit(1); } fprintf(stderr, "Client DH Parameters:\n"); DHparams_print_fp(stdout, c_dh); fprintf(stderr, "\n"); /*** Would now send DH params and client's public key to the server ***/ /* Generate DH params on the server side */ if (NULL == (s_dh = tr_create_matching_dh(NULL, 0, c_dh))) { printf("Error: Can't create server server DH params, exiting.\n"); exit(1); } fprintf(stdout, "Server DH Parameters:\n"); DHparams_print_fp(stdout, s_dh); fprintf(stdout, "\n"); /*** Would now send server's pub key to client ***/ /* Compute key on client */ DH_get0_key(s_dh, &pub_key, NULL); if (0 > (c_keylen = tr_compute_dh_key(&c_keybuf, pub_key, c_dh))) { printf("Error: Can't compute client key.\n"); } /* Compute key on server */ DH_get0_key(c_dh, &pub_key, NULL); if (0 > (s_keylen = tr_compute_dh_key(&s_keybuf, pub_key, s_dh))) { printf("Error: Can't compute server key.\n"); exit(1); } /* Print out the client key. */ printf("Client Key Generated (len = %d):\n", c_keylen); for (i = 0; i < c_keylen; i++) { printf("%2x", c_keybuf[i]); } printf("\n"); /* Print out the server key. */ printf("Server Key Generated (len = %d):\n", s_keylen); for (i = 0; i < s_keylen; i++) { printf("%2x", s_keybuf[i]); } printf("\n"); /* Compare the two keys to see if they match */ if ((c_keylen != s_keylen) || (0 != memcmp(c_keybuf, s_keybuf, c_keylen))) { printf("Error: Different keys generated!\n"); exit(1); } printf("Success: Identical keys generated, key length = %d!\n", c_keylen); exit(0); }