Add extms support to master key generation.
[openssl.git] / ssl / s3_srvr.c
index f77c4c6c072e653067df230a7a0dc766db56d309..f31b76a96ab9f1e4c19c7b208782af94cbc013e7 100644 (file)
@@ -480,8 +480,7 @@ int ssl3_accept(SSL *s)
                 || ((alg_k & SSL_kRSA)
                     && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL
                         || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)
-                            && EVP_PKEY_size(s->cert->
-                                             pkeys
+                            && EVP_PKEY_size(s->cert->pkeys
                                              [SSL_PKEY_RSA_ENC].privatekey) *
                             8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)
                         )
@@ -621,17 +620,19 @@ int ssl3_accept(SSL *s)
                 s->init_num = 0;
                 if (!s->session->peer)
                     break;
-                /*
-                 * For sigalgs freeze the handshake buffer at this point and
-                 * digest cached records.
-                 */
                 if (!s->s3->handshake_buffer) {
                     SSLerr(SSL_F_SSL3_ACCEPT, ERR_R_INTERNAL_ERROR);
                     return -1;
                 }
-                s->s3->flags |= TLS1_FLAGS_KEEP_HANDSHAKE;
-                if (!ssl3_digest_cached_records(s))
-                    return -1;
+                /*
+                 * For sigalgs freeze the handshake buffer. If we support
+                 * extms we've done this already.
+                 */
+                if (!(s->s3->flags & SSL_SESS_FLAG_EXTMS)) {
+                    s->s3->flags |= TLS1_FLAGS_KEEP_HANDSHAKE;
+                    if (!ssl3_digest_cached_records(s))
+                        return -1;
+                }
             } else {
                 int offset = 0;
                 int dgst_num;
@@ -1413,17 +1414,17 @@ int ssl3_get_client_hello(SSL *s)
             goto f_err;
     }
 
-        /*-
-         * we now have the following setup.
-         * client_random
-         * cipher_list          - our prefered list of ciphers
-         * ciphers              - the clients prefered list of ciphers
-         * compression          - basically ignored right now
-         * ssl version is set   - sslv3
-         * s->session           - The ssl session has been setup.
-         * s->hit               - session reuse flag
-         * s->s3->tmp.new_cipher- the new cipher to use.
-         */
+    /*-
+     * we now have the following setup.
+     * client_random
+     * cipher_list          - our prefered list of ciphers
+     * ciphers              - the clients prefered list of ciphers
+     * compression          - basically ignored right now
+     * ssl version is set   - sslv3
+     * s->session           - The ssl session has been setup.
+     * s->hit               - session reuse flag
+     * s->s3->tmp.new_cipher- the new cipher to use.
+     */
 
     /* Handles TLS extensions that we couldn't check earlier */
     if (s->version >= SSL3_VERSION) {
@@ -1470,22 +1471,22 @@ int ssl3_send_server_hello(SSL *s)
         memcpy(p, s->s3->server_random, SSL3_RANDOM_SIZE);
         p += SSL3_RANDOM_SIZE;
 
-                /*-
-                 * There are several cases for the session ID to send
-                 * back in the server hello:
-                 * - For session reuse from the session cache,
-                 *   we send back the old session ID.
-                 * - If stateless session reuse (using a session ticket)
-                 *   is successful, we send back the client's "session ID"
-                 *   (which doesn't actually identify the session).
-                 * - If it is a new session, we send back the new
-                 *   session ID.
-                 * - However, if we want the new session to be single-use,
-                 *   we send back a 0-length session ID.
-                 * s->hit is non-zero in either case of session reuse,
-                 * so the following won't overwrite an ID that we're supposed
-                 * to send back.
-                 */
+        /*-
+         * There are several cases for the session ID to send
+         * back in the server hello:
+         * - For session reuse from the session cache,
+         *   we send back the old session ID.
+         * - If stateless session reuse (using a session ticket)
+         *   is successful, we send back the client's "session ID"
+         *   (which doesn't actually identify the session).
+         * - If it is a new session, we send back the new
+         *   session ID.
+         * - However, if we want the new session to be single-use,
+         *   we send back a 0-length session ID.
+         * s->hit is non-zero in either case of session reuse,
+         * so the following won't overwrite an ID that we're supposed
+         * to send back.
+         */
         if (s->session->not_resumable ||
             (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)
              && !s->hit))
@@ -2541,11 +2542,11 @@ int ssl3_get_client_key_exchange(SSL *s)
             }
         }
 
-                /*- Was doing kssl_ctx_free() here,
-                 *  but it caused problems for apache.
-                 *  kssl_ctx = kssl_ctx_free(kssl_ctx);
-                 *  if (s->kssl_ctx)  s->kssl_ctx = NULL;
-                 */
+        /*- Was doing kssl_ctx_free() here,
+         *  but it caused problems for apache.
+         *  kssl_ctx = kssl_ctx_free(kssl_ctx);
+         *  if (s->kssl_ctx)  s->kssl_ctx = NULL;
+         */
     } else
 #endif                          /* OPENSSL_NO_KRB5 */
 
@@ -3356,14 +3357,14 @@ int ssl3_send_newsession_ticket(SSL *s)
         i2d_SSL_SESSION(sess, &p);
         SSL_SESSION_free(sess);
 
-                /*-
-                 * Grow buffer if need be: the length calculation is as
-                 * follows handshake_header_length +
-                 * 4 (ticket lifetime hint) + 2 (ticket length) +
-                 * 16 (key name) + max_iv_len (iv length) +
-                 * session_length + max_enc_block_size (max encrypted session
-                 * length) + max_md_size (HMAC).
-                 */
+        /*-
+         * Grow buffer if need be: the length calculation is as
+         * follows handshake_header_length +
+         * 4 (ticket lifetime hint) + 2 (ticket length) +
+         * 16 (key name) + max_iv_len (iv length) +
+         * session_length + max_enc_block_size (max encrypted session
+         * length) + max_md_size (HMAC).
+         */
         if (!BUF_MEM_grow(s->init_buf,
                           SSL_HM_HEADER_LENGTH(s) + 22 + EVP_MAX_IV_LENGTH +
                           EVP_MAX_BLOCK_LENGTH + EVP_MAX_MD_SIZE + slen))
@@ -3386,7 +3387,7 @@ int ssl3_send_newsession_ticket(SSL *s)
             EVP_EncryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL,
                                tctx->tlsext_tick_aes_key, iv);
             HMAC_Init_ex(&hctx, tctx->tlsext_tick_hmac_key, 16,
-                         tlsext_tick_md(), NULL);
+                         EVP_sha256(), NULL);
             memcpy(key_name, tctx->tlsext_tick_key_name, 16);
         }
 
@@ -3437,12 +3438,12 @@ int ssl3_send_cert_status(SSL *s)
 {
     if (s->state == SSL3_ST_SW_CERT_STATUS_A) {
         unsigned char *p;
-                /*-
-                 * Grow buffer if need be: the length calculation is as
-                 * follows 1 (message type) + 3 (message length) +
-                 * 1 (ocsp response type) + 3 (ocsp response length)
-                 * + (ocsp response)
-                 */
+        /*-
+         * Grow buffer if need be: the length calculation is as
+         * follows 1 (message type) + 3 (message length) +
+         * 1 (ocsp response type) + 3 (ocsp response length)
+         * + (ocsp response)
+         */
         if (!BUF_MEM_grow(s->init_buf, 8 + s->tlsext_ocsp_resplen))
             return -1;
 
@@ -3514,13 +3515,13 @@ int ssl3_get_next_proto(SSL *s)
 
     p = (unsigned char *)s->init_msg;
 
-        /*-
-         * The payload looks like:
-         *   uint8 proto_len;
-         *   uint8 proto[proto_len];
-         *   uint8 padding_len;
-         *   uint8 padding[padding_len];
-         */
+    /*-
+     * The payload looks like:
+     *   uint8 proto_len;
+     *   uint8 proto[proto_len];
+     *   uint8 padding_len;
+     *   uint8 padding[padding_len];
+     */
     proto_len = p[0];
     if (proto_len + 2 > s->init_num)
         return 0;