/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-19 23:44:17 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080819234417-8dz5prw19ihrklx6
* Makefile (DOCBOOKTOMAN): Include all DocBook-to-manpage-related
                           commands here, and use it everywhere.
  (mandos.8, mandos.conf.5): New; also depend on "mandos-options.xml".

* mandos-keygen.xml: Removed OVERVIEW entity.  Add XInclude namespace.
  (OVERVIEW): Changed to do <xi:include/>.

* mandos-options.xml (<simplesect>): Changed to a <section>.
  ([@id="address"]): Reordered sentences.

* mandos.conf.xml (OPTIONS): Removed illegal <arg> tags.
  (EXAMPLE): Added empty example.

* mandos.xml (NETWORK PROTOCOL): Bug fix: Changed "1\r\en" back to
                                 "1\r\n".
  (CHECKING): Do not refer to the non-relevant mandos.conf(5) manual.

Show diffs side-by-side

added added

removed removed

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