#include <sqlite3.h>
#include <trust_router/tid.h>
-#include <tr_dh.h>
+#include <trust_router/tr_dh.h>
#include <openssl/rand.h>
static sqlite3 *db = NULL;
return -1;
}
- /* Hard-code the IP Address in the response. If this were a AAA server, we'd expect
- * this to be set by the Trust Router before calling us.
- */
- if (0 == inet_aton("127.0.0.1", &((*resp)->servers->aaa_server_addr))) {
+ if (0 == inet_aton(tids->ipaddr, &((*resp)->servers->aaa_server_addr))) {
printf("tids_req_handler(): inet_aton() failed.\n");
return -1;
}
/* Generate the server key */
printf("Generating the server key.\n");
- if (NULL == (s_keybuf = malloc(DH_size((*resp)->servers->aaa_server_dh)))) {
- printf ("tids_req_handler(): Can't allocate server keybuf.\n");
- return -1;
- }
- if (0 > (s_keylen = tr_compute_dh_key(s_keybuf,
- DH_size((*resp)->servers->aaa_server_dh),
+ if (0 > (s_keylen = tr_compute_dh_key(&s_keybuf,
req->tidc_dh->pub_key,
(*resp)->servers->aaa_server_dh))) {
printf("tids_req_handler(): Key computation failed.");
{
TIDS_INSTANCE *tids;
int rc = 0;
+ char *ipaddr = NULL;
/* Parse command-line arguments */
- if (argc > 2)
- printf("Unexpected arguments, ignored.\n");
+ if (argc > 3)
+ printf("Usage: %s [<ip-address> [<database-name>]]\n", argv[0]);
- /*If we have a database, open and prepare*/
if (argc >= 2) {
- if (SQLITE_OK != sqlite3_open(argv[1], &db)) {
- printf("Error opening database\n");
+ ipaddr = (char *)argv[1];
+ } else {
+ ipaddr = "127.0.0.1";
+ }
+
+ /* TBD -- check that input is a valid IP address? */
+
+ /*If we have a database, open and prepare*/
+ if (argc == 3) {
+ if (SQLITE_OK != sqlite3_open(argv[2], &db)) {
+ printf("Error opening database %s\n", argv[2]);
exit(1);
}
sqlite3_prepare_v2(db, "insert into psk_keys (keyid, key) values(?, ?)",
return 1;
}
+ tids->ipaddr = ipaddr;
+
/* Start-up the server, won't return unless there is an error. */
rc = tids_start(tids, &tids_req_handler , NULL);