From 6e3c47cb9cf52992ff76e7e9795ea37fe6a884db Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 22 Feb 2013 21:39:02 +0000 Subject: [PATCH] Give a better error message if a PuTTY private key file has a version number we don't understand. It's nicer to report 'format too new' than 'not a PuTTY key file'. git-svn-id: svn://svn.tartarus.org/sgt/putty@9763 cda61777-01e9-0310-a592-d414129be87e --- cmdgen.c | 12 +++++++----- sshpubk.c | 10 +++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmdgen.c b/cmdgen.c index 254ae6a7..33662c3b 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -779,11 +779,13 @@ int main(int argc, char **argv) if (!load_encrypted) { ssh2blob = ssh2_userkey_loadpub(infilename, &ssh2alg, &ssh2bloblen, NULL, &error); - ssh2algf = find_pubkey_alg(ssh2alg); - if (ssh2algf) - bits = ssh2algf->pubkey_bits(ssh2blob, ssh2bloblen); - else - bits = -1; + if (ssh2blob) { + ssh2algf = find_pubkey_alg(ssh2alg); + if (ssh2algf) + bits = ssh2algf->pubkey_bits(ssh2blob, ssh2bloblen); + else + bits = -1; + } } else { ssh2key = ssh2_load_userkey(infilename, passphrase, &error); } diff --git a/sshpubk.c b/sshpubk.c index c29d8a58..76aa3436 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -647,6 +647,11 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename, /* this is an old key file; warn and then continue */ old_keyfile_warning(); old_fmt = 1; + } else if (0 == strncmp(header, "PuTTY-User-Key-File-", 20)) { + /* this is a key file FROM THE FUTURE; refuse it, but with a + * more specific error message than the generic one below */ + error = "PuTTY key format too new"; + goto error; } else { error = "not a PuTTY SSH-2 private key"; goto error; @@ -891,7 +896,10 @@ unsigned char *ssh2_userkey_loadpub(const Filename *filename, char **algorithm, if (!read_header(fp, header) || (0 != strcmp(header, "PuTTY-User-Key-File-2") && 0 != strcmp(header, "PuTTY-User-Key-File-1"))) { - error = "not a PuTTY SSH-2 private key"; + if (0 == strncmp(header, "PuTTY-User-Key-File-", 20)) + error = "PuTTY key format too new"; + else + error = "not a PuTTY SSH-2 private key"; goto error; } error = "file format error"; -- 2.11.0