From 681c6d45b4720a6eafd6726877f0522ff12717a9 Mon Sep 17 00:00:00 2001 From: Markus Friedl Date: Fri, 31 May 2002 13:20:51 +0000 Subject: pad received signature with leading zeros, because RSA_verify expects a signature of RSA_size. the drafts says the signature is transmitted unpadded (e.g. putty does not pad), reported by anakin@pobox.com --- usr.bin/ssh/ssh-rsa.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/usr.bin/ssh/ssh-rsa.c b/usr.bin/ssh/ssh-rsa.c index fe4dc1f8dff..458c9c840ef 100644 --- a/usr.bin/ssh/ssh-rsa.c +++ b/usr.bin/ssh/ssh-rsa.c @@ -23,7 +23,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-rsa.c,v 1.18 2002/04/02 20:11:38 markus Exp $"); +RCSID("$OpenBSD: ssh-rsa.c,v 1.19 2002/05/31 13:20:50 markus Exp $"); #include #include @@ -115,7 +115,7 @@ ssh_rsa_verify( EVP_MD_CTX md; char *ktype; u_char digest[EVP_MAX_MD_SIZE], *sigblob; - u_int len, dlen; + u_int len, dlen, modlen; int rlen, ret, nid; if (key == NULL || key->type != KEY_RSA || key->rsa == NULL) { @@ -145,6 +145,21 @@ ssh_rsa_verify( xfree(sigblob); return -1; } + /* RSA_verify expects a signature of RSA_size */ + modlen = RSA_size(key->rsa); + if (len > modlen) { + error("ssh_rsa_verify: len %d > modlen %d", len, modlen); + xfree(sigblob); + return -1; + } else if (len < modlen) { + int diff = modlen - len; + debug("ssh_rsa_verify: add padding: modlen %d > len %d", + modlen, len); + sigblob = xrealloc(sigblob, modlen); + memmove(sigblob + diff, sigblob, len); + memset(sigblob, 0, diff); + len = modlen; + } nid = (datafellows & SSH_BUG_RSASIGMD5) ? NID_md5 : NID_sha1; if ((evp_md = EVP_get_digestbynid(nid)) == NULL) { error("ssh_rsa_verify: EVP_get_digestbynid %d failed", nid); -- cgit v1.2.3