Add support for automatic ECDH temporary key parameter selection. When
[openssl.git] / ssl / ssl_lib.c
index 4c4665b0881cb74dbafdb35738f16caddcf97db9..679894cb3db15328c03b0d89a2cae9bbc652b32a 100644 (file)
@@ -177,7 +177,10 @@ SSL3_ENC_METHOD ssl3_undef_enc_method={
        0,      /* client_finished_label_len */
        NULL,   /* server_finished_label */
        0,      /* server_finished_label_len */
-       (int (*)(int))ssl_undefined_function
+       (int (*)(int))ssl_undefined_function,
+       (int (*)(SSL *, unsigned char *, size_t, const char *,
+                size_t, const unsigned char *, size_t,
+                int use_context)) ssl_undefined_function,
        };
 
 int SSL_clear(SSL *s)
@@ -355,6 +358,28 @@ SSL *SSL_new(SSL_CTX *ctx)
        s->tlsext_ocsp_resplen = -1;
        CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
        s->initial_ctx=ctx;
+#ifndef OPENSSL_NO_EC
+       if (ctx->tlsext_ecpointformatlist)
+               {
+               s->tlsext_ecpointformatlist =
+                       BUF_memdup(ctx->tlsext_ecpointformatlist,
+                                       ctx->tlsext_ecpointformatlist_length);
+               if (!s->tlsext_ecpointformatlist)
+                       goto err;
+               s->tlsext_ecpointformatlist_length =
+                                       ctx->tlsext_ecpointformatlist_length;
+               }
+       if (ctx->tlsext_ellipticcurvelist)
+               {
+               s->tlsext_ellipticcurvelist =
+                       BUF_memdup(ctx->tlsext_ellipticcurvelist,
+                                       ctx->tlsext_ellipticcurvelist_length);
+               if (!s->tlsext_ellipticcurvelist)
+                       goto err;
+               s->tlsext_ellipticcurvelist_length = 
+                                       ctx->tlsext_ellipticcurvelist_length;
+               }
+#endif
 # ifndef OPENSSL_NO_NEXTPROTONEG
        s->next_proto_negotiated = NULL;
 # endif
@@ -596,6 +621,9 @@ void SSL_free(SSL *s)
                OPENSSL_free(s->next_proto_negotiated);
 #endif
 
+        if (s->srtp_profiles)
+            sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);
+
        OPENSSL_free(s);
        }
 
@@ -1075,8 +1103,10 @@ long SSL_ctrl(SSL *s,int cmd,long larg,void *parg)
                s->max_cert_list=larg;
                return(l);
        case SSL_CTRL_SET_MTU:
+#ifndef OPENSSL_NO_DTLS1
                if (larg < (long)dtls1_min_mtu())
                        return 0;
+#endif
 
                if (SSL_version(s) == DTLS1_VERSION ||
                    SSL_version(s) == DTLS1_BAD_VER)
@@ -1381,7 +1411,7 @@ int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,
                c=sk_SSL_CIPHER_value(sk,i);
                /* Skip TLS v1.2 only ciphersuites if lower than v1.2 */
                if ((c->algorithm_ssl & SSL_TLSV1_2) && 
-                       (TLS1_get_version(s) < TLS1_2_VERSION))
+                       (TLS1_get_client_version(s) < TLS1_2_VERSION))
                        continue;
 #ifndef OPENSSL_NO_KRB5
                if (((c->algorithm_mkey & SSL_kKRB5) || (c->algorithm_auth & SSL_aKRB5)) &&
@@ -1624,6 +1654,18 @@ void SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s, unsigned
 # endif
 #endif
 
+int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen,
+       const char *label, size_t llen, const unsigned char *p, size_t plen,
+       int use_context)
+       {
+       if (s->version < TLS1_VERSION)
+               return -1;
+
+       return s->method->ssl3_enc->export_keying_material(s, out, olen, label,
+                                                          llen, p, plen,
+                                                          use_context);
+       }
+
 static unsigned long ssl_session_hash(const SSL_SESSION *a)
        {
        unsigned long l;
@@ -1849,8 +1891,6 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)
         * deployed might change this.
         */
        ret->options |= SSL_OP_LEGACY_SERVER_CONNECT;
-       /* Disable TLS v1.2 by default for now */
-       ret->options |= SSL_OP_NO_TLSv1_2;
 
        return(ret);
 err:
@@ -1937,6 +1977,9 @@ void SSL_CTX_free(SSL_CTX *a)
        a->comp_methods = NULL;
 #endif
 
+        if (a->srtp_profiles)
+                sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);
+
 #ifndef OPENSSL_NO_PSK
        if (a->psk_identity_hint)
                OPENSSL_free(a->psk_identity_hint);
@@ -1954,6 +1997,14 @@ void SSL_CTX_free(SSL_CTX *a)
                ssl_buf_freelist_free(a->wbuf_freelist);
        if (a->rbuf_freelist)
                ssl_buf_freelist_free(a->rbuf_freelist);
+#endif
+#ifndef OPENSSL_NO_TLSEXT
+# ifndef OPENSSL_NO_EC
+       if (a->tlsext_ecpointformatlist)
+               OPENSSL_free(a->tlsext_ecpointformatlist);
+       if (a->tlsext_ellipticcurvelist)
+               OPENSSL_free(a->tlsext_ellipticcurvelist);
+# endif /* OPENSSL_NO_EC */
 #endif
 
        OPENSSL_free(a);
@@ -2021,7 +2072,7 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)
 #endif
 
 #ifndef OPENSSL_NO_ECDH
-       have_ecdh_tmp=(c->ecdh_tmp != NULL || c->ecdh_tmp_cb != NULL);
+       have_ecdh_tmp=(c->ecdh_tmp || c->ecdh_tmp_cb || c->ecdh_tmp_auto);
 #endif
        cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);
        rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL);
@@ -2090,6 +2141,9 @@ void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)
        if (dh_dsa) mask_k|=SSL_kDHd;
        if (dh_dsa_export) emask_k|=SSL_kDHd;
 
+       if (emask_k & (SSL_kDHr|SSL_kDHd))
+               mask_a |= SSL_aDH;
+
        if (rsa_enc || rsa_sign)
                {
                mask_a|=SSL_aRSA;
@@ -2269,7 +2323,7 @@ int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s)
 #endif
 
 /* THIS NEEDS CLEANING UP */
-X509 *ssl_get_server_send_cert(SSL *s)
+CERT_PKEY *ssl_get_server_send_pkey(SSL *s)
        {
        unsigned long alg_k,alg_a;
        CERT *c;
@@ -2324,12 +2378,12 @@ X509 *ssl_get_server_send_cert(SSL *s)
                i=SSL_PKEY_GOST01;
        else /* if (alg_a & SSL_aNULL) */
                {
-               SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR);
+               SSLerr(SSL_F_SSL_GET_SERVER_SEND_PKEY,ERR_R_INTERNAL_ERROR);
                return(NULL);
                }
        if (c->pkeys[i].x509 == NULL) return(NULL);
 
-       return(c->pkeys[i].x509);
+       return(&c->pkeys[i]);
        }
 
 EVP_PKEY *ssl_get_sign_pkey(SSL *s,const SSL_CIPHER *cipher, const EVP_MD **pmd)