Properly check EVP_VerifyFinal() and similar return values
authorDr. Stephen Henson <steve@openssl.org>
Wed, 7 Jan 2009 10:48:23 +0000 (10:48 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 7 Jan 2009 10:48:23 +0000 (10:48 +0000)
(CVE-2008-5077).
Submitted by: Ben Laurie, Bodo Moeller, Google Security Team

CHANGES
apps/speed.c
apps/spkac.c
apps/verify.c
apps/x509.c
crypto/cms/cms_sd.c
ssl/s2_clnt.c
ssl/s2_srvr.c
ssl/s3_clnt.c
ssl/s3_srvr.c
ssl/ssltest.c

diff --git a/CHANGES b/CHANGES
index f02a6d356a0adae2c1922f4b8788b520b4b6353d..006d2fea549f53bde937414fe43fdc18dc4da9c8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,10 @@
 
  Changes between 0.9.8i and 0.9.8j  [xx XXX xxxx]
 
+  *) Properly check EVP_VerifyFinal() and similar return values
+     (CVE-2008-5077).
+     [Ben Laurie, Bodo Moeller, Google Security Team]
+
   *) Enable TLS extensions by default.
      [Ben Laurie]
 
index e6b187d840d5932cb6ea2cb623aa14efbf867bac..af077b54a86b998bd243ba62e74de39911a61756 100644 (file)
@@ -2132,7 +2132,7 @@ int MAIN(int argc, char **argv)
                                {
                                ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
                                        rsa_num, rsa_key[j]);
-                               if (ret == 0)
+                               if (ret <= 0)
                                        {
                                        BIO_printf(bio_err,
                                                "RSA verify failure\n");
index ae2d88694f5257805513acb29cc8cb456b040c25..0e01ea9947dae0c3ce0bcf69c4ec70fc365909c1 100644 (file)
@@ -285,7 +285,7 @@ bad:
        pkey = NETSCAPE_SPKI_get_pubkey(spki);
        if(verify) {
                i = NETSCAPE_SPKI_verify(spki, pkey);
-               if(i) BIO_printf(bio_err, "Signature OK\n");
+               if (i > 0) BIO_printf(bio_err, "Signature OK\n");
                else {
                        BIO_printf(bio_err, "Signature Failure\n");
                        ERR_print_errors(bio_err);
index 9ff32cb06832162f6ea32e1055c8941a7a4c534c..20cc9e354cd3c1934d4c4036c1ad68f8fc4e453f 100644 (file)
@@ -266,7 +266,7 @@ static int check(X509_STORE *ctx, char *file, STACK_OF(X509) *uchain, STACK_OF(X
 
        ret=0;
 end:
-       if (i)
+       if (i > 0)
                {
                fprintf(stdout,"OK\n");
                ret=1;
@@ -367,4 +367,3 @@ static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx)
                ERR_clear_error();
        return(ok);
        }
-
index f6938356f8a7acd5f0b655ab24788588fb39e1e8..d904d3402187d30a98398f7e21964661af4a290d 100644 (file)
@@ -1151,7 +1151,7 @@ static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
        /* NOTE: this certificate can/should be self signed, unless it was
         * a certificate request in which case it is not. */
        X509_STORE_CTX_set_cert(&xsc,x);
-       if (!reqfile && !X509_verify_cert(&xsc))
+       if (!reqfile && X509_verify_cert(&xsc) <= 0)
                goto end;
 
        if (!X509_check_private_key(xca,pkey))
index 591bfbec33b22c1ffcb0a02a3d0e0da74804c0bc..cdac3b870dd922aea7a1d8235f07e8f031383aab 100644 (file)
@@ -830,7 +830,7 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
        cms_fixup_mctx(&mctx, si->pkey);
        r = EVP_VerifyFinal(&mctx,
                        si->signature->data, si->signature->length, si->pkey);
-       if (!r)
+       if (r <= 0)
                CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY, CMS_R_VERIFICATION_FAILURE);
        err:
        EVP_MD_CTX_cleanup(&mctx);
index e2a90a3ca26b923b5045e8844d351c963d12fb28..782129cd5d51f334a914f1c2647970641b8992c5 100644 (file)
@@ -1044,7 +1044,7 @@ int ssl2_set_certificate(SSL *s, int type, int len, const unsigned char *data)
 
        i=ssl_verify_cert_chain(s,sk);
                
-       if ((s->verify_mode != SSL_VERIFY_NONE) && (!i))
+       if ((s->verify_mode != SSL_VERIFY_NONE) && (i <= 0))
                {
                SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
                goto err;
index 0daf2b129df3cc36785ad51975cab60a338e08a9..50d55e6bf14cb45bbb60b1c1ef19f32d1ee5464d 100644 (file)
@@ -1054,7 +1054,7 @@ static int request_certificate(SSL *s)
 
        i=ssl_verify_cert_chain(s,sk);
 
-       if (i)  /* we like the packet, now check the chksum */
+       if (i > 0)      /* we like the packet, now check the chksum */
                {
                EVP_MD_CTX ctx;
                EVP_PKEY *pkey=NULL;
@@ -1083,7 +1083,7 @@ static int request_certificate(SSL *s)
                EVP_PKEY_free(pkey);
                EVP_MD_CTX_cleanup(&ctx);
 
-               if (i
+               if (i > 0)
                        {
                        if (s->session->peer != NULL)
                                X509_free(s->session->peer);
index 837507cce1b41289e3faa653ddef835c371cc8d5..5fd3520caf4c0cb3ec96c9ab3762fe6e360ab1ed 100644 (file)
@@ -972,7 +972,7 @@ int ssl3_get_server_certificate(SSL *s)
                }
 
        i=ssl_verify_cert_chain(s,sk);
-       if ((s->verify_mode != SSL_VERIFY_NONE) && (!i)
+       if ((s->verify_mode != SSL_VERIFY_NONE) && (i <= 0)
 #ifndef OPENSSL_NO_KRB5
                && (s->s3->tmp.new_cipher->algorithms & (SSL_MKEY_MASK|SSL_AUTH_MASK))
                != (SSL_aKRB5|SSL_kKRB5)
@@ -1459,7 +1459,7 @@ int ssl3_get_key_exchange(SSL *s)
                        EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
                        EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
                        EVP_VerifyUpdate(&md_ctx,param,param_len);
-                       if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))
+                       if (EVP_VerifyFinal(&md_ctx,p,(int)n,pkey) <= 0)
                                {
                                /* bad signature */
                                al=SSL_AD_DECRYPT_ERROR;
@@ -1477,7 +1477,7 @@ int ssl3_get_key_exchange(SSL *s)
                        EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
                        EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
                        EVP_VerifyUpdate(&md_ctx,param,param_len);
-                       if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))
+                       if (EVP_VerifyFinal(&md_ctx,p,(int)n,pkey) <= 0)
                                {
                                /* bad signature */
                                al=SSL_AD_DECRYPT_ERROR;
index 04f9f79ab2a4443be2eecca8051a40cb6a390aba..80b45eb86ff1aeb79ddf8d623019e3e89279f8da 100644 (file)
@@ -2566,7 +2566,7 @@ int ssl3_get_client_certificate(SSL *s)
        else
                {
                i=ssl_verify_cert_chain(s,sk);
-               if (!i)
+               if (i <= 0)
                        {
                        al=ssl_verify_alarm_type(s->verify_result);
                        SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED);
index 82086d1718e0d042193658d28aaf9fbb2e51a3e7..b09c542087ba9afe42cdc9ff5c0c09aa25731544 100644 (file)
@@ -2093,7 +2093,7 @@ static int MS_CALLBACK app_verify_callback(X509_STORE_CTX *ctx, void *arg)
 
        if (cb_arg->proxy_auth)
                {
-               if (ok)
+               if (ok > 0)
                        {
                        const char *cond_end = NULL;