65
65
#include <arpa/inet.h> /* inet_pton() */
66
66
#include <iso646.h> /* not */
67
67
#include <net/if.h> /* IF_NAMESIZE */
68
#include <argp.h> /* struct argp_option,
69
struct argp_state, struct argp,
72
70
#include <errno.h> /* perror() */
75
76
#define BUFFER_SIZE 256
78
static const char *keydir = "/conf/conf.d/mandos";
79
static const char *pubkeyfile = "pubkey.txt";
80
static const char *seckeyfile = "seckey.txt";
77
82
bool debug = false;
78
static const char *keydir = "/conf/conf.d/mandos";
79
static const char mandos_protocol_version[] = "1";
80
const char *argp_program_version = "mandosclient 0.9";
81
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
83
/* Used for passing in values through the Avahi callback functions */
84
const char mandos_protocol_version[] = "1";
86
/* Used for passing in values through all the callback functions */
85
88
AvahiSimplePoll *simple_poll;
86
89
AvahiServer *server;
345
339
if (ret != GNUTLS_E_SUCCESS) {
346
340
fprintf (stderr, "Error in GnuTLS DH parameter initialization:"
347
341
" %s\n", safer_gnutls_strerror(ret));
350
344
ret = gnutls_dh_params_generate2(mc->dh_params, mc->dh_bits);
351
345
if (ret != GNUTLS_E_SUCCESS) {
352
346
fprintf (stderr, "Error in GnuTLS prime generation: %s\n",
353
347
safer_gnutls_strerror(ret));
357
351
gnutls_certificate_set_dh_params(mc->cred, mc->dh_params);
363
gnutls_certificate_free_credentials (mc->cred);
364
gnutls_global_deinit ();
369
static int init_gnutls_session(mandos_context *mc,
370
gnutls_session_t *session){
356
static int init_gnutls_session(mandos_context *mc, gnutls_session_t *session){
372
358
/* GnuTLS session creation */
373
359
ret = gnutls_init(session, GNUTLS_SERVER);
463
448
fprintf(stderr, "Bad address: %s\n", ip);
466
to.in6.sin6_port = htons(port); /* Spurious warning */
451
to.sin6_port = htons(port); /* Spurious warning */
468
to.in6.sin6_scope_id = (uint32_t)if_index;
453
to.sin6_scope_id = (uint32_t)if_index;
471
456
fprintf(stderr, "Connection to: %s, port %d\n", ip, port);
472
457
char addrstr[INET6_ADDRSTRLEN] = "";
473
if(inet_ntop(to.in6.sin6_family, &(to.in6.sin6_addr), addrstr,
458
if(inet_ntop(to.sin6_family, &(to.sin6_addr), addrstr,
474
459
sizeof(addrstr)) == NULL){
475
460
perror("inet_ntop");
746
732
char *connect_to = NULL;
747
733
AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
748
const char *pubkeyfile = "pubkey.txt";
749
const char *seckeyfile = "seckey.txt";
750
734
mandos_context mc = { .simple_poll = NULL, .server = NULL,
751
735
.dh_bits = 1024, .priority = "SECURE256"};
752
bool gnutls_initalized = false;
755
struct argp_option options[] = {
756
{ .name = "debug", .key = 128,
757
.doc = "Debug mode", .group = 3 },
758
{ .name = "connect", .key = 'c',
760
.doc = "Connect directly to a sepcified mandos server",
762
{ .name = "interface", .key = 'i',
764
.doc = "Interface that Avahi will conntect through",
766
{ .name = "keydir", .key = 'd',
768
.doc = "Directory where the openpgp keyring is",
770
{ .name = "seckey", .key = 's',
772
.doc = "Secret openpgp key for gnutls authentication",
774
{ .name = "pubkey", .key = 'p',
776
.doc = "Public openpgp key for gnutls authentication",
778
{ .name = "dh-bits", .key = 129,
780
.doc = "dh-bits to use in gnutls communication",
782
{ .name = "priority", .key = 130,
784
.doc = "GNUTLS priority", .group = 1 },
789
error_t parse_opt (int key, char *arg,
790
struct argp_state *state) {
791
/* Get the INPUT argument from `argp_parse', which we know is
792
a pointer to our plugin list pointer. */
738
/* Temporary int to get the address of for getopt_long */
739
int debug_int = debug ? 1 : 0;
741
struct option long_options[] = {
742
{"debug", no_argument, &debug_int, 1},
743
{"connect", required_argument, NULL, 'c'},
744
{"interface", required_argument, NULL, 'i'},
745
{"keydir", required_argument, NULL, 'd'},
746
{"seckey", required_argument, NULL, 's'},
747
{"pubkey", required_argument, NULL, 'p'},
748
{"dh-bits", required_argument, NULL, 'D'},
749
{"priority", required_argument, NULL, 'P'},
752
int option_index = 0;
753
ret = getopt_long (argc, argv, "i:", long_options,
814
mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
780
mc.dh_bits = (unsigned int) strtol(optarg, NULL, 10);
816
782
perror("strtol");
817
783
exit(EXIT_FAILURE);
787
mc.priority = optarg;
829
return ARGP_ERR_UNKNOWN;
791
/* getopt_long() has already printed a message about the
792
unrcognized option, so just exit. */
834
struct argp argp = { .options = options, .parser = parse_opt,
836
.doc = "Mandos client -- Get and decrypt"
837
" passwords from mandos server" };
838
argp_parse (&argp, argc, argv, 0, 0, NULL);
796
/* Set the global debug flag from the temporary int */
797
debug = debug_int ? true : false;
841
800
pubkeyfile = combinepath(keydir, pubkeyfile);
842
801
if (pubkeyfile == NULL){
843
802
perror("combinepath");