/mandos/trunk

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

« back to all changes in this revision

Viewing changes to plugins.d/password-request.c

  • Committer: Teddy Hogeborn
  • Date: 2008-08-27 01:18:25 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080827011825-ka3ni6xvy2ehi1y8
* .bzrignore: New.

* clients.conf ([foo]): Remove Radix-64 checksum.

* mandos (AvahiService.rename, server_state_changed,
          entry_group_state_changed): Make Avahi log messages more
                                      clear that they are about
                                      Zeroconf.
  (fingerprint): Use plain "0" instead of "ctypes.c_uint(0)".

Show diffs side-by-side

added added

removed removed

Lines of Context:
281
281
    }
282
282
    plaintext_length += ret;
283
283
  }
284
 
  
 
284
 
285
285
  if(debug){
286
286
    fprintf(stderr, "Decrypted password is: ");
287
287
    for(ssize_t i = 0; i < plaintext_length; i++){
348
348
  }
349
349
  
350
350
  if(debug){
351
 
    fprintf(stderr, "Attempting to use OpenPGP public key %s and"
352
 
            " secret key %s as GnuTLS credentials\n", pubkeyfilename,
 
351
    fprintf(stderr, "Attempting to use OpenPGP certificate %s"
 
352
            " and keyfile %s as GnuTLS credentials\n", pubkeyfilename,
353
353
            seckeyfilename);
354
354
  }
355
355
  
360
360
    fprintf(stderr,
361
361
            "Error[%d] while reading the OpenPGP key pair ('%s',"
362
362
            " '%s')\n", ret, pubkeyfilename, seckeyfilename);
363
 
    fprintf(stderr, "The GnuTLS error is: %s\n",
 
363
    fprintf(stdout, "The GnuTLS error is: %s\n",
364
364
            safer_gnutls_strerror(ret));
365
365
    goto globalfail;
366
366
  }
380
380
  }
381
381
  
382
382
  gnutls_certificate_set_dh_params(mc->cred, mc->dh_params);
383
 
  
 
383
 
384
384
  return 0;
385
 
  
 
385
 
386
386
 globalfail:
387
 
  
 
387
 
388
388
  gnutls_certificate_free_credentials(mc->cred);
389
389
  gnutls_global_deinit();
390
390
  return -1;
 
391
 
391
392
}
392
393
 
393
394
static int init_gnutls_session(mandos_context *mc,
465
466
    perror("socket");
466
467
    return -1;
467
468
  }
468
 
  
 
469
 
469
470
  if(debug){
470
471
    if(if_indextoname((unsigned int)if_index, interface) == NULL){
471
472
      perror("if_indextoname");
510
511
    perror("connect");
511
512
    return -1;
512
513
  }
513
 
  
 
514
 
514
515
  const char *out = mandos_protocol_version;
515
516
  written = 0;
516
517
  while (true){
534
535
      }
535
536
    }
536
537
  }
537
 
  
 
538
 
538
539
  if(debug){
539
540
    fprintf(stderr, "Establishing TLS session with %s\n", ip);
540
541
  }
541
542
  
542
543
  gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) tcp_sd);
543
 
  
 
544
 
544
545
  do{
545
546
    ret = gnutls_handshake (session);
546
547
  } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
560
561
    fprintf(stderr, "Retrieving pgp encrypted password from %s\n",
561
562
            ip);
562
563
  }
563
 
  
 
564
 
564
565
  while(true){
565
566
    buffer_capacity = adjustbuffer(&buffer, buffer_length,
566
567
                                   buffer_capacity);
773
774
    const char *pubkeyname = "pubkey.txt";
774
775
    const char *seckeyname = "seckey.txt";
775
776
    mandos_context mc = { .simple_poll = NULL, .server = NULL,
776
 
                          .dh_bits = 1024, .priority = "SECURE256"
777
 
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
 
777
                          .dh_bits = 1024, .priority = "SECURE256"};
778
778
    bool gnutls_initalized = false;
779
779
    
780
780
    {
782
782
        { .name = "debug", .key = 128,
783
783
          .doc = "Debug mode", .group = 3 },
784
784
        { .name = "connect", .key = 'c',
785
 
          .arg = "ADDRESS:PORT",
786
 
          .doc = "Connect directly to a specific Mandos server",
 
785
          .arg = "IP",
 
786
          .doc = "Connect directly to a sepcified mandos server",
787
787
          .group = 1 },
788
788
        { .name = "interface", .key = 'i',
789
 
          .arg = "NAME",
790
 
          .doc = "Interface that will be used to search for Mandos"
791
 
          " servers",
 
789
          .arg = "INTERFACE",
 
790
          .doc = "Interface that Avahi will conntect through",
792
791
          .group = 1 },
793
792
        { .name = "keydir", .key = 'd',
794
 
          .arg = "DIRECTORY",
795
 
          .doc = "Directory to read the OpenPGP key files from",
 
793
          .arg = "KEYDIR",
 
794
          .doc = "Directory where the openpgp keyring is",
796
795
          .group = 1 },
797
796
        { .name = "seckey", .key = 's',
798
 
          .arg = "FILE",
799
 
          .doc = "OpenPGP secret key file base name",
 
797
          .arg = "SECKEY",
 
798
          .doc = "Secret openpgp key for gnutls authentication",
800
799
          .group = 1 },
801
800
        { .name = "pubkey", .key = 'p',
802
 
          .arg = "FILE",
803
 
          .doc = "OpenPGP public key file base name",
 
801
          .arg = "PUBKEY",
 
802
          .doc = "Public openpgp key for gnutls authentication",
804
803
          .group = 2 },
805
804
        { .name = "dh-bits", .key = 129,
806
805
          .arg = "BITS",
807
 
          .doc = "Bit length of the prime number used in the"
808
 
          " Diffie-Hellman key exchange",
 
806
          .doc = "dh-bits to use in gnutls communication",
809
807
          .group = 2 },
810
808
        { .name = "priority", .key = 130,
811
 
          .arg = "STRING",
812
 
          .doc = "GnuTLS priority string for the TLS handshake",
813
 
          .group = 1 },
 
809
          .arg = "PRIORITY",
 
810
          .doc = "GNUTLS priority", .group = 1 },
814
811
        { .name = NULL }
815
812
      };
 
813
 
816
814
      
817
815
      error_t parse_opt (int key, char *arg,
818
816
                         struct argp_state *state) {
819
817
        /* Get the INPUT argument from `argp_parse', which we know is
820
818
           a pointer to our plugin list pointer. */
821
819
        switch (key) {
822
 
        case 128:               /* --debug */
 
820
        case 128:
823
821
          debug = true;
824
822
          break;
825
 
        case 'c':               /* --connect */
 
823
        case 'c':
826
824
          connect_to = arg;
827
825
          break;
828
 
        case 'i':               /* --interface */
 
826
        case 'i':
829
827
          interface = arg;
830
828
          break;
831
 
        case 'd':               /* --keydir */
 
829
        case 'd':
832
830
          keydir = arg;
833
831
          break;
834
 
        case 's':               /* --seckey */
 
832
        case 's':
835
833
          seckeyname = arg;
836
834
          break;
837
 
        case 'p':               /* --pubkey */
 
835
        case 'p':
838
836
          pubkeyname = arg;
839
837
          break;
840
 
        case 129:               /* --dh-bits */
 
838
        case 129:
841
839
          errno = 0;
842
840
          mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
843
841
          if (errno){
845
843
            exit(EXIT_FAILURE);
846
844
          }
847
845
          break;
848
 
        case 130:               /* --priority */
 
846
        case 130:
849
847
          mc.priority = arg;
850
848
          break;
851
849
        case ARGP_KEY_ARG:
857
855
        }
858
856
        return 0;
859
857
      }
860
 
      
 
858
 
861
859
      struct argp argp = { .options = options, .parser = parse_opt,
862
860
                           .args_doc = "",
863
861
                           .doc = "Mandos client -- Get and decrypt"
864
 
                           " passwords from a Mandos server" };
 
862
                           " passwords from mandos server" };
865
863
      ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
866
864
      if (ret == ARGP_ERR_UNKNOWN){
867
865
        fprintf(stderr, "Unknown error while parsing arguments\n");
869
867
        goto end;
870
868
      }
871
869
    }
872
 
    
 
870
      
873
871
    pubkeyfilename = combinepath(keydir, pubkeyname);
874
872
    if (pubkeyfilename == NULL){
875
873
      perror("combinepath");
883
881
      exitcode = EXIT_FAILURE;
884
882
      goto end;
885
883
    }
886
 
    
 
884
 
887
885
    ret = init_gnutls_global(&mc, pubkeyfilename, seckeyfilename);
888
886
    if (ret == -1){
889
887
      fprintf(stderr, "init_gnutls_global failed\n");
981
979
        exitcode = EXIT_FAILURE;
982
980
        goto end;
983
981
    }
984
 
    
 
982
 
985
983
    {
986
984
      AvahiServerConfig config;
987
985
      /* Do not publish any local Zeroconf records */
990
988
      config.publish_addresses = 0;
991
989
      config.publish_workstation = 0;
992
990
      config.publish_domain = 0;
993
 
      
 
991
 
994
992
      /* Allocate a new server */
995
993
      mc.server = avahi_server_new(avahi_simple_poll_get
996
994
                                   (mc.simple_poll), &config, NULL,
997
995
                                   NULL, &error);
998
 
      
 
996
    
999
997
      /* Free the Avahi configuration data */
1000
998
      avahi_server_config_free(&config);
1001
999
    }
1021
1019
    }
1022
1020
    
1023
1021
    /* Run the main loop */
1024
 
    
 
1022
 
1025
1023
    if (debug){
1026
1024
      fprintf(stderr, "Starting Avahi loop search\n");
1027
1025
    }
1029
1027
    avahi_simple_poll_loop(mc.simple_poll);
1030
1028
    
1031
1029
 end:
1032
 
    
 
1030
 
1033
1031
    if (debug){
1034
1032
      fprintf(stderr, "%s exiting\n", argv[0]);
1035
1033
    }
1040
1038
    
1041
1039
    if (mc.server != NULL)
1042
1040
        avahi_server_free(mc.server);
1043
 
    
 
1041
 
1044
1042
    if (mc.simple_poll != NULL)
1045
1043
        avahi_simple_poll_free(mc.simple_poll);
1046
1044
    free(pubkeyfilename);
1047
1045
    free(seckeyfilename);
1048
 
    
 
1046
 
1049
1047
    if (gnutls_initalized){
1050
1048
      gnutls_certificate_free_credentials(mc.cred);
1051
1049
      gnutls_global_deinit ();