Apply by doing: cd /usr/src patch -p0 < 002_openssl.patch And then rebuild and install OpenSSL: cd lib/libssl make obj make depend make includes make make install Index: lib/libssl/src/crypto/asn1/tasn_dec.c =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/asn1/tasn_dec.c,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -p -r1.5 -r1.5.2.1 --- lib/libssl/src/crypto/asn1/tasn_dec.c 27 Jun 2006 05:07:00 -0000 1.5 +++ lib/libssl/src/crypto/asn1/tasn_dec.c 2 Nov 2006 19:56:23 -0000 1.5.2.1 @@ -629,6 +629,8 @@ static int asn1_d2i_ex_primitive(ASN1_VA ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); return 0; } else if(ret == -1) return -1; + + ret = 0; /* SEQUENCE, SET and "OTHER" are left in encoded form */ if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) { /* Clear context cache for type OTHER because the auto clear when Index: lib/libssl/src/crypto/dh/dh.h =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/dh/dh.h,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -u -p -r1.7 -r1.7.2.1 --- lib/libssl/src/crypto/dh/dh.h 27 Jun 2006 05:07:01 -0000 1.7 +++ lib/libssl/src/crypto/dh/dh.h 2 Nov 2006 19:56:23 -0000 1.7.2.1 @@ -70,6 +70,8 @@ #include #include +#define OPENSSL_DH_MAX_MODULUS_BITS 10000 + #define DH_FLAG_CACHE_MONT_P 0x01 #define DH_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DH * implementation now uses constant time @@ -213,6 +215,7 @@ void ERR_load_DH_strings(void); #define DH_R_BAD_GENERATOR 101 #define DH_R_NO_PRIVATE_VALUE 100 #define DH_R_INVALID_PUBKEY 102 +#define DH_R_MODULUS_TOO_LARGE 103 #ifdef __cplusplus } Index: lib/libssl/src/crypto/dh/dh_err.c =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/dh/dh_err.c,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -u -p -r1.7 -r1.7.2.1 --- lib/libssl/src/crypto/dh/dh_err.c 27 Jun 2006 05:07:01 -0000 1.7 +++ lib/libssl/src/crypto/dh/dh_err.c 2 Nov 2006 19:56:23 -0000 1.7.2.1 @@ -84,6 +84,7 @@ static ERR_STRING_DATA DH_str_reasons[]= {ERR_REASON(DH_R_BAD_GENERATOR) ,"bad generator"}, {ERR_REASON(DH_R_NO_PRIVATE_VALUE) ,"no private value"}, {ERR_REASON(DH_R_INVALID_PUBKEY) ,"invalid public key"}, +{ERR_REASON(DH_R_MODULUS_TOO_LARGE) ,"modulus too large"}, {0,NULL} }; Index: lib/libssl/src/crypto/dh/dh_key.c =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/dh/dh_key.c,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -u -p -r1.10 -r1.10.2.1 --- lib/libssl/src/crypto/dh/dh_key.c 27 Jun 2006 05:07:01 -0000 1.10 +++ lib/libssl/src/crypto/dh/dh_key.c 2 Nov 2006 19:56:23 -0000 1.10.2.1 @@ -181,6 +181,12 @@ static int compute_key(unsigned char *ke int ret= -1; int check_result; + if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) + { + DHerr(DH_F_DH_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE); + return -1; + } + ctx = BN_CTX_new(); if (ctx == NULL) goto err; BN_CTX_start(ctx); Index: lib/libssl/src/crypto/dsa/dsa.h =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/dsa/dsa.h,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -u -p -r1.8 -r1.8.2.1 --- lib/libssl/src/crypto/dsa/dsa.h 27 Jun 2006 05:07:01 -0000 1.8 +++ lib/libssl/src/crypto/dsa/dsa.h 2 Nov 2006 19:56:23 -0000 1.8.2.1 @@ -79,6 +79,8 @@ # include #endif +#define OPENSSL_DSA_MAX_MODULUS_BITS 3072 + #define DSA_FLAG_CACHE_MONT_P 0x01 #define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA * implementation now uses constant time @@ -259,8 +261,10 @@ void ERR_load_DSA_strings(void); #define DSA_F_SIG_CB 114 /* Reason codes. */ +#define DSA_R_BAD_Q_VALUE 102 #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 #define DSA_R_MISSING_PARAMETERS 101 +#define DSA_R_MODULUS_TOO_LARGE 103 #ifdef __cplusplus } Index: lib/libssl/src/crypto/dsa/dsa_err.c =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/dsa/dsa_err.c,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -u -p -r1.7 -r1.7.2.1 --- lib/libssl/src/crypto/dsa/dsa_err.c 27 Jun 2006 05:07:01 -0000 1.7 +++ lib/libssl/src/crypto/dsa/dsa_err.c 2 Nov 2006 19:56:23 -0000 1.7.2.1 @@ -89,8 +89,10 @@ static ERR_STRING_DATA DSA_str_functs[]= static ERR_STRING_DATA DSA_str_reasons[]= { +{ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"}, {ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"}, {ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"}, +{ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"}, {0,NULL} }; Index: lib/libssl/src/crypto/dsa/dsa_ossl.c =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/dsa/dsa_ossl.c,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -u -p -r1.9 -r1.9.2.1 --- lib/libssl/src/crypto/dsa/dsa_ossl.c 27 Jun 2006 05:07:01 -0000 1.9 +++ lib/libssl/src/crypto/dsa/dsa_ossl.c 2 Nov 2006 19:56:23 -0000 1.9.2.1 @@ -274,6 +274,18 @@ static int dsa_do_verify(const unsigned return -1; } + if (BN_num_bits(dsa->q) != 160) + { + DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE); + return -1; + } + + if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) + { + DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE); + return -1; + } + BN_init(&u1); BN_init(&u2); BN_init(&t1); Index: lib/libssl/src/crypto/rsa/rsa.h =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/rsa/rsa.h,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -u -p -r1.10 -r1.10.2.1 --- lib/libssl/src/crypto/rsa/rsa.h 27 Jun 2006 05:07:02 -0000 1.10 +++ lib/libssl/src/crypto/rsa/rsa.h 2 Nov 2006 19:56:23 -0000 1.10.2.1 @@ -154,6 +154,11 @@ struct rsa_st BN_BLINDING *blinding; }; +#define OPENSSL_RSA_MAX_MODULUS_BITS 16384 + +#define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 +#define OPENSSL_RSA_MAX_PUBEXP_BITS 64 /* exponent limit enforced for "small" modulus only */ + #define RSA_3 0x3L #define RSA_F4 0x10001L @@ -386,6 +391,7 @@ void ERR_load_RSA_strings(void); #define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 #define RSA_R_KEY_SIZE_TOO_SMALL 120 #define RSA_R_LAST_OCTET_INVALID 134 +#define RSA_R_MODULUS_TOO_LARGE 105 #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 #define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 #define RSA_R_OAEP_DECODING_ERROR 121 Index: lib/libssl/src/crypto/rsa/rsa_eay.c =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/rsa/rsa_eay.c,v retrieving revision 1.16 retrieving revision 1.16.2.1 diff -u -p -r1.16 -r1.16.2.1 --- lib/libssl/src/crypto/rsa/rsa_eay.c 27 Jun 2006 05:07:02 -0000 1.16 +++ lib/libssl/src/crypto/rsa/rsa_eay.c 2 Nov 2006 19:56:23 -0000 1.16.2.1 @@ -295,6 +295,28 @@ static int RSA_eay_private_encrypt(int f BN_init(&f); BN_init(&ret); + if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) + { + RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE); + return -1; + } + + if (BN_ucmp(rsa->n, rsa->e) <= 0) + { + RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE); + return -1; + } + + /* for large moduli, enforce exponent limit */ + if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) + { + if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) + { + RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE); + return -1; + } + } + if ((ctx=BN_CTX_new()) == NULL) goto err; num=BN_num_bytes(rsa->n); if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL) @@ -575,6 +597,28 @@ static int RSA_eay_public_decrypt(int fl unsigned char *p; unsigned char *buf=NULL; BN_CTX *ctx=NULL; + + if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) + { + RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_MODULUS_TOO_LARGE); + return -1; + } + + if (BN_ucmp(rsa->n, rsa->e) <= 0) + { + RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE); + return -1; + } + + /* for large moduli, enforce exponent limit */ + if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) + { + if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) + { + RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE); + return -1; + } + } BN_init(&f); BN_init(&ret); Index: lib/libssl/src/crypto/rsa/rsa_err.c =================================================================== RCS file: /cvs/src/lib/libssl/src/crypto/rsa/rsa_err.c,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -p -r1.6 -r1.6.2.1 --- lib/libssl/src/crypto/rsa/rsa_err.c 27 Jun 2006 05:07:02 -0000 1.6 +++ lib/libssl/src/crypto/rsa/rsa_err.c 2 Nov 2006 19:56:23 -0000 1.6.2.1 @@ -129,6 +129,7 @@ static ERR_STRING_DATA RSA_str_reasons[] {ERR_REASON(RSA_R_IQMP_NOT_INVERSE_OF_Q) ,"iqmp not inverse of q"}, {ERR_REASON(RSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"}, {ERR_REASON(RSA_R_LAST_OCTET_INVALID) ,"last octet invalid"}, +{ERR_REASON(RSA_R_MODULUS_TOO_LARGE) ,"modulus too large"}, {ERR_REASON(RSA_R_NULL_BEFORE_BLOCK_MISSING),"null before block missing"}, {ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q) ,"n does not equal p q"}, {ERR_REASON(RSA_R_OAEP_DECODING_ERROR) ,"oaep decoding error"}, Index: lib/libssl/src/ssl/s2_clnt.c =================================================================== RCS file: /cvs/src/lib/libssl/src/ssl/s2_clnt.c,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -p -r1.12 -r1.12.2.1 --- lib/libssl/src/ssl/s2_clnt.c 27 Jun 2006 05:07:03 -0000 1.12 +++ lib/libssl/src/ssl/s2_clnt.c 2 Nov 2006 19:56:23 -0000 1.12.2.1 @@ -538,7 +538,8 @@ static int get_server_hello(SSL *s) CRYPTO_add(&s->session->peer->references, 1, CRYPTO_LOCK_X509); } - if (s->session->peer != s->session->sess_cert->peer_key->x509) + if (s->session->sess_cert == NULL || + s->session->peer != s->session->sess_cert->peer_key->x509) /* can't happen */ { ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR); Index: lib/libssl/src/ssl/ssl_lib.c =================================================================== RCS file: /cvs/src/lib/libssl/src/ssl/ssl_lib.c,v retrieving revision 1.14 retrieving revision 1.14.2.1 diff -u -p -r1.14 -r1.14.2.1 --- lib/libssl/src/ssl/ssl_lib.c 27 Jun 2006 05:07:03 -0000 1.14 +++ lib/libssl/src/ssl/ssl_lib.c 2 Nov 2006 19:56:23 -0000 1.14.2.1 @@ -1187,7 +1187,7 @@ char *SSL_get_shared_ciphers(const SSL * c=sk_SSL_CIPHER_value(sk,i); for (cp=c->name; *cp; ) { - if (len-- == 0) + if (len-- <= 0) { *p='\0'; return(buf);