summaryrefslogtreecommitdiffstats
path: root/crypto/rsa/rsa_sign.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2014-09-25 23:28:48 +0100
committerDr. Stephen Henson <steve@openssl.org>2014-09-29 12:01:05 +0100
commit1cfd255c9123cdb4637cc9a65c6665fe4a06c6d5 (patch)
tree86e26adccb01a6f970de107123649ea51c055d91 /crypto/rsa/rsa_sign.c
parent3d81ec5b92e1141762eb72caf2aeb9b2cd019a78 (diff)
Add additional DigestInfo checks.
Reencode DigestInto in DER and check against the original: this will reject any improperly encoded DigestInfo structures. Note: this is a precautionary measure, there is no known attack which can exploit this. Thanks to Brian Smith for reporting this issue. Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'crypto/rsa/rsa_sign.c')
-rw-r--r--crypto/rsa/rsa_sign.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/crypto/rsa/rsa_sign.c b/crypto/rsa/rsa_sign.c
index fa3239ab30..748292550d 100644
--- a/crypto/rsa/rsa_sign.c
+++ b/crypto/rsa/rsa_sign.c
@@ -143,6 +143,25 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
return(ret);
}
+/*
+ * Check DigestInfo structure does not contain extraneous data by reencoding
+ * using DER and checking encoding against original.
+ */
+static int rsa_check_digestinfo(X509_SIG *sig, const unsigned char *dinfo, int dinfolen)
+ {
+ unsigned char *der = NULL;
+ int derlen;
+ int ret = 0;
+ derlen = i2d_X509_SIG(sig, &der);
+ if (derlen <= 0)
+ return 0;
+ if (derlen == dinfolen && !memcmp(dinfo, der, derlen))
+ ret = 1;
+ OPENSSL_cleanse(der, derlen);
+ OPENSSL_free(der);
+ return ret;
+ }
+
int int_rsa_verify(int dtype, const unsigned char *m,
unsigned int m_len,
unsigned char *rm, size_t *prm_len,
@@ -211,7 +230,7 @@ int int_rsa_verify(int dtype, const unsigned char *m,
if (sig == NULL) goto err;
/* Excess data can be used to create forgeries */
- if(p != s+i)
+ if(p != s+i || !rsa_check_digestinfo(sig, s, i))
{
RSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
goto err;