Fix source where indent will not be able to cope
[openssl.git] / ssl / s3_clnt.c
index 1aff83318436271ff4b836e0707e200a1c231544..1ddcf26d4971b68aab4f0c5d157d01653e76494d 100644 (file)
@@ -730,7 +730,8 @@ int ssl3_client_hello(SSL *s)
                /* Do the message type and length last */
                d=p= ssl_handshake_start(s);
 
-               /* version indicates the negotiated version: for example from
+               /*-
+                * version indicates the negotiated version: for example from
                 * an SSLv2/v3 compatible client hello). The client_version
                 * field is the maximum version we permit and it is also
                 * used in RSA encrypted premaster secrets. Some servers can
@@ -887,7 +888,7 @@ int ssl3_get_server_hello(SSL *s)
                SSL3_ST_CR_SRVR_HELLO_A,
                SSL3_ST_CR_SRVR_HELLO_B,
                -1,
-               20000, /* ?? */
+               20000,
                &ok);
 
        if (!ok) return((int)n);
@@ -1275,9 +1276,9 @@ int ssl3_get_server_certificate(SSL *s)
                    ? 0 : 1;
 
 #ifdef KSSL_DEBUG
-       printf("pkey,x = %p, %p\n", pkey,x);
-       printf("ssl_cert_type(x,pkey) = %d\n", ssl_cert_type(x,pkey));
-       printf("cipher, alg, nc = %s, %lx, %lx, %d\n", s->s3->tmp.new_cipher->name,
+       fprintf(stderr,"pkey,x = %p, %p\n", pkey,x);
+       fprintf(stderr,"ssl_cert_type(x,pkey) = %d\n", ssl_cert_type(x,pkey));
+       fprintf(stderr,"cipher, alg, nc = %s, %lx, %lx, %d\n", s->s3->tmp.new_cipher->name,
                s->s3->tmp.new_cipher->algorithm_mkey, s->s3->tmp.new_cipher->algorithm_auth, need_cert);
 #endif    /* KSSL_DEBUG */
 
@@ -1375,6 +1376,8 @@ int ssl3_get_key_exchange(SSL *s)
        int encoded_pt_len = 0;
 #endif
 
+       EVP_MD_CTX_init(&md_ctx);
+
        /* use same message size as in ssl3_get_certificate_request()
         * as ServerKeyExchange message may be skipped */
        n=s->method->ssl_get_message(s,
@@ -1385,14 +1388,26 @@ int ssl3_get_key_exchange(SSL *s)
                &ok);
        if (!ok) return((int)n);
 
+       alg_k=s->s3->tmp.new_cipher->algorithm_mkey;
+
        if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)
                {
+               /*
+                * Can't skip server key exchange if this is an ephemeral
+                * ciphersuite.
+                */
+               if (alg_k & (SSL_kDHE|SSL_kECDHE))
+                       {
+                       SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, SSL_R_UNEXPECTED_MESSAGE);
+                       al = SSL_AD_UNEXPECTED_MESSAGE;
+                       goto f_err;
+                       }
 #ifndef OPENSSL_NO_PSK
                /* In plain PSK ciphersuite, ServerKeyExchange can be
                   omitted if no identity hint is sent. Set
                   session->sess_cert anyway to avoid problems
                   later.*/
-               if (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)
+               if (alg_k & SSL_kPSK)
                        {
                        s->session->sess_cert=ssl_sess_cert_new();
                        if (s->ctx->psk_identity_hint)
@@ -1437,9 +1452,7 @@ int ssl3_get_key_exchange(SSL *s)
        /* Total length of the parameters including the length prefix */
        param_len=0;
 
-       alg_k=s->s3->tmp.new_cipher->algorithm_mkey;
        alg_a=s->s3->tmp.new_cipher->algorithm_auth;
-       EVP_MD_CTX_init(&md_ctx);
 
        al=SSL_AD_DECODE_ERROR;
 
@@ -1623,6 +1636,13 @@ int ssl3_get_key_exchange(SSL *s)
 #ifndef OPENSSL_NO_RSA
        if (alg_k & SSL_kRSA)
                {
+               /* Temporary RSA keys only allowed in export ciphersuites */
+               if (!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher))
+                       {
+                       al=SSL_AD_UNEXPECTED_MESSAGE;
+                       SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_UNEXPECTED_MESSAGE);
+                       goto f_err;
+                       }
                if ((rsa=RSA_new()) == NULL)
                        {
                        SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
@@ -2428,11 +2448,12 @@ int ssl3_get_server_done(SSL *s)
        int ok,ret=0;
        long n;
 
+       /* Second to last param should be very small, like 0 :-) */
        n=s->method->ssl_get_message(s,
                SSL3_ST_CR_SRVR_DONE_A,
                SSL3_ST_CR_SRVR_DONE_B,
                SSL3_MT_SERVER_DONE,
-               30, /* should be very small, like 0 :-) */
+               30,
                &ok);
 
        if (!ok) return((int)n);
@@ -2562,7 +2583,7 @@ int ssl3_send_client_key_exchange(SSL *s)
                        EVP_CIPHER_CTX_init(&ciph_ctx);
 
 #ifdef KSSL_DEBUG
-                       printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
+                       fprintf(stderr,"ssl3_send_client_key_exchange(%lx & %lx)\n",
                                alg_k, SSL_kKRB5);
 #endif /* KSSL_DEBUG */
 
@@ -2578,9 +2599,9 @@ int ssl3_send_client_key_exchange(SSL *s)
                            goto err;
 #ifdef KSSL_DEBUG
                        {
-                       printf("kssl_cget_tkt rtn %d\n", krb5rc);
+                       fprintf(stderr,"kssl_cget_tkt rtn %d\n", krb5rc);
                        if (krb5rc && kssl_err.text)
-                         printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text);
+                         fprintf(stderr,"kssl_cget_tkt kssl_err=%s\n", kssl_err.text);
                        }
 #endif /* KSSL_DEBUG */
 
@@ -2593,24 +2614,25 @@ int ssl3_send_client_key_exchange(SSL *s)
                                goto err;
                                }
 
-                       /*  20010406 VRS - Earlier versions used KRB5 AP_REQ
-                       **  in place of RFC 2712 KerberosWrapper, as in:
-                       **
-                       **  Send ticket (copy to *p, set n = length)
-                       **  n = krb5_ap_req.length;
-                       **  memcpy(p, krb5_ap_req.data, krb5_ap_req.length);
-                       **  if (krb5_ap_req.data)  
-                       **    kssl_krb5_free_data_contents(NULL,&krb5_ap_req);
-                       **
-                       **  Now using real RFC 2712 KerberosWrapper
-                       **  (Thanks to Simon Wilkinson <sxw@sxw.org.uk>)
-                       **  Note: 2712 "opaque" types are here replaced
-                       **  with a 2-byte length followed by the value.
-                       **  Example:
-                       **  KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms
-                       **  Where "xx xx" = length bytes.  Shown here with
-                       **  optional authenticator omitted.
-                       */
+                       /*-
+                        * 20010406 VRS - Earlier versions used KRB5 AP_REQ
+                        * in place of RFC 2712 KerberosWrapper, as in:
+                        *
+                        * Send ticket (copy to *p, set n = length)
+                        * n = krb5_ap_req.length;
+                        * memcpy(p, krb5_ap_req.data, krb5_ap_req.length);
+                        * if (krb5_ap_req.data)  
+                        *   kssl_krb5_free_data_contents(NULL,&krb5_ap_req);
+                        *
+                        * Now using real RFC 2712 KerberosWrapper
+                        * (Thanks to Simon Wilkinson <sxw@sxw.org.uk>)
+                        * Note: 2712 "opaque" types are here replaced
+                        * with a 2-byte length followed by the value.
+                        * Example:
+                        * KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms
+                        * Where "xx xx" = length bytes.  Shown here with
+                        * optional authenticator omitted.
+                        */
 
                        /*  KerberosWrapper.Ticket              */
                        s2n(enc_ticket->length,p);
@@ -2641,12 +2663,13 @@ int ssl3_send_client_key_exchange(SSL *s)
                            if (RAND_bytes(&(tmp_buf[2]),sizeof tmp_buf-2) <= 0)
                                goto err;
 
-                       /*  20010420 VRS.  Tried it this way; failed.
-                       **      EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL);
-                       **      EVP_CIPHER_CTX_set_key_length(&ciph_ctx,
-                       **                              kssl_ctx->length);
-                       **      EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv);
-                       */
+                       /*-
+                        * 20010420 VRS.  Tried it this way; failed.
+                        *      EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL);
+                        *      EVP_CIPHER_CTX_set_key_length(&ciph_ctx,
+                        *                              kssl_ctx->length);
+                        *      EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv);
+                        */
 
                        memset(iv, 0, sizeof iv);  /* per RFC 1510 */
                        EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,
@@ -2803,7 +2826,8 @@ int ssl3_send_client_key_exchange(SSL *s)
                         */
                        if ((alg_k & (SSL_kECDHr|SSL_kECDHe)) && (s->cert != NULL)) 
                                {
-                               /* XXX: For now, we do not support client
+                               /*-
+                                * XXX: For now, we do not support client
                                 * authentication using ECDH certificates.
                                 * To add such support, one needs to add
                                 * code that checks for appropriate 
@@ -3551,7 +3575,8 @@ int ssl3_check_cert_and_algorithm(SSL *s)
                {
                if (ssl_check_srvr_ecc_cert_and_alg(sc->peer_pkeys[idx].x509,
                                                                s) == 0) 
-                       { /* check failed */
+                       {
+                       /* check failed */
                        SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_BAD_ECC_CERT);
                        goto f_err;
                        }