X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/b81cca98c2709d60a25ec96b0871d26b62e35d0a..aca589d972c5c12706d57322e89f9dec2b2a3a00:/cmdgen.c diff --git a/cmdgen.c b/cmdgen.c index 2f0fdc1d..5042aa4e 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -602,21 +602,19 @@ int main(int argc, char **argv) if (keytype != NOKEYGEN) { char *entropy; char default_comment[80]; - time_t t; - struct tm *tm; + struct tm tm; struct progress prog; prog.phase = -1; prog.current = -1; - time(&t); - tm = localtime(&t); + tm = ltime(); if (keytype == DSA) - strftime(default_comment, 30, "dsa-key-%Y%m%d", tm); + strftime(default_comment, 30, "dsa-key-%Y%m%d", &tm); else - strftime(default_comment, 30, "rsa-key-%Y%m%d", tm); + strftime(default_comment, 30, "rsa-key-%Y%m%d", &tm); - random_init(); + random_ref(); entropy = get_random_data(bits / 8); random_add_heavynoise(entropy, bits / 8); memset(entropy, 0, bits/8); @@ -686,14 +684,26 @@ int main(int argc, char **argv) if (!load_encrypted) { void *vblob; char *blob; - int n, bloblen; + int n, l, bloblen; ret = rsakey_pubblob(&infilename, &vblob, &bloblen, &error); blob = (char *)vblob; n = 4; /* skip modulus bits */ - n += ssh1_read_bignum(blob + n, &ssh1key->exponent); - n += ssh1_read_bignum(blob + n, &ssh1key->modulus); + + l = ssh1_read_bignum(blob + n, bloblen - n, + &ssh1key->exponent); + if (l < 0) { + error = "SSH1 public key blob was too short"; + } else { + n += l; + l = ssh1_read_bignum(blob + n, bloblen - n, + &ssh1key->modulus); + if (l < 0) { + error = "SSH1 public key blob was too short"; + } else + n += l; + } ssh1key->comment = NULL; ssh1key->private_exponent = NULL; } else { @@ -730,7 +740,7 @@ int main(int argc, char **argv) case SSH_KEYTYPE_OPENSSH: case SSH_KEYTYPE_SSHCOM: ssh2key = import_ssh2(&infilename, intype, passphrase); - if (ssh2key) + if (ssh2key && ssh2key != SSH2_WRONG_PASSPHRASE) error = NULL; else if (!error) { if (ssh2key == SSH2_WRONG_PASSPHRASE)