diff options
author | Ben Lindstrom <mouring@eviladmin.org> | 2002-06-06 20:55:04 +0000 |
---|---|---|
committer | Ben Lindstrom <mouring@eviladmin.org> | 2002-06-06 20:55:04 +0000 |
commit | ceae9d1c333c24894cccddc861c1b9b6d208a8bc (patch) | |
tree | b6c428a9f721579f0379cc1aa5f6768aaedcf3cc /ssh-rsa.c | |
parent | 01fff0c9d4f64d13e02ea6d516b5a335a35d00dd (diff) |
- markus@cvs.openbsd.org 2002/05/31 13:20:50
[ssh-rsa.c]
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
Diffstat (limited to 'ssh-rsa.c')
-rw-r--r-- | ssh-rsa.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -23,7 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | RCSID("$OpenBSD: ssh-rsa.c,v 1.18 2002/04/02 20:11:38 markus Exp $"); | 26 | RCSID("$OpenBSD: ssh-rsa.c,v 1.19 2002/05/31 13:20:50 markus Exp $"); |
27 | 27 | ||
28 | #include <openssl/evp.h> | 28 | #include <openssl/evp.h> |
29 | #include <openssl/err.h> | 29 | #include <openssl/err.h> |
@@ -115,7 +115,7 @@ ssh_rsa_verify( | |||
115 | EVP_MD_CTX md; | 115 | EVP_MD_CTX md; |
116 | char *ktype; | 116 | char *ktype; |
117 | u_char digest[EVP_MAX_MD_SIZE], *sigblob; | 117 | u_char digest[EVP_MAX_MD_SIZE], *sigblob; |
118 | u_int len, dlen; | 118 | u_int len, dlen, modlen; |
119 | int rlen, ret, nid; | 119 | int rlen, ret, nid; |
120 | 120 | ||
121 | if (key == NULL || key->type != KEY_RSA || key->rsa == NULL) { | 121 | if (key == NULL || key->type != KEY_RSA || key->rsa == NULL) { |
@@ -145,6 +145,21 @@ ssh_rsa_verify( | |||
145 | xfree(sigblob); | 145 | xfree(sigblob); |
146 | return -1; | 146 | return -1; |
147 | } | 147 | } |
148 | /* RSA_verify expects a signature of RSA_size */ | ||
149 | modlen = RSA_size(key->rsa); | ||
150 | if (len > modlen) { | ||
151 | error("ssh_rsa_verify: len %d > modlen %d", len, modlen); | ||
152 | xfree(sigblob); | ||
153 | return -1; | ||
154 | } else if (len < modlen) { | ||
155 | int diff = modlen - len; | ||
156 | debug("ssh_rsa_verify: add padding: modlen %d > len %d", | ||
157 | modlen, len); | ||
158 | sigblob = xrealloc(sigblob, modlen); | ||
159 | memmove(sigblob + diff, sigblob, len); | ||
160 | memset(sigblob, 0, diff); | ||
161 | len = modlen; | ||
162 | } | ||
148 | nid = (datafellows & SSH_BUG_RSASIGMD5) ? NID_md5 : NID_sha1; | 163 | nid = (datafellows & SSH_BUG_RSASIGMD5) ? NID_md5 : NID_sha1; |
149 | if ((evp_md = EVP_get_digestbynid(nid)) == NULL) { | 164 | if ((evp_md = EVP_get_digestbynid(nid)) == NULL) { |
150 | error("ssh_rsa_verify: EVP_get_digestbynid %d failed", nid); | 165 | error("ssh_rsa_verify: EVP_get_digestbynid %d failed", nid); |