Skip to content

Commit a856553

Browse files
committed
Fix various certificate fingerprint issues.
By using non-DER or invalid encodings outside the signed portion of a certificate the fingerprint can be changed without breaking the signature. Although no details of the signed portion of the certificate can be changed this can cause problems with some applications: e.g. those using the certificate fingerprint for blacklists. 1. Reject signatures with non zero unused bits. If the BIT STRING containing the signature has non zero unused bits reject the signature. All current signature algorithms require zero unused bits. 2. Check certificate algorithm consistency. Check the AlgorithmIdentifier inside TBS matches the one in the certificate signature. NB: this will result in signature failure errors for some broken certificates. 3. Check DSA/ECDSA signatures use DER. Reencode DSA/ECDSA signatures and compare with the original received signature. Return an error if there is a mismatch. This will reject various cases including garbage after signature (thanks to Antti Karjalainen and Tuomo Untinen from the Codenomicon CROSS program for discovering this case) and use of BER or invalid ASN.1 INTEGERs (negative or with leading zeroes). CVE-2014-8275 Reviewed-by: Emilia Käsper <emilia@openssl.org> (cherry picked from commit 684400c)
1 parent 9e9ee7e commit a856553

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

CHANGES

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,43 @@
44

55
Changes between 1.0.1j and 1.0.1k [xx XXX xxxx]
66

7+
*) Fix various certificate fingerprint issues.
8+
9+
By using non-DER or invalid encodings outside the signed portion of a
10+
certificate the fingerprint can be changed without breaking the signature.
11+
Although no details of the signed portion of the certificate can be changed
12+
this can cause problems with some applications: e.g. those using the
13+
certificate fingerprint for blacklists.
14+
15+
1. Reject signatures with non zero unused bits.
16+
17+
If the BIT STRING containing the signature has non zero unused bits reject
18+
the signature. All current signature algorithms require zero unused bits.
19+
20+
2. Check certificate algorithm consistency.
21+
22+
Check the AlgorithmIdentifier inside TBS matches the one in the
23+
certificate signature. NB: this will result in signature failure
24+
errors for some broken certificates.
25+
26+
Thanks to Konrad Kraszewski from Google for reporting this issue.
27+
28+
3. Check DSA/ECDSA signatures use DER.
29+
30+
Reencode DSA/ECDSA signatures and compare with the original received
31+
signature. Return an error if there is a mismatch.
32+
33+
This will reject various cases including garbage after signature
34+
(thanks to Antti Karjalainen and Tuomo Untinen from the Codenomicon CROSS
35+
program for discovering this case) and use of BER or invalid ASN.1 INTEGERs
36+
(negative or with leading zeroes).
37+
38+
Further analysis was conducted and fixes were developed by Stephen Henson
39+
of the OpenSSL core team.
40+
41+
(CVE-2014-8275)
42+
[Steve Henson]
43+
744
*) Do not resume sessions on the server if the negotiated protocol
845
version does not match the session's version. Resuming with a different
946
version, while not strictly forbidden by the RFC, is of questionable

crypto/asn1/a_verify.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
9090
ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
9191
goto err;
9292
}
93+
94+
if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)
95+
{
96+
ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
97+
goto err;
98+
}
9399

94100
inl=i2d(data,NULL);
95101
buf_in=OPENSSL_malloc((unsigned int)inl);
@@ -146,6 +152,12 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
146152
return -1;
147153
}
148154

155+
if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)
156+
{
157+
ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
158+
return -1;
159+
}
160+
149161
EVP_MD_CTX_init(&ctx);
150162

151163
/* Convert signature OID into digest and public key OIDs */

crypto/dsa/dsa_asn1.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,25 @@ int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
176176
const unsigned char *sigbuf, int siglen, DSA *dsa)
177177
{
178178
DSA_SIG *s;
179+
const unsigned char *p = sigbuf;
180+
unsigned char *der = NULL;
181+
int derlen = -1;
179182
int ret=-1;
180183

181184
s = DSA_SIG_new();
182185
if (s == NULL) return(ret);
183-
if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
186+
if (d2i_DSA_SIG(&s,&p,siglen) == NULL) goto err;
187+
/* Ensure signature uses DER and doesn't have trailing garbage */
188+
derlen = i2d_DSA_SIG(s, &der);
189+
if (derlen != siglen || memcmp(sigbuf, der, derlen))
190+
goto err;
184191
ret=DSA_do_verify(dgst,dgst_len,s,dsa);
185192
err:
193+
if (derlen > 0)
194+
{
195+
OPENSSL_cleanse(der, derlen);
196+
OPENSSL_free(der);
197+
}
186198
DSA_SIG_free(s);
187199
return(ret);
188200
}

crypto/ecdsa/ecs_vrf.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
*/
5858

5959
#include "ecs_locl.h"
60+
#include "cryptlib.h"
6061
#ifndef OPENSSL_NO_ENGINE
6162
#include <openssl/engine.h>
6263
#endif
@@ -84,13 +85,25 @@ int ECDSA_verify(int type, const unsigned char *dgst, int dgst_len,
8485
const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
8586
{
8687
ECDSA_SIG *s;
88+
const unsigned char *p = sigbuf;
89+
unsigned char *der = NULL;
90+
int derlen = -1;
8791
int ret=-1;
8892

8993
s = ECDSA_SIG_new();
9094
if (s == NULL) return(ret);
91-
if (d2i_ECDSA_SIG(&s, &sigbuf, sig_len) == NULL) goto err;
95+
if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL) goto err;
96+
/* Ensure signature uses DER and doesn't have trailing garbage */
97+
derlen = i2d_ECDSA_SIG(s, &der);
98+
if (derlen != sig_len || memcmp(sigbuf, der, derlen))
99+
goto err;
92100
ret=ECDSA_do_verify(dgst, dgst_len, s, eckey);
93101
err:
102+
if (derlen > 0)
103+
{
104+
OPENSSL_cleanse(der, derlen);
105+
OPENSSL_free(der);
106+
}
94107
ECDSA_SIG_free(s);
95108
return(ret);
96109
}

crypto/x509/x_all.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272

7373
int X509_verify(X509 *a, EVP_PKEY *r)
7474
{
75+
if (X509_ALGOR_cmp(a->sig_alg, a->cert_info->signature))
76+
return 0;
7577
return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg,
7678
a->signature,a->cert_info,r));
7779
}

0 commit comments

Comments
 (0)