#include <tr_debug.h>
#include <tid_internal.h>
#include <trust_router/tr_dh.h>
+#include <trust_router/tid.h>
+#include <tr_inet_util.h>
+
+struct tidc_resp_cookie {
+ int succeeded;
+};
static void tidc_resp_handler (TIDC_INSTANCE * tidc,
TID_REQ *req,
int c_keylen = 0;
unsigned char *c_keybuf = NULL;
int i;
+ struct timeval tv;
+ struct tidc_resp_cookie *data = talloc_get_type_abort(cookie, struct tidc_resp_cookie);
printf ("Response received! Realm = %s, Community = %s.\n", resp->realm->buf, resp->comm->buf);
+ data->succeeded = 0;
+
/* Generate the client key -- TBD, handle more than one server */
if (TID_SUCCESS != resp->result) {
fprintf(stderr, "tidc_resp_handler: Response is an error.\n");
fprintf(stderr, "tidc_resp_handler: Response does not contain server info.\n");
return;
}
-
+ if (tid_srvr_get_key_expiration(tid_resp_get_server(resp, 0), &tv))
+ printf("Error reading key expiration\n");
+ else
+ printf("Key expiration: %s", ctime(&tv.tv_sec));
+
+
if (0 > (c_keylen = tr_compute_dh_key(&c_keybuf,
resp->servers->aaa_server_dh->pub_key,
req->tidc_dh))) {
}
printf("\n");
+ data->succeeded = 1;
return;
}
+static void print_version_info(void)
+{
+ printf("Moonshot TID Client %s\n\n", PACKAGE_VERSION);
+}
+
/* command-line option setup */
/* argp global parameters */
const char *argp_program_bug_address=PACKAGE_BUGREPORT; /* bug reporting address */
/* doc strings */
-static const char doc[]=PACKAGE_NAME " - TID Client";
+static const char doc[]=PACKAGE_NAME " - Moonshot TID Client " PACKAGE_VERSION;
static const char arg_doc[]="<server> <RP-realm> <target-realm> <community> [<port>]"; /* string describing arguments, if any */
/* define the options here. Fields are:
* { long-name, short-name, variable name, options, help description } */
static const struct argp_option cmdline_options[] = {
- { NULL }
+ { "version", 'v', NULL, 0, "Print version information and exit"},
+ { NULL }
};
/* structure for communicating with option parser */
break;
case 4:
- arguments->port=strtol(arg, NULL, 10); /* optional */
+ arguments->port=tr_parse_port(arg); /* optional */
+ if (arguments->port < 0) {
+ switch(-(arguments->port)) {
+ case ERANGE:
+ printf("\nError parsing port (%s): port must be an integer in the range 1 - 65535\n\n", arg);
+ break;
+
+ default:
+ printf("\nError parsing port (%s): %s\n\n", arg, strerror(-arguments->port));
+ break;
+ }
+ argp_usage(state);
+ }
break;
default:
}
break;
+ case 'v':
+ print_version_info();
+ exit(0);
+
default:
return ARGP_ERR_UNKNOWN;
}
return 0; /* success */
}
+/* Exit values */
+#define EXIT_OK 0
+#define EXIT_REQ_FAILED 2
+#define EXIT_ERROR 1
+
/* assemble the argp parser */
static struct argp argp = {cmdline_options, parse_option, arg_doc, doc};
int rc;
gss_ctx_id_t gssctx;
struct cmdline_args opts;
+ struct tidc_resp_cookie cookie = {0};
/* parse the command line*/
/* set defaults */
argp_parse(&argp, argc, argv, 0, 0, &opts);
/* TBD -- validity checking, dealing with quotes, etc. */
+ print_version_info();
+
/* Use standalone logging */
tr_log_open();
/* Create a TID client instance & the client DH */
tidc = tidc_create();
- if (NULL == (tidc->client_dh = tr_create_dh_params(NULL, 0))) {
+ tidc_set_dh(tidc, tr_create_dh_params(NULL, 0));
+ if (tidc_get_dh(tidc) == NULL) {
printf("Error creating client DH params.\n");
- return 1;
+ return EXIT_ERROR;
}
/* 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;
+ return EXIT_ERROR;
};
/* 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))) {
+ &tidc_resp_handler, &cookie))) {
/* Handle error */
printf("Error in tidc_send_request, rc = %d.\n", rc);
- return 1;
+ return EXIT_ERROR;
}
/* Clean-up the TID client instance, and exit */
- tidc_free(tidc);
+ tidc_destroy(tidc);
- return 0;
+ if (cookie.succeeded)
+ return EXIT_OK;
+ else
+ return EXIT_REQ_FAILED;
}