version 1.398, 2020/02/07 03:27:54 |
version 1.399, 2020/02/26 13:40:09 |
|
|
else |
else |
pass = read_passphrase("Enter passphrase: ", RP_ALLOW_STDIN); |
pass = read_passphrase("Enter passphrase: ", RP_ALLOW_STDIN); |
r = sshkey_load_private(filename, pass, &prv, commentp); |
r = sshkey_load_private(filename, pass, &prv, commentp); |
explicit_bzero(pass, strlen(pass)); |
freezero(pass, strlen(pass)); |
free(pass); |
|
if (r != 0) |
if (r != 0) |
fatal("Load key \"%s\": %s", filename, ssh_err(r)); |
fatal("Load key \"%s\": %s", filename, ssh_err(r)); |
return prv; |
return prv; |
|
|
RP_ALLOW_STDIN); |
RP_ALLOW_STDIN); |
r = sshkey_load_private(identity_file, old_passphrase, |
r = sshkey_load_private(identity_file, old_passphrase, |
&private, &comment); |
&private, &comment); |
explicit_bzero(old_passphrase, strlen(old_passphrase)); |
freezero(old_passphrase, strlen(old_passphrase)); |
free(old_passphrase); |
|
if (r != 0) |
if (r != 0) |
goto badkey; |
goto badkey; |
} else if (r != 0) { |
} else if (r != 0) { |
|
|
exit(1); |
exit(1); |
} |
} |
/* Destroy the other copy. */ |
/* Destroy the other copy. */ |
explicit_bzero(passphrase2, strlen(passphrase2)); |
freezero(passphrase2, strlen(passphrase2)); |
free(passphrase2); |
|
} |
} |
|
|
/* Save the file using the new passphrase. */ |
/* Save the file using the new passphrase. */ |
|
|
comment, private_key_format, openssh_format_cipher, rounds)) != 0) { |
comment, private_key_format, openssh_format_cipher, rounds)) != 0) { |
error("Saving key \"%s\" failed: %s.", |
error("Saving key \"%s\" failed: %s.", |
identity_file, ssh_err(r)); |
identity_file, ssh_err(r)); |
explicit_bzero(passphrase1, strlen(passphrase1)); |
freezero(passphrase1, strlen(passphrase1)); |
free(passphrase1); |
|
sshkey_free(private); |
sshkey_free(private); |
free(comment); |
free(comment); |
exit(1); |
exit(1); |
} |
} |
/* Destroy the passphrase and the copy of the key in memory. */ |
/* Destroy the passphrase and the copy of the key in memory. */ |
explicit_bzero(passphrase1, strlen(passphrase1)); |
freezero(passphrase1, strlen(passphrase1)); |
free(passphrase1); |
|
sshkey_free(private); /* Destroys contents */ |
sshkey_free(private); /* Destroys contents */ |
free(comment); |
free(comment); |
|
|
|
|
/* Try to load using the passphrase. */ |
/* Try to load using the passphrase. */ |
if ((r = sshkey_load_private(identity_file, passphrase, |
if ((r = sshkey_load_private(identity_file, passphrase, |
&private, &comment)) != 0) { |
&private, &comment)) != 0) { |
explicit_bzero(passphrase, strlen(passphrase)); |
freezero(passphrase, strlen(passphrase)); |
free(passphrase); |
|
fatal("Cannot load private key \"%s\": %s.", |
fatal("Cannot load private key \"%s\": %s.", |
identity_file, ssh_err(r)); |
identity_file, ssh_err(r)); |
} |
} |
|
|
rounds)) != 0) { |
rounds)) != 0) { |
error("Saving key \"%s\" failed: %s", |
error("Saving key \"%s\" failed: %s", |
identity_file, ssh_err(r)); |
identity_file, ssh_err(r)); |
explicit_bzero(passphrase, strlen(passphrase)); |
freezero(passphrase, strlen(passphrase)); |
free(passphrase); |
|
sshkey_free(private); |
sshkey_free(private); |
free(comment); |
free(comment); |
exit(1); |
exit(1); |
} |
} |
explicit_bzero(passphrase, strlen(passphrase)); |
freezero(passphrase, strlen(passphrase)); |
free(passphrase); |
|
if ((r = sshkey_from_private(private, &public)) != 0) |
if ((r = sshkey_from_private(private, &public)) != 0) |
fatal("sshkey_from_private failed: %s", ssh_err(r)); |
fatal("sshkey_from_private failed: %s", ssh_err(r)); |
sshkey_free(private); |
sshkey_free(private); |