summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index eae83a461..2a316bcea 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.238 2013/12/06 13:39:49 markus Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.241 2014/02/05 20:13:25 naddy 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
@@ -267,7 +267,7 @@ load_identity(char *filename)
267 pass = read_passphrase("Enter passphrase: ", 267 pass = read_passphrase("Enter passphrase: ",
268 RP_ALLOW_STDIN); 268 RP_ALLOW_STDIN);
269 prv = key_load_private(filename, pass, NULL); 269 prv = key_load_private(filename, pass, NULL);
270 memset(pass, 0, strlen(pass)); 270 explicit_bzero(pass, strlen(pass));
271 free(pass); 271 free(pass);
272 } 272 }
273 return prv; 273 return prv;
@@ -1258,7 +1258,7 @@ do_change_passphrase(struct passwd *pw)
1258 RP_ALLOW_STDIN); 1258 RP_ALLOW_STDIN);
1259 private = key_load_private(identity_file, old_passphrase, 1259 private = key_load_private(identity_file, old_passphrase,
1260 &comment); 1260 &comment);
1261 memset(old_passphrase, 0, strlen(old_passphrase)); 1261 explicit_bzero(old_passphrase, strlen(old_passphrase));
1262 free(old_passphrase); 1262 free(old_passphrase);
1263 if (private == NULL) { 1263 if (private == NULL) {
1264 printf("Bad passphrase.\n"); 1264 printf("Bad passphrase.\n");
@@ -1280,15 +1280,15 @@ do_change_passphrase(struct passwd *pw)
1280 1280
1281 /* Verify that they are the same. */ 1281 /* Verify that they are the same. */
1282 if (strcmp(passphrase1, passphrase2) != 0) { 1282 if (strcmp(passphrase1, passphrase2) != 0) {
1283 memset(passphrase1, 0, strlen(passphrase1)); 1283 explicit_bzero(passphrase1, strlen(passphrase1));
1284 memset(passphrase2, 0, strlen(passphrase2)); 1284 explicit_bzero(passphrase2, strlen(passphrase2));
1285 free(passphrase1); 1285 free(passphrase1);
1286 free(passphrase2); 1286 free(passphrase2);
1287 printf("Pass phrases do not match. Try again.\n"); 1287 printf("Pass phrases do not match. Try again.\n");
1288 exit(1); 1288 exit(1);
1289 } 1289 }
1290 /* Destroy the other copy. */ 1290 /* Destroy the other copy. */
1291 memset(passphrase2, 0, strlen(passphrase2)); 1291 explicit_bzero(passphrase2, strlen(passphrase2));
1292 free(passphrase2); 1292 free(passphrase2);
1293 } 1293 }
1294 1294
@@ -1296,14 +1296,14 @@ do_change_passphrase(struct passwd *pw)
1296 if (!key_save_private(private, identity_file, passphrase1, comment, 1296 if (!key_save_private(private, identity_file, passphrase1, comment,
1297 use_new_format, new_format_cipher, rounds)) { 1297 use_new_format, new_format_cipher, rounds)) {
1298 printf("Saving the key failed: %s.\n", identity_file); 1298 printf("Saving the key failed: %s.\n", identity_file);
1299 memset(passphrase1, 0, strlen(passphrase1)); 1299 explicit_bzero(passphrase1, strlen(passphrase1));
1300 free(passphrase1); 1300 free(passphrase1);
1301 key_free(private); 1301 key_free(private);
1302 free(comment); 1302 free(comment);
1303 exit(1); 1303 exit(1);
1304 } 1304 }
1305 /* Destroy the passphrase and the copy of the key in memory. */ 1305 /* Destroy the passphrase and the copy of the key in memory. */
1306 memset(passphrase1, 0, strlen(passphrase1)); 1306 explicit_bzero(passphrase1, strlen(passphrase1));
1307 free(passphrase1); 1307 free(passphrase1);
1308 key_free(private); /* Destroys contents */ 1308 key_free(private); /* Destroys contents */
1309 free(comment); 1309 free(comment);
@@ -1375,7 +1375,7 @@ do_change_comment(struct passwd *pw)
1375 /* Try to load using the passphrase. */ 1375 /* Try to load using the passphrase. */
1376 private = key_load_private(identity_file, passphrase, &comment); 1376 private = key_load_private(identity_file, passphrase, &comment);
1377 if (private == NULL) { 1377 if (private == NULL) {
1378 memset(passphrase, 0, strlen(passphrase)); 1378 explicit_bzero(passphrase, strlen(passphrase));
1379 free(passphrase); 1379 free(passphrase);
1380 printf("Bad passphrase.\n"); 1380 printf("Bad passphrase.\n");
1381 exit(1); 1381 exit(1);
@@ -1396,7 +1396,7 @@ do_change_comment(struct passwd *pw)
1396 printf("Enter new comment: "); 1396 printf("Enter new comment: ");
1397 fflush(stdout); 1397 fflush(stdout);
1398 if (!fgets(new_comment, sizeof(new_comment), stdin)) { 1398 if (!fgets(new_comment, sizeof(new_comment), stdin)) {
1399 memset(passphrase, 0, strlen(passphrase)); 1399 explicit_bzero(passphrase, strlen(passphrase));
1400 key_free(private); 1400 key_free(private);
1401 exit(1); 1401 exit(1);
1402 } 1402 }
@@ -1407,13 +1407,13 @@ do_change_comment(struct passwd *pw)
1407 if (!key_save_private(private, identity_file, passphrase, new_comment, 1407 if (!key_save_private(private, identity_file, passphrase, new_comment,
1408 use_new_format, new_format_cipher, rounds)) { 1408 use_new_format, new_format_cipher, rounds)) {
1409 printf("Saving the key failed: %s.\n", identity_file); 1409 printf("Saving the key failed: %s.\n", identity_file);
1410 memset(passphrase, 0, strlen(passphrase)); 1410 explicit_bzero(passphrase, strlen(passphrase));
1411 free(passphrase); 1411 free(passphrase);
1412 key_free(private); 1412 key_free(private);
1413 free(comment); 1413 free(comment);
1414 exit(1); 1414 exit(1);
1415 } 1415 }
1416 memset(passphrase, 0, strlen(passphrase)); 1416 explicit_bzero(passphrase, strlen(passphrase));
1417 free(passphrase); 1417 free(passphrase);
1418 public = key_from_private(private); 1418 public = key_from_private(private);
1419 key_free(private); 1419 key_free(private);
@@ -1716,7 +1716,7 @@ parse_absolute_time(const char *s)
1716 fatal("Invalid certificate time format %s", s); 1716 fatal("Invalid certificate time format %s", s);
1717 } 1717 }
1718 1718
1719 bzero(&tm, sizeof(tm)); 1719 memset(&tm, 0, sizeof(tm));
1720 if (strptime(buf, fmt, &tm) == NULL) 1720 if (strptime(buf, fmt, &tm) == NULL)
1721 fatal("Invalid certificate time %s", s); 1721 fatal("Invalid certificate time %s", s);
1722 if ((tt = mktime(&tm)) < 0) 1722 if ((tt = mktime(&tm)) < 0)
@@ -2196,8 +2196,8 @@ usage(void)
2196 fprintf(stderr, " -v Verbose.\n"); 2196 fprintf(stderr, " -v Verbose.\n");
2197 fprintf(stderr, " -W gen Generator to use for generating DH-GEX moduli.\n"); 2197 fprintf(stderr, " -W gen Generator to use for generating DH-GEX moduli.\n");
2198 fprintf(stderr, " -y Read private key file and print public key.\n"); 2198 fprintf(stderr, " -y Read private key file and print public key.\n");
2199 fprintf(stderr, " -z serial Specify a serial number.\n");
2200 fprintf(stderr, " -Z cipher Specify a cipher for new private key format.\n"); 2199 fprintf(stderr, " -Z cipher Specify a cipher for new private key format.\n");
2200 fprintf(stderr, " -z serial Specify a serial number.\n");
2201 2201
2202 exit(1); 2202 exit(1);
2203} 2203}
@@ -2632,15 +2632,15 @@ passphrase_again:
2632 * The passphrases do not match. Clear them and 2632 * The passphrases do not match. Clear them and
2633 * retry. 2633 * retry.
2634 */ 2634 */
2635 memset(passphrase1, 0, strlen(passphrase1)); 2635 explicit_bzero(passphrase1, strlen(passphrase1));
2636 memset(passphrase2, 0, strlen(passphrase2)); 2636 explicit_bzero(passphrase2, strlen(passphrase2));
2637 free(passphrase1); 2637 free(passphrase1);
2638 free(passphrase2); 2638 free(passphrase2);
2639 printf("Passphrases do not match. Try again.\n"); 2639 printf("Passphrases do not match. Try again.\n");
2640 goto passphrase_again; 2640 goto passphrase_again;
2641 } 2641 }
2642 /* Clear the other copy of the passphrase. */ 2642 /* Clear the other copy of the passphrase. */
2643 memset(passphrase2, 0, strlen(passphrase2)); 2643 explicit_bzero(passphrase2, strlen(passphrase2));
2644 free(passphrase2); 2644 free(passphrase2);
2645 } 2645 }
2646 2646
@@ -2655,12 +2655,12 @@ passphrase_again:
2655 if (!key_save_private(private, identity_file, passphrase1, comment, 2655 if (!key_save_private(private, identity_file, passphrase1, comment,
2656 use_new_format, new_format_cipher, rounds)) { 2656 use_new_format, new_format_cipher, rounds)) {
2657 printf("Saving the key failed: %s.\n", identity_file); 2657 printf("Saving the key failed: %s.\n", identity_file);
2658 memset(passphrase1, 0, strlen(passphrase1)); 2658 explicit_bzero(passphrase1, strlen(passphrase1));
2659 free(passphrase1); 2659 free(passphrase1);
2660 exit(1); 2660 exit(1);
2661 } 2661 }
2662 /* Clear the passphrase. */ 2662 /* Clear the passphrase. */
2663 memset(passphrase1, 0, strlen(passphrase1)); 2663 explicit_bzero(passphrase1, strlen(passphrase1));
2664 free(passphrase1); 2664 free(passphrase1);
2665 2665
2666 /* Clear the private key and the random number generator. */ 2666 /* Clear the private key and the random number generator. */