/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-09-05 07:11:24 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080905071124-9dq11jq5rfd6zfxf
* Makefile: Changed to use symbolic instead of octal modes throughout.
  (KEYDIR): New variable for the key directory.
  (install-server): Bug fix: remove "--parents" from install args.
  (install-client): Bug fix: - '' -  Also create key directory.  Do
                    not chmod plugin dir.  Create custom plugin directory
                    if not the same as normal plugin directory.  Add
                    "--dir" option to "mandos-keygen".  Add note about
                    running "mandos-keygen --password".
  (uninstall-server): Do not depend on the installed server binary,
                      since this made it impossible to do a purge
                      after an uninstall.
  (purge-client): Shred seckey.txt.  Use $(KEYDIR).

* README: Improved wording.

* initramfs-tools-hook: Use a loop to find prefix.  Also find keydir.
                        Remove "${DESTDIR}" from "copy_exec".  Do not
                        try to copy literal "*" if no custom plugins
                        are found.  Copy key files from keydir, not
                        config dir.  Only repair mode on directories
                        that actually exist.  Do not run chmod if
                        nothing needs repairing.

* plugin-runner.conf: New file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  -*- coding: utf-8 -*- */
2
2
/*
3
 
 * Mandos-client - get and decrypt data from a Mandos server
 
3
 * Mandos client - get and decrypt data from a Mandos server
4
4
 *
5
5
 * This program is partly derived from an example program for an Avahi
6
6
 * service browser, downloaded from
9
9
 * "browse_callback", and parts of "main".
10
10
 * 
11
11
 * Everything else is
12
 
 * Copyright © 2008,2009 Teddy Hogeborn
13
 
 * Copyright © 2008,2009 Björn Påhlsson
 
12
 * Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
14
13
 * 
15
14
 * This program is free software: you can redistribute it and/or
16
15
 * modify it under the terms of the GNU General Public License as
102
101
 
103
102
#define BUFFER_SIZE 256
104
103
 
 
104
/*
 
105
  #define PATHDIR "/conf/conf.d/mandos"
 
106
*/
 
107
 
105
108
#define PATHDIR "/conf/conf.d/mandos"
106
109
#define SECKEY "seckey.txt"
107
 
#define PUBKEY "pubkey.txt"
 
110
#define PUBKEY "pupkey.txt"
108
111
 
109
112
bool debug = false;
110
113
static const char mandos_protocol_version[] = "1";
111
 
const char *argp_program_version = "mandos-client " VERSION;
 
114
const char *argp_program_version = "password-request 1.0";
112
115
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
113
116
 
114
117
/* Used for passing in values through the Avahi callback functions */
147
150
  int ret;
148
151
  gpgme_error_t rc;
149
152
  gpgme_engine_info_t engine_info;
150
 
  
 
153
 
151
154
  
152
155
  /*
153
156
   * Helper function to insert pub and seckey to the enigne keyring.
156
159
    int fd;
157
160
    gpgme_data_t pgp_data;
158
161
    
159
 
    fd = (int)TEMP_FAILURE_RETRY(open(filename, O_RDONLY));
 
162
    fd = TEMP_FAILURE_RETRY(open(filename, O_RDONLY));
160
163
    if(fd == -1){
161
164
      perror("open");
162
165
      return false;
168
171
              gpgme_strsource(rc), gpgme_strerror(rc));
169
172
      return false;
170
173
    }
171
 
    
 
174
 
172
175
    rc = gpgme_op_import(mc->ctx, pgp_data);
173
176
    if (rc != GPG_ERR_NO_ERROR){
174
177
      fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
175
178
              gpgme_strsource(rc), gpgme_strerror(rc));
176
179
      return false;
177
180
    }
178
 
    
179
 
    ret = (int)TEMP_FAILURE_RETRY(close(fd));
 
181
 
 
182
    ret = TEMP_FAILURE_RETRY(close(fd));
180
183
    if(ret == -1){
181
184
      perror("close");
182
185
    }
187
190
  if (debug){
188
191
    fprintf(stderr, "Initialize gpgme\n");
189
192
  }
190
 
  
 
193
 
191
194
  /* Init GPGME */
192
195
  gpgme_check_version(NULL);
193
196
  rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
196
199
            gpgme_strsource(rc), gpgme_strerror(rc));
197
200
    return false;
198
201
  }
199
 
  
 
202
 
200
203
    /* Set GPGME home directory for the OpenPGP engine only */
201
204
  rc = gpgme_get_engine_info (&engine_info);
202
205
  if (rc != GPG_ERR_NO_ERROR){
216
219
    fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
217
220
    return false;
218
221
  }
219
 
  
 
222
 
220
223
  /* Create new GPGME "context" */
221
224
  rc = gpgme_new(&(mc->ctx));
222
225
  if (rc != GPG_ERR_NO_ERROR){
312
315
  
313
316
  /* Seek back to the beginning of the GPGME plaintext data buffer */
314
317
  if (gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET) == -1){
315
 
    perror("gpgme_data_seek");
 
318
    perror("pgpme_data_seek");
316
319
    plaintext_length = -1;
317
320
    goto decrypt_end;
318
321
  }
448
451
  
449
452
  gnutls_certificate_free_credentials(mc->cred);
450
453
  gnutls_global_deinit();
451
 
  gnutls_dh_params_deinit(mc->dh_params);
452
454
  return -1;
453
455
}
454
456
 
501
503
                                      AvahiIfIndex if_index,
502
504
                                      mandos_context *mc){
503
505
  int ret, tcp_sd;
504
 
  ssize_t sret;
505
506
  union { struct sockaddr in; struct sockaddr_in6 in6; } to;
506
507
  char *buffer = NULL;
507
508
  char *decrypted_buffer;
578
579
  written = 0;
579
580
  while (true){
580
581
    size_t out_size = strlen(out);
581
 
    ret = (int)TEMP_FAILURE_RETRY(write(tcp_sd, out + written,
 
582
    ret = TEMP_FAILURE_RETRY(write(tcp_sd, out + written,
582
583
                                   out_size - written));
583
584
    if (ret == -1){
584
585
      perror("write");
633
634
      goto mandos_end;
634
635
    }
635
636
    
636
 
    sret = gnutls_record_recv(session, buffer+buffer_length,
637
 
                              BUFFER_SIZE);
638
 
    if (sret == 0){
 
637
    ret = gnutls_record_recv(session, buffer+buffer_length,
 
638
                             BUFFER_SIZE);
 
639
    if (ret == 0){
639
640
      break;
640
641
    }
641
 
    if (sret < 0){
642
 
      switch(sret){
 
642
    if (ret < 0){
 
643
      switch(ret){
643
644
      case GNUTLS_E_INTERRUPTED:
644
645
      case GNUTLS_E_AGAIN:
645
646
        break;
662
663
        goto mandos_end;
663
664
      }
664
665
    } else {
665
 
      buffer_length += (size_t) sret;
 
666
      buffer_length += (size_t) ret;
666
667
    }
667
668
  }
668
669
  
704
705
  
705
706
 mandos_end:
706
707
  free(buffer);
707
 
  ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
 
708
  ret = TEMP_FAILURE_RETRY(close(tcp_sd));
708
709
  if(ret == -1){
709
710
    perror("close");
710
711
  }
829
830
                          .dh_bits = 1024, .priority = "SECURE256"
830
831
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
831
832
    bool gnutls_initalized = false;
832
 
    bool gpgme_initalized = false;
 
833
    bool pgpme_initalized = false;
833
834
    
834
835
    {
835
836
      struct argp_option options[] = {
917
918
      }
918
919
    }
919
920
    
 
921
    ret = init_gnutls_global(&mc, pubkey, seckey);
 
922
    if (ret == -1){
 
923
      fprintf(stderr, "init_gnutls_global failed\n");
 
924
      exitcode = EXIT_FAILURE;
 
925
      goto end;
 
926
    } else {
 
927
      gnutls_initalized = true;
 
928
    }
 
929
 
 
930
    if(mkdtemp(tempdir) == NULL){
 
931
      perror("mkdtemp");
 
932
      tempdir[0] = '\0';
 
933
      goto end;
 
934
    }
 
935
    
 
936
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
 
937
      fprintf(stderr, "pgpme_initalized failed\n");
 
938
      exitcode = EXIT_FAILURE;
 
939
      goto end;
 
940
    } else {
 
941
      pgpme_initalized = true;
 
942
    }
 
943
    
920
944
    /* If the interface is down, bring it up */
921
945
    {
922
946
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
941
965
          goto end;
942
966
        }
943
967
      }
944
 
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
968
      ret = TEMP_FAILURE_RETRY(close(sd));
945
969
      if(ret == -1){
946
970
        perror("close");
947
971
      }
960
984
      perror("setgid");
961
985
    }
962
986
    
963
 
    ret = init_gnutls_global(&mc, pubkey, seckey);
964
 
    if (ret == -1){
965
 
      fprintf(stderr, "init_gnutls_global failed\n");
966
 
      exitcode = EXIT_FAILURE;
967
 
      goto end;
968
 
    } else {
969
 
      gnutls_initalized = true;
970
 
    }
971
 
    
972
 
    if(mkdtemp(tempdir) == NULL){
973
 
      perror("mkdtemp");
974
 
      tempdir[0] = '\0';
975
 
      goto end;
976
 
    }
977
 
    
978
 
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
979
 
      fprintf(stderr, "gpgme_initalized failed\n");
980
 
      exitcode = EXIT_FAILURE;
981
 
      goto end;
982
 
    } else {
983
 
      gpgme_initalized = true;
984
 
    }
985
 
    
986
987
    if_index = (AvahiIfIndex) if_nametoindex(interface);
987
988
    if(if_index == 0){
988
989
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
1097
1098
    if (gnutls_initalized){
1098
1099
      gnutls_certificate_free_credentials(mc.cred);
1099
1100
      gnutls_global_deinit ();
1100
 
      gnutls_dh_params_deinit(mc.dh_params);
1101
1101
    }
1102
 
    
1103
 
    if(gpgme_initalized){
 
1102
 
 
1103
    if(pgpme_initalized){
1104
1104
      gpgme_release(mc.ctx);
1105
1105
    }
1106
 
    
 
1106
 
1107
1107
    /* Removes the temp directory used by GPGME */
1108
1108
    if(tempdir[0] != '\0'){
1109
1109
      DIR *d;
1133
1133
            free(fullname);
1134
1134
          }
1135
1135
        }
1136
 
        closedir(d);
1137
1136
      }
1138
1137
      ret = rmdir(tempdir);
1139
1138
      if(ret == -1){