summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c51
1 files changed, 38 insertions, 13 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index e5e2f2f6c..533eed291 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.236 2013/12/06 03:40:51 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.237 2013/12/06 13:34:54 markus Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -150,6 +150,18 @@ char *key_type_name = NULL;
150/* Load key from this PKCS#11 provider */ 150/* Load key from this PKCS#11 provider */
151char *pkcs11provider = NULL; 151char *pkcs11provider = NULL;
152 152
153/* Use new OpenSSH private key format when writing SSH2 keys instead of PEM */
154int use_new_format = 0;
155
156/* Cipher for new-format private keys */
157char *new_format_cipher = NULL;
158
159/*
160 * Number of KDF rounds to derive new format keys /
161 * number of primality trials when screening moduli.
162 */
163int rounds = 0;
164
153/* argv0 */ 165/* argv0 */
154extern char *__progname; 166extern char *__progname;
155 167
@@ -923,7 +935,8 @@ do_gen_all_hostkeys(struct passwd *pw)
923 public = key_from_private(private); 935 public = key_from_private(private);
924 snprintf(comment, sizeof comment, "%s@%s", pw->pw_name, 936 snprintf(comment, sizeof comment, "%s@%s", pw->pw_name,
925 hostname); 937 hostname);
926 if (!key_save_private(private, identity_file, "", comment)) { 938 if (!key_save_private(private, identity_file, "", comment,
939 use_new_format, new_format_cipher, rounds)) {
927 printf("Saving the key failed: %s.\n", identity_file); 940 printf("Saving the key failed: %s.\n", identity_file);
928 key_free(private); 941 key_free(private);
929 key_free(public); 942 key_free(public);
@@ -1275,7 +1288,8 @@ do_change_passphrase(struct passwd *pw)
1275 } 1288 }
1276 1289
1277 /* Save the file using the new passphrase. */ 1290 /* Save the file using the new passphrase. */
1278 if (!key_save_private(private, identity_file, passphrase1, comment)) { 1291 if (!key_save_private(private, identity_file, passphrase1, comment,
1292 use_new_format, new_format_cipher, rounds)) {
1279 printf("Saving the key failed: %s.\n", identity_file); 1293 printf("Saving the key failed: %s.\n", identity_file);
1280 memset(passphrase1, 0, strlen(passphrase1)); 1294 memset(passphrase1, 0, strlen(passphrase1));
1281 free(passphrase1); 1295 free(passphrase1);
@@ -1385,7 +1399,8 @@ do_change_comment(struct passwd *pw)
1385 } 1399 }
1386 1400
1387 /* Save the file using the new passphrase. */ 1401 /* Save the file using the new passphrase. */
1388 if (!key_save_private(private, identity_file, passphrase, new_comment)) { 1402 if (!key_save_private(private, identity_file, passphrase, new_comment,
1403 use_new_format, new_format_cipher, rounds)) {
1389 printf("Saving the key failed: %s.\n", identity_file); 1404 printf("Saving the key failed: %s.\n", identity_file);
1390 memset(passphrase, 0, strlen(passphrase)); 1405 memset(passphrase, 0, strlen(passphrase));
1391 free(passphrase); 1406 free(passphrase);
@@ -2132,7 +2147,7 @@ usage(void)
2132 fprintf(stderr, "usage: %s [options]\n", __progname); 2147 fprintf(stderr, "usage: %s [options]\n", __progname);
2133 fprintf(stderr, "Options:\n"); 2148 fprintf(stderr, "Options:\n");
2134 fprintf(stderr, " -A Generate non-existent host keys for all key types.\n"); 2149 fprintf(stderr, " -A Generate non-existent host keys for all key types.\n");
2135 fprintf(stderr, " -a trials Number of trials for screening DH-GEX moduli.\n"); 2150 fprintf(stderr, " -a number Number of KDF rounds for new key format or moduli primality tests.\n");
2136 fprintf(stderr, " -B Show bubblebabble digest of key file.\n"); 2151 fprintf(stderr, " -B Show bubblebabble digest of key file.\n");
2137 fprintf(stderr, " -b bits Number of bits in the key to create.\n"); 2152 fprintf(stderr, " -b bits Number of bits in the key to create.\n");
2138 fprintf(stderr, " -C comment Provide new comment.\n"); 2153 fprintf(stderr, " -C comment Provide new comment.\n");
@@ -2160,6 +2175,7 @@ usage(void)
2160 fprintf(stderr, " -N phrase Provide new passphrase.\n"); 2175 fprintf(stderr, " -N phrase Provide new passphrase.\n");
2161 fprintf(stderr, " -n name,... User/host principal names to include in certificate\n"); 2176 fprintf(stderr, " -n name,... User/host principal names to include in certificate\n");
2162 fprintf(stderr, " -O option Specify a certificate option.\n"); 2177 fprintf(stderr, " -O option Specify a certificate option.\n");
2178 fprintf(stderr, " -o Enforce new private key format.\n");
2163 fprintf(stderr, " -P phrase Provide old passphrase.\n"); 2179 fprintf(stderr, " -P phrase Provide old passphrase.\n");
2164 fprintf(stderr, " -p Change passphrase of private key file.\n"); 2180 fprintf(stderr, " -p Change passphrase of private key file.\n");
2165 fprintf(stderr, " -Q Test whether key(s) are revoked in KRL.\n"); 2181 fprintf(stderr, " -Q Test whether key(s) are revoked in KRL.\n");
@@ -2176,6 +2192,7 @@ usage(void)
2176 fprintf(stderr, " -W gen Generator to use for generating DH-GEX moduli.\n"); 2192 fprintf(stderr, " -W gen Generator to use for generating DH-GEX moduli.\n");
2177 fprintf(stderr, " -y Read private key file and print public key.\n"); 2193 fprintf(stderr, " -y Read private key file and print public key.\n");
2178 fprintf(stderr, " -z serial Specify a serial number.\n"); 2194 fprintf(stderr, " -z serial Specify a serial number.\n");
2195 fprintf(stderr, " -Z cipher Specify a cipher for new private key format.\n");
2179 2196
2180 exit(1); 2197 exit(1);
2181} 2198}
@@ -2193,7 +2210,7 @@ main(int argc, char **argv)
2193 struct passwd *pw; 2210 struct passwd *pw;
2194 struct stat st; 2211 struct stat st;
2195 int opt, type, fd; 2212 int opt, type, fd;
2196 u_int32_t memory = 0, generator_wanted = 0, trials = 100; 2213 u_int32_t memory = 0, generator_wanted = 0;
2197 int do_gen_candidates = 0, do_screen_candidates = 0; 2214 int do_gen_candidates = 0, do_screen_candidates = 0;
2198 int gen_all_hostkeys = 0, gen_krl = 0, update_krl = 0, check_krl = 0; 2215 int gen_all_hostkeys = 0, gen_krl = 0, update_krl = 0, check_krl = 0;
2199 unsigned long start_lineno = 0, lines_to_process = 0; 2216 unsigned long start_lineno = 0, lines_to_process = 0;
@@ -2225,9 +2242,9 @@ main(int argc, char **argv)
2225 exit(1); 2242 exit(1);
2226 } 2243 }
2227 2244
2228 /* Remaining characters: EUYZdow */ 2245 /* Remaining characters: EUYdw */
2229 while ((opt = getopt(argc, argv, "ABHLQXceghiklpquvxy" 2246 while ((opt = getopt(argc, argv, "ABHLQXceghiklopquvxy"
2230 "C:D:F:G:I:J:K:M:N:O:P:R:S:T:V:W:a:b:f:j:m:n:r:s:t:z:")) != -1) { 2247 "C:D:F:G:I:J:K:M:N:O:P:R:S:T:V:W:Z:a:b:f:g:j:m:n:r:s:t:z:")) != -1) {
2231 switch (opt) { 2248 switch (opt) {
2232 case 'A': 2249 case 'A':
2233 gen_all_hostkeys = 1; 2250 gen_all_hostkeys = 1;
@@ -2285,6 +2302,9 @@ main(int argc, char **argv)
2285 case 'n': 2302 case 'n':
2286 cert_principals = optarg; 2303 cert_principals = optarg;
2287 break; 2304 break;
2305 case 'o':
2306 use_new_format = 1;
2307 break;
2288 case 'p': 2308 case 'p':
2289 change_passphrase = 1; 2309 change_passphrase = 1;
2290 break; 2310 break;
@@ -2312,6 +2332,9 @@ main(int argc, char **argv)
2312 case 'O': 2332 case 'O':
2313 add_cert_option(optarg); 2333 add_cert_option(optarg);
2314 break; 2334 break;
2335 case 'Z':
2336 new_format_cipher = optarg;
2337 break;
2315 case 'C': 2338 case 'C':
2316 identity_comment = optarg; 2339 identity_comment = optarg;
2317 break; 2340 break;
@@ -2370,9 +2393,9 @@ main(int argc, char **argv)
2370 optarg, errstr); 2393 optarg, errstr);
2371 break; 2394 break;
2372 case 'a': 2395 case 'a':
2373 trials = (u_int32_t)strtonum(optarg, 1, UINT_MAX, &errstr); 2396 rounds = (int)strtonum(optarg, 1, INT_MAX, &errstr);
2374 if (errstr) 2397 if (errstr)
2375 fatal("Invalid number of trials: %s (%s)", 2398 fatal("Invalid number: %s (%s)",
2376 optarg, errstr); 2399 optarg, errstr);
2377 break; 2400 break;
2378 case 'M': 2401 case 'M':
@@ -2531,7 +2554,8 @@ main(int argc, char **argv)
2531 fatal("Couldn't open moduli file \"%s\": %s", 2554 fatal("Couldn't open moduli file \"%s\": %s",
2532 out_file, strerror(errno)); 2555 out_file, strerror(errno));
2533 } 2556 }
2534 if (prime_test(in, out, trials, generator_wanted, checkpoint, 2557 if (prime_test(in, out, rounds == 0 ? 100 : rounds,
2558 generator_wanted, checkpoint,
2535 start_lineno, lines_to_process) != 0) 2559 start_lineno, lines_to_process) != 0)
2536 fatal("modulus screening failed"); 2560 fatal("modulus screening failed");
2537 return (0); 2561 return (0);
@@ -2623,7 +2647,8 @@ passphrase_again:
2623 } 2647 }
2624 2648
2625 /* Save the key with the given passphrase and comment. */ 2649 /* Save the key with the given passphrase and comment. */
2626 if (!key_save_private(private, identity_file, passphrase1, comment)) { 2650 if (!key_save_private(private, identity_file, passphrase1, comment,
2651 use_new_format, new_format_cipher, rounds)) {
2627 printf("Saving the key failed: %s.\n", identity_file); 2652 printf("Saving the key failed: %s.\n", identity_file);
2628 memset(passphrase1, 0, strlen(passphrase1)); 2653 memset(passphrase1, 0, strlen(passphrase1));
2629 free(passphrase1); 2654 free(passphrase1);