108
108
#define PATHDIR "/conf/conf.d/mandos"
109
109
#define SECKEY "seckey.txt"
110
#define PUBKEY "pupkey.txt"
110
#define PUBKEY "pubkey.txt"
112
112
bool debug = false;
113
113
static const char mandos_protocol_version[] = "1";
114
const char *argp_program_version = "password-request 1.0";
114
const char *argp_program_version = "mandos-client 1.0";
115
115
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
117
117
/* Used for passing in values through the Avahi callback functions */
171
171
gpgme_strsource(rc), gpgme_strerror(rc));
175
175
rc = gpgme_op_import(mc->ctx, pgp_data);
176
176
if (rc != GPG_ERR_NO_ERROR){
177
177
fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
178
178
gpgme_strsource(rc), gpgme_strerror(rc));
182
182
ret = TEMP_FAILURE_RETRY(close(fd));
415
fprintf(stderr, "Attempting to use OpenPGP certificate %s"
416
" and keyfile %s as GnuTLS credentials\n", pubkeyfilename,
415
fprintf(stderr, "Attempting to use OpenPGP public key %s and"
416
" secret key %s as GnuTLS credentials\n", pubkeyfilename,
604
603
fprintf(stderr, "Establishing TLS session with %s\n", ip);
607
606
gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) tcp_sd);
610
609
ret = gnutls_handshake (session);
611
610
} while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
828
827
const char *pubkey = PATHDIR "/" PUBKEY;
830
829
mandos_context mc = { .simple_poll = NULL, .server = NULL,
831
.dh_bits = 1024, .priority = "SECURE256"};
830
.dh_bits = 1024, .priority = "SECURE256"
831
":!CTYPE-X.509:+CTYPE-OPENPGP" };
832
832
bool gnutls_initalized = false;
833
833
bool pgpme_initalized = false;
837
837
{ .name = "debug", .key = 128,
838
838
.doc = "Debug mode", .group = 3 },
839
839
{ .name = "connect", .key = 'c',
841
.doc = "Connect directly to a sepcified mandos server",
840
.arg = "ADDRESS:PORT",
841
.doc = "Connect directly to a specific Mandos server",
843
843
{ .name = "interface", .key = 'i',
845
.doc = "Interface that Avahi will conntect through",
845
.doc = "Interface that will be used to search for Mandos"
847
848
{ .name = "seckey", .key = 's',
849
.doc = "Secret openpgp key for gnutls authentication",
850
.doc = "OpenPGP secret key file base name",
851
852
{ .name = "pubkey", .key = 'p',
853
.doc = "Public openpgp key for gnutls authentication",
854
.doc = "OpenPGP public key file base name",
855
856
{ .name = "dh-bits", .key = 129,
857
.doc = "dh-bits to use in gnutls communication",
858
.doc = "Bit length of the prime number used in the"
859
" Diffie-Hellman key exchange",
859
861
{ .name = "priority", .key = 130,
861
.doc = "GNUTLS priority", .group = 1 },
863
.doc = "GnuTLS priority string for the TLS handshake",
866
868
error_t parse_opt (int key, char *arg,
867
869
struct argp_state *state) {
868
870
/* Get the INPUT argument from `argp_parse', which we know is
869
871
a pointer to our plugin list pointer. */
873
case 128: /* --debug */
876
case 'c': /* --connect */
875
877
connect_to = arg;
879
case 'i': /* --interface */
882
case 's': /* --seckey */
885
case 'p': /* --pubkey */
888
case 129: /* --dh-bits */
888
890
mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
907
909
struct argp argp = { .options = options, .parser = parse_opt,
909
911
.doc = "Mandos client -- Get and decrypt"
910
" passwords from mandos server" };
912
" passwords from a Mandos server" };
911
913
ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
912
914
if (ret == ARGP_ERR_UNKNOWN){
913
915
fprintf(stderr, "Unknown error while parsing arguments\n");
919
ret = init_gnutls_global(&mc, pubkey, seckey);
921
fprintf(stderr, "init_gnutls_global failed\n");
922
exitcode = EXIT_FAILURE;
925
gnutls_initalized = true;
928
if(mkdtemp(tempdir) == NULL){
934
if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
935
fprintf(stderr, "pgpme_initalized failed\n");
936
exitcode = EXIT_FAILURE;
939
pgpme_initalized = true;
942
921
/* If the interface is down, bring it up */
982
961
perror("setgid");
964
ret = init_gnutls_global(&mc, pubkey, seckey);
966
fprintf(stderr, "init_gnutls_global failed\n");
967
exitcode = EXIT_FAILURE;
970
gnutls_initalized = true;
973
if(mkdtemp(tempdir) == NULL){
979
if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
980
fprintf(stderr, "pgpme_initalized failed\n");
981
exitcode = EXIT_FAILURE;
984
pgpme_initalized = true;
985
987
if_index = (AvahiIfIndex) if_nametoindex(interface);
986
988
if(if_index == 0){
987
989
fprintf(stderr, "No such interface: \"%s\"\n", interface);
1039
1041
config.publish_addresses = 0;
1040
1042
config.publish_workstation = 0;
1041
1043
config.publish_domain = 0;
1043
1045
/* Allocate a new server */
1044
1046
mc.server = avahi_server_new(avahi_simple_poll_get
1045
1047
(mc.simple_poll), &config, NULL,
1048
1050
/* Free the Avahi configuration data */
1049
1051
avahi_server_config_free(&config);