| 1 |
/* |
| 2 |
* Utility program for generating entries in /etc/ppp/srp-secrets |
| 3 |
* |
| 4 |
* Copyright (c) 2001 by Sun Microsystems, Inc. |
| 5 |
* All rights reserved. |
| 6 |
* |
| 7 |
* Non-exclusive rights to redistribute, modify, translate, and use |
| 8 |
* this software in source and binary forms, in whole or in part, is |
| 9 |
* hereby granted, provided that the above copyright notice is |
| 10 |
* duplicated in any source form, and that neither the name of the |
| 11 |
* copyright holder nor the author is used to endorse or promote |
| 12 |
* products derived from this software. |
| 13 |
* |
| 14 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 15 |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 16 |
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 17 |
* |
| 18 |
* Original version by James Carlson |
| 19 |
* |
| 20 |
* Usage: |
| 21 |
* srp-entry [-i index] [clientname] |
| 22 |
* |
| 23 |
* Index, if supplied, is the modulus/generator index from |
| 24 |
* /etc/tpasswd.conf. If not supplied, then the last (highest |
| 25 |
* numbered) entry from that file is used. If the file doesn't exist, |
| 26 |
* then the default "well known" EAP SRP-SHA1 modulus/generator is |
| 27 |
* used. |
| 28 |
* |
| 29 |
* The default modulus/generator can be requested as index 0. |
| 30 |
*/ |
| 31 |
|
| 32 |
#ifdef HAVE_CONFIG_H |
| 33 |
#include "config.h" |
| 34 |
#endif |
| 35 |
|
| 36 |
#include <stdio.h> |
| 37 |
#include <stdlib.h> |
| 38 |
#include <unistd.h> |
| 39 |
#include <string.h> |
| 40 |
#include <ctype.h> |
| 41 |
#include <t_pwd.h> |
| 42 |
|
| 43 |
#ifndef SOL2 |
| 44 |
#define getpassphrase getpass |
| 45 |
#endif |
| 46 |
|
| 47 |
#define HAS_SPACE 1 |
| 48 |
#define HAS_DQUOTE 2 |
| 49 |
#define HAS_SQUOTE 4 |
| 50 |
#define HAS_BACKSLASH 8 |
| 51 |
|
| 52 |
static const u_char wkmodulus[] = { |
| 53 |
0xAC, 0x6B, 0xDB, 0x41, 0x32, 0x4A, 0x9A, 0x9B, |
| 54 |
0xF1, 0x66, 0xDE, 0x5E, 0x13, 0x89, 0x58, 0x2F, |
| 55 |
0xAF, 0x72, 0xB6, 0x65, 0x19, 0x87, 0xEE, 0x07, |
| 56 |
0xFC, 0x31, 0x92, 0x94, 0x3D, 0xB5, 0x60, 0x50, |
| 57 |
0xA3, 0x73, 0x29, 0xCB, 0xB4, 0xA0, 0x99, 0xED, |
| 58 |
0x81, 0x93, 0xE0, 0x75, 0x77, 0x67, 0xA1, 0x3D, |
| 59 |
0xD5, 0x23, 0x12, 0xAB, 0x4B, 0x03, 0x31, 0x0D, |
| 60 |
0xCD, 0x7F, 0x48, 0xA9, 0xDA, 0x04, 0xFD, 0x50, |
| 61 |
0xE8, 0x08, 0x39, 0x69, 0xED, 0xB7, 0x67, 0xB0, |
| 62 |
0xCF, 0x60, 0x95, 0x17, 0x9A, 0x16, 0x3A, 0xB3, |
| 63 |
0x66, 0x1A, 0x05, 0xFB, 0xD5, 0xFA, 0xAA, 0xE8, |
| 64 |
0x29, 0x18, 0xA9, 0x96, 0x2F, 0x0B, 0x93, 0xB8, |
| 65 |
0x55, 0xF9, 0x79, 0x93, 0xEC, 0x97, 0x5E, 0xEA, |
| 66 |
0xA8, 0x0D, 0x74, 0x0A, 0xDB, 0xF4, 0xFF, 0x74, |
| 67 |
0x73, 0x59, 0xD0, 0x41, 0xD5, 0xC3, 0x3E, 0xA7, |
| 68 |
0x1D, 0x28, 0x1E, 0x44, 0x6B, 0x14, 0x77, 0x3B, |
| 69 |
0xCA, 0x97, 0xB4, 0x3A, 0x23, 0xFB, 0x80, 0x16, |
| 70 |
0x76, 0xBD, 0x20, 0x7A, 0x43, 0x6C, 0x64, 0x81, |
| 71 |
0xF1, 0xD2, 0xB9, 0x07, 0x87, 0x17, 0x46, 0x1A, |
| 72 |
0x5B, 0x9D, 0x32, 0xE6, 0x88, 0xF8, 0x77, 0x48, |
| 73 |
0x54, 0x45, 0x23, 0xB5, 0x24, 0xB0, 0xD5, 0x7D, |
| 74 |
0x5E, 0xA7, 0x7A, 0x27, 0x75, 0xD2, 0xEC, 0xFA, |
| 75 |
0x03, 0x2C, 0xFB, 0xDB, 0xF5, 0x2F, 0xB3, 0x78, |
| 76 |
0x61, 0x60, 0x27, 0x90, 0x04, 0xE5, 0x7A, 0xE6, |
| 77 |
0xAF, 0x87, 0x4E, 0x73, 0x03, 0xCE, 0x53, 0x29, |
| 78 |
0x9C, 0xCC, 0x04, 0x1C, 0x7B, 0xC3, 0x08, 0xD8, |
| 79 |
0x2A, 0x56, 0x98, 0xF3, 0xA8, 0xD0, 0xC3, 0x82, |
| 80 |
0x71, 0xAE, 0x35, 0xF8, 0xE9, 0xDB, 0xFB, 0xB6, |
| 81 |
0x94, 0xB5, 0xC8, 0x03, 0xD8, 0x9F, 0x7A, 0xE4, |
| 82 |
0x35, 0xDE, 0x23, 0x6D, 0x52, 0x5F, 0x54, 0x75, |
| 83 |
0x9B, 0x65, 0xE3, 0x72, 0xFC, 0xD6, 0x8E, 0xF2, |
| 84 |
0x0F, 0xA7, 0x11, 0x1F, 0x9E, 0x4A, 0xFF, 0x73 |
| 85 |
}; |
| 86 |
|
| 87 |
static const char *myname; |
| 88 |
|
| 89 |
static void |
| 90 |
usage(void) |
| 91 |
{ |
| 92 |
(void) fprintf(stderr, "Usage:\n\t%s [-i index] [clientname]\n", |
| 93 |
myname); |
| 94 |
exit(1); |
| 95 |
} |
| 96 |
|
| 97 |
int |
| 98 |
main(int argc, char **argv) |
| 99 |
{ |
| 100 |
struct t_conf *tc; |
| 101 |
struct t_confent *tcent, mytce; |
| 102 |
struct t_pw pwval; |
| 103 |
char *name; |
| 104 |
char pname[256]; |
| 105 |
char *pass1, *pass2; |
| 106 |
int flags, idx; |
| 107 |
char *cp; |
| 108 |
char delimit; |
| 109 |
char strbuf[MAXB64PARAMLEN]; |
| 110 |
char saltbuf[MAXB64SALTLEN]; |
| 111 |
|
| 112 |
if ((myname = *argv) == NULL) |
| 113 |
myname = "srp-entry"; |
| 114 |
else |
| 115 |
argv++; |
| 116 |
|
| 117 |
idx = -1; |
| 118 |
if (*argv != NULL && strcmp(*argv, "-i") == 0) { |
| 119 |
if (*++argv == NULL) |
| 120 |
usage(); |
| 121 |
idx = atoi(*argv++); |
| 122 |
} |
| 123 |
|
| 124 |
tcent = NULL; |
| 125 |
if (idx != 0 && (tc = t_openconf(NULL)) != NULL) { |
| 126 |
if (idx == -1) |
| 127 |
tcent = t_getconflast(tc); |
| 128 |
else |
| 129 |
tcent = t_getconfbyindex(tc, idx); |
| 130 |
} |
| 131 |
if (idx <= 0 && tcent == NULL) { |
| 132 |
mytce.index = 0; |
| 133 |
mytce.modulus.data = (u_char *)wkmodulus; |
| 134 |
mytce.modulus.len = sizeof (wkmodulus); |
| 135 |
mytce.generator.data = (u_char *)"\002"; |
| 136 |
mytce.generator.len = 1; |
| 137 |
tcent = &mytce; |
| 138 |
} |
| 139 |
if (tcent == NULL) { |
| 140 |
(void) fprintf(stderr, "SRP modulus/generator %d not found\n", |
| 141 |
idx); |
| 142 |
exit(1); |
| 143 |
} |
| 144 |
|
| 145 |
if ((name = *argv) == NULL) { |
| 146 |
(void) printf("Client name: "); |
| 147 |
if (fgets(pname, sizeof (pname), stdin) == NULL) |
| 148 |
exit(1); |
| 149 |
if ((cp = strchr(pname, '\n')) != NULL) |
| 150 |
*cp = '\0'; |
| 151 |
name = pname; |
| 152 |
} |
| 153 |
|
| 154 |
for (;;) { |
| 155 |
if ((pass1 = getpassphrase("Pass phrase: ")) == NULL) |
| 156 |
exit(1); |
| 157 |
pass1 = strdup(pass1); |
| 158 |
if ((pass2 = getpassphrase("Re-enter phrase: ")) == NULL) |
| 159 |
exit(1); |
| 160 |
if (strcmp(pass1, pass2) == 0) |
| 161 |
break; |
| 162 |
free(pass1); |
| 163 |
(void) printf("Phrases don't match; try again.\n"); |
| 164 |
} |
| 165 |
|
| 166 |
memset(&pwval, 0, sizeof (pwval)); |
| 167 |
t_makepwent(&pwval, name, pass1, NULL, tcent); |
| 168 |
flags = 0; |
| 169 |
for (cp = name; *cp != '\0'; cp++) |
| 170 |
if (isspace(*cp)) |
| 171 |
flags |= HAS_SPACE; |
| 172 |
else if (*cp == '"') |
| 173 |
flags |= HAS_DQUOTE; |
| 174 |
else if (*cp == '\'') |
| 175 |
flags |= HAS_SQUOTE; |
| 176 |
else if (*cp == '\\') |
| 177 |
flags |= HAS_BACKSLASH; |
| 178 |
delimit = flags == 0 ? '\0' : (flags & HAS_DQUOTE) ? '\'' : '"'; |
| 179 |
if (delimit != '\0') |
| 180 |
(void) putchar(delimit); |
| 181 |
for (cp = name; *cp != '\0'; cp++) { |
| 182 |
if (*cp == delimit || *cp == '\\') |
| 183 |
(void) putchar('\\'); |
| 184 |
(void) putchar(*cp); |
| 185 |
} |
| 186 |
if (delimit != '\0') |
| 187 |
(void) putchar(delimit); |
| 188 |
(void) printf(" * %d:%s:%s *\n", |
| 189 |
pwval.pebuf.index, t_tob64(strbuf, |
| 190 |
(char *)pwval.pebuf.password.data, pwval.pebuf.password.len), |
| 191 |
t_tob64(saltbuf, (char *)pwval.pebuf.salt.data, |
| 192 |
pwval.pebuf.salt.len)); |
| 193 |
return 0; |
| 194 |
} |