/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugins.d/mandosclient.c

  • Committer: Teddy Hogeborn
  • Date: 2008-08-02 14:33:47 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080802143347-u1m4zs1q0feu72ei
* TODO: Converted to org-mode style

* plugins.d/mandosclient.c (certdir): Changed to "/conf/conf.d/mandos/".
  (certdir, certfile, certkey, pgp_packet_decrypt, debuggnutls,
  initgnutls, empty_log, combinepath): Made static.
  (combinepath): Rewritten to only get the argument string lengths
                 once.  Do not print error message; leave that to
                 caller.  All callers changed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
#include <errno.h>              /* perror() */
64
64
#include <gpgme.h>
65
65
 
66
 
// getopt_long
 
66
// getopt long
67
67
#include <getopt.h>
68
68
 
69
69
#define BUFFER_SIZE 256
70
 
 
71
 
static int dh_bits = 1024;
72
 
 
73
 
static const char *keydir = "/conf/conf.d/mandos";
74
 
static const char *pubkeyfile = "pubkey.txt";
75
 
static const char *seckeyfile = "seckey.txt";
 
70
#define DH_BITS 1024
 
71
 
 
72
static const char *certdir = "/conf/conf.d/mandos";
 
73
static const char *certfile = "openpgp-client.txt";
 
74
static const char *certkey = "openpgp-client-key.txt";
76
75
 
77
76
bool debug = false;
78
77
 
79
 
/* Used for  */
80
78
typedef struct {
81
79
  gnutls_session_t session;
82
80
  gnutls_certificate_credentials_t cred;
282
280
  
283
281
  if(debug){
284
282
    fprintf(stderr, "Attempting to use OpenPGP certificate %s"
285
 
            " and keyfile %s as GnuTLS credentials\n", pubkeyfile,
286
 
            seckeyfile);
 
283
            " and keyfile %s as GnuTLS credentials\n", certfile,
 
284
            certkey);
287
285
  }
288
286
  
289
287
  ret = gnutls_certificate_set_openpgp_key_file
290
 
    (es->cred, pubkeyfile, seckeyfile, GNUTLS_OPENPGP_FMT_BASE64);
 
288
    (es->cred, certfile, certkey, GNUTLS_OPENPGP_FMT_BASE64);
291
289
  if (ret != GNUTLS_E_SUCCESS) {
292
290
    fprintf
293
291
      (stderr, "Error[%d] while reading the OpenPGP key pair ('%s',"
294
292
       " '%s')\n",
295
 
       ret, pubkeyfile, seckeyfile);
 
293
       ret, certfile, certkey);
296
294
    fprintf(stdout, "The Error is: %s\n",
297
295
            safer_gnutls_strerror(ret));
298
296
    return -1;
306
304
    return -1;
307
305
  }
308
306
  
309
 
  if ((ret = gnutls_dh_params_generate2 (es->dh_params, dh_bits))
 
307
  if ((ret = gnutls_dh_params_generate2 (es->dh_params, DH_BITS))
310
308
      != GNUTLS_E_SUCCESS) {
311
309
    fprintf (stderr, "Error in prime generation: %s\n",
312
310
             safer_gnutls_strerror(ret));
342
340
  gnutls_certificate_server_set_request (es->session,
343
341
                                         GNUTLS_CERT_IGNORE);
344
342
  
345
 
  gnutls_dh_set_prime_bits (es->session, dh_bits);
 
343
  gnutls_dh_set_prime_bits (es->session, DH_BITS);
346
344
  
347
345
  return 0;
348
346
}
403
401
  
404
402
  if(debug){
405
403
    fprintf(stderr, "Connection to: %s, port %d\n", ip, port);
406
 
    char addrstr[INET6_ADDRSTRLEN] = "";
407
 
    if(inet_ntop(to.sin6_family, &(to.sin6_addr), addrstr,
408
 
                 sizeof(addrstr)) == NULL){
409
 
      perror("inet_ntop");
410
 
    } else {
411
 
      if(strcmp(addrstr, ip) != 0){
412
 
        fprintf(stderr, "Canonical address form: %s\n",
413
 
                addrstr, ntohs(to.sin6_port));
414
 
      }
415
 
    }
 
404
/*     char addrstr[INET6_ADDRSTRLEN]; */
 
405
/*     if(inet_ntop(to.sin6_family, &(to.sin6_addr), addrstr, */
 
406
/*               sizeof(addrstr)) == NULL){ */
 
407
/*       perror("inet_ntop"); */
 
408
/*     } else { */
 
409
/*       fprintf(stderr, "Really connecting to: %s, port %d\n", */
 
410
/*            addrstr, ntohs(to.sin6_port)); */
 
411
/*     } */
416
412
  }
417
413
  
418
414
  ret = connect(tcp_sd, (struct sockaddr *) &to, sizeof(to));
497
493
    decrypted_buffer_size = pgp_packet_decrypt(buffer,
498
494
                                               buffer_length,
499
495
                                               &decrypted_buffer,
500
 
                                               keydir);
 
496
                                               certdir);
501
497
    if (decrypted_buffer_size >= 0){
502
498
      while(written < (size_t) decrypted_buffer_size){
503
499
        ret = (int)fwrite (decrypted_buffer + written, 1,
658
654
    AvahiSServiceBrowser *sb = NULL;
659
655
    int error;
660
656
    int ret;
661
 
    int debug_int = 0;
662
657
    int returncode = EXIT_SUCCESS;
663
658
    const char *interface = NULL;
664
659
    AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
665
660
    char *connect_to = NULL;
666
661
    
667
 
    debug_int = debug ? 1 : 0;
668
662
    while (true){
669
663
      static struct option long_options[] = {
670
 
        {"debug", no_argument, &debug_int, 1},
671
 
        {"connect", required_argument, NULL, 'C'},
672
 
        {"interface", required_argument, NULL, 'i'},
673
 
        {"keydir", required_argument, NULL, 'd'},
674
 
        {"seckey", required_argument, NULL, 'c'},
675
 
        {"pubkey", required_argument, NULL, 'k'},
676
 
        {"dh-bits", required_argument, NULL, 'D'},
 
664
        {"debug", no_argument, (int *)&debug, 1},
 
665
        {"connect", required_argument, 0, 'C'},
 
666
        {"interface", required_argument, 0, 'i'},
 
667
        {"certdir", required_argument, 0, 'd'},
 
668
        {"certkey", required_argument, 0, 'c'},
 
669
        {"certfile", required_argument, 0, 'k'},
677
670
        {0, 0, 0, 0} };
678
671
      
679
672
      int option_index = 0;
694
687
        connect_to = optarg;
695
688
        break;
696
689
      case 'd':
697
 
        keydir = optarg;
 
690
        certdir = optarg;
698
691
        break;
699
692
      case 'c':
700
 
        pubkeyfile = optarg;
 
693
        certfile = optarg;
701
694
        break;
702
695
      case 'k':
703
 
        seckeyfile = optarg;
704
 
        break;
705
 
      case 'D':
706
 
        dh_bits = atoi(optarg);
707
 
        break;
708
 
      case '?':
709
 
        break
 
696
        certkey = optarg;
 
697
        break;
710
698
      default:
711
699
        exit(EXIT_FAILURE);
712
700
      }
713
701
    }
714
 
    debug = debug_int ? true : false;
715
702
    
716
 
    pubkeyfile = combinepath(keydir, pubkeyfile);
717
 
    if (pubkeyfile == NULL){
 
703
    certfile = combinepath(certdir, certfile);
 
704
    if (certfile == NULL){
718
705
      perror("combinepath");
719
706
      goto exit;
720
707
    }
751
738
      }
752
739
    }
753
740
    
754
 
    seckeyfile = combinepath(keydir, seckeyfile);
755
 
    if (seckeyfile == NULL){
 
741
    certkey = combinepath(certdir, certkey);
 
742
    if (certkey == NULL){
756
743
      perror("combinepath");
757
744
      goto exit;
758
745
    }
828
815
 
829
816
    if (simple_poll)
830
817
        avahi_simple_poll_free(simple_poll);
831
 
    free(pubkeyfile);
832
 
    free(seckeyfile);
 
818
    free(certfile);
 
819
    free(certkey);
833
820
    
834
821
    return returncode;
835
822
}