version 1.13, 1999/11/24 00:26:03 |
version 1.14, 1999/11/24 19:53:52 |
|
|
/* Generated public key. */ |
/* Generated public key. */ |
RSA *public_key; |
RSA *public_key; |
|
|
/* Number of bits in the RSA key. This value can be changed on the command |
/* Number of bits in the RSA key. This value can be changed on the command line. */ |
line. */ |
|
int bits = 1024; |
int bits = 1024; |
|
|
/* Flag indicating that we just want to change the passphrase. This can be |
/* |
set on the command line. */ |
* Flag indicating that we just want to change the passphrase. This can be |
|
* set on the command line. |
|
*/ |
int change_passphrase = 0; |
int change_passphrase = 0; |
|
|
/* Flag indicating that we just want to change the comment. This can be set |
/* |
on the command line. */ |
* Flag indicating that we just want to change the comment. This can be set |
|
* on the command line. |
|
*/ |
int change_comment = 0; |
int change_comment = 0; |
|
|
int quiet = 0; |
int quiet = 0; |
|
|
|
|
if (!have_identity) |
if (!have_identity) |
ask_filename(pw, "Enter file in which the key is"); |
ask_filename(pw, "Enter file in which the key is"); |
/* Check if the file exists. */ |
|
if (stat(identity_file, &st) < 0) { |
if (stat(identity_file, &st) < 0) { |
perror(identity_file); |
perror(identity_file); |
exit(1); |
exit(1); |
} |
} |
/* Try to load the public key from the file the verify that it is |
|
readable and of the proper format. */ |
|
public_key = RSA_new(); |
public_key = RSA_new(); |
if (!load_public_key(identity_file, public_key, NULL)) { |
if (!load_public_key(identity_file, public_key, NULL)) { |
printf("%s is not a valid key file.\n", identity_file); |
printf("%s is not a valid key file.\n", identity_file); |
|
|
/* Try to load the file with empty passphrase. */ |
/* Try to load the file with empty passphrase. */ |
private_key = RSA_new(); |
private_key = RSA_new(); |
if (!load_private_key(identity_file, "", private_key, &comment)) { |
if (!load_private_key(identity_file, "", private_key, &comment)) { |
/* Read passphrase from the user. */ |
|
if (identity_passphrase) |
if (identity_passphrase) |
old_passphrase = xstrdup(identity_passphrase); |
old_passphrase = xstrdup(identity_passphrase); |
else |
else |
old_passphrase = read_passphrase("Enter old passphrase: ", 1); |
old_passphrase = read_passphrase("Enter old passphrase: ", 1); |
/* Try to load using the passphrase. */ |
|
if (!load_private_key(identity_file, old_passphrase, private_key, &comment)) { |
if (!load_private_key(identity_file, old_passphrase, private_key, &comment)) { |
memset(old_passphrase, 0, strlen(old_passphrase)); |
memset(old_passphrase, 0, strlen(old_passphrase)); |
xfree(old_passphrase); |
xfree(old_passphrase); |
printf("Bad passphrase.\n"); |
printf("Bad passphrase.\n"); |
exit(1); |
exit(1); |
} |
} |
/* Destroy the passphrase. */ |
|
memset(old_passphrase, 0, strlen(old_passphrase)); |
memset(old_passphrase, 0, strlen(old_passphrase)); |
xfree(old_passphrase); |
xfree(old_passphrase); |
} |
} |
|
|
|
|
if (!have_identity) |
if (!have_identity) |
ask_filename(pw, "Enter file in which the key is"); |
ask_filename(pw, "Enter file in which the key is"); |
/* Check if the file exists. */ |
|
if (stat(identity_file, &st) < 0) { |
if (stat(identity_file, &st) < 0) { |
perror(identity_file); |
perror(identity_file); |
exit(1); |
exit(1); |
} |
} |
/* Try to load the public key from the file the verify that it is |
/* |
readable and of the proper format. */ |
* Try to load the public key from the file the verify that it is |
|
* readable and of the proper format. |
|
*/ |
public_key = RSA_new(); |
public_key = RSA_new(); |
if (!load_public_key(identity_file, public_key, NULL)) { |
if (!load_public_key(identity_file, public_key, NULL)) { |
printf("%s is not a valid key file.\n", identity_file); |
printf("%s is not a valid key file.\n", identity_file); |
exit(1); |
exit(1); |
} |
} |
private_key = RSA_new(); |
private_key = RSA_new(); |
/* Try to load the file with empty passphrase. */ |
|
if (load_private_key(identity_file, "", private_key, &comment)) |
if (load_private_key(identity_file, "", private_key, &comment)) |
passphrase = xstrdup(""); |
passphrase = xstrdup(""); |
else { |
else { |
/* Read passphrase from the user. */ |
|
if (identity_passphrase) |
if (identity_passphrase) |
passphrase = xstrdup(identity_passphrase); |
passphrase = xstrdup(identity_passphrase); |
else if (identity_new_passphrase) |
else if (identity_new_passphrase) |
|
|
RSA_free(private_key); |
RSA_free(private_key); |
exit(1); |
exit(1); |
} |
} |
/* Remove terminating newline from comment. */ |
|
if (strchr(new_comment, '\n')) |
if (strchr(new_comment, '\n')) |
*strchr(new_comment, '\n') = 0; |
*strchr(new_comment, '\n') = 0; |
} |
} |
|
|
xfree(comment); |
xfree(comment); |
exit(1); |
exit(1); |
} |
} |
/* Destroy the passphrase and the private key in memory. */ |
|
memset(passphrase, 0, strlen(passphrase)); |
memset(passphrase, 0, strlen(passphrase)); |
xfree(passphrase); |
xfree(passphrase); |
RSA_free(private_key); |
RSA_free(private_key); |
|
|
/* Save the public key in text format in a file with the same name |
|
but .pub appended. */ |
|
strlcat(identity_file, ".pub", sizeof(identity_file)); |
strlcat(identity_file, ".pub", sizeof(identity_file)); |
f = fopen(identity_file, "w"); |
f = fopen(identity_file, "w"); |
if (!f) { |
if (!f) { |
|
|
|
|
/* check if RSA support exists */ |
/* check if RSA support exists */ |
if (rsa_alive() == 0) { |
if (rsa_alive() == 0) { |
extern char *__progname; |
|
|
|
fprintf(stderr, |
fprintf(stderr, |
"%s: no RSA support in libssl and libcrypto. See ssl(8).\n", |
"%s: no RSA support in libssl and libcrypto. See ssl(8).\n", |
__progname); |
__progname); |
exit(1); |
exit(1); |
} |
} |
/* Get user\'s passwd structure. We need this for the home |
/* we need this for the home * directory. */ |
directory. */ |
|
pw = getpwuid(getuid()); |
pw = getpwuid(getuid()); |
if (!pw) { |
if (!pw) { |
printf("You don't exist, go away!\n"); |
printf("You don't exist, go away!\n"); |
exit(1); |
exit(1); |
} |
} |
/* Parse command line arguments. */ |
|
while ((opt = getopt(ac, av, "qpclb:f:P:N:C:")) != EOF) { |
while ((opt = getopt(ac, av, "qpclb:f:P:N:C:")) != EOF) { |
switch (opt) { |
switch (opt) { |
case 'b': |
case 'b': |
|
|
} |
} |
if (print_fingerprint) |
if (print_fingerprint) |
do_fingerprint(pw); |
do_fingerprint(pw); |
|
|
/* If the user requested to change the passphrase, do it now. |
|
This function never returns. */ |
|
if (change_passphrase) |
if (change_passphrase) |
do_change_passphrase(pw); |
do_change_passphrase(pw); |
|
|
/* If the user requested to change the comment, do it now. This |
|
function never returns. */ |
|
if (change_comment) |
if (change_comment) |
do_change_comment(pw); |
do_change_comment(pw); |
|
|
|
|
xfree(passphrase2); |
xfree(passphrase2); |
} |
} |
|
|
/* Create default commend field for the passphrase. The user can |
|
later edit this field. */ |
|
if (identity_comment) { |
if (identity_comment) { |
strlcpy(comment, identity_comment, sizeof(comment)); |
strlcpy(comment, identity_comment, sizeof(comment)); |
} else { |
} else { |
|
/* Create default commend field for the passphrase. */ |
if (gethostname(hostname, sizeof(hostname)) < 0) { |
if (gethostname(hostname, sizeof(hostname)) < 0) { |
perror("gethostname"); |
perror("gethostname"); |
exit(1); |
exit(1); |
|
|
if (!quiet) |
if (!quiet) |
printf("Your identification has been saved in %s.\n", identity_file); |
printf("Your identification has been saved in %s.\n", identity_file); |
|
|
/* Save the public key in text format in a file with the same name |
|
but .pub appended. */ |
|
strlcat(identity_file, ".pub", sizeof(identity_file)); |
strlcat(identity_file, ".pub", sizeof(identity_file)); |
f = fopen(identity_file, "w"); |
f = fopen(identity_file, "w"); |
if (!f) { |
if (!f) { |