1 /*- 2 * Copyright (c) 2010 Alistair Crooks <agc@NetBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 #include <sys/types.h> 26 27 #include <netdb.h> 28 29 #include <netpgp.h> 30 #include <regex.h> 31 #include <sha1.h> 32 #include <stdio.h> 33 #include <stdlib.h> 34 #include <string.h> 35 #include <time.h> 36 #include <unistd.h> 37 38 #include "libpaa.h" 39 40 #define DEFAULT_HASH_ALG "SHA256" 41 42 int 43 main(int argc, char **argv) 44 { 45 paa_response_t response; 46 netpgp_t netpgp; 47 char challenge[2048]; 48 char buf[2048]; 49 int challengec; 50 int cc; 51 int i; 52 53 (void) memset(&response, 0x0, sizeof(response)); 54 (void) memset(&netpgp, 0x0, sizeof(netpgp)); 55 while ((i = getopt(argc, argv, "S:d:r:u:")) != -1) { 56 switch(i) { 57 case 'S': 58 netpgp_setvar(&netpgp, "ssh keys", "1"); 59 netpgp_setvar(&netpgp, "sshkeyfile", optarg); 60 break; 61 case 'd': 62 //challenge.domain = optarg; 63 break; 64 case 'r': 65 //challenge.realm = optarg; 66 response.realm = optarg; 67 break; 68 case 'u': 69 netpgp_setvar(&netpgp, "userid", optarg); 70 break; 71 } 72 } 73 netpgp_setvar(&netpgp, "hash", DEFAULT_HASH_ALG); 74 netpgp_setvar(&netpgp, "need seckey", "1"); 75 netpgp_setvar(&netpgp, "need userid", "1"); 76 netpgp_set_homedir(&netpgp, getenv("HOME"), 77 netpgp_getvar(&netpgp, "ssh keys") ? "/.ssh" : "/.gnupg", 1); 78 if (!netpgp_init(&netpgp)) { 79 (void) fprintf(stderr, "can't initialise netpgp\n"); 80 exit(EXIT_FAILURE); 81 } 82 /* read challenge into challenge */ 83 challengec = read(0, challenge, sizeof(challenge)); 84 cc = paa_format_response(&response, &netpgp, challenge, buf, sizeof(buf)); 85 write(1, buf, cc); 86 exit(EXIT_SUCCESS); 87 } 88