Modify handshake_patch such that app data is sent along with CCS/Finished.
diff --git a/patches/handshake_cutthrough.patch b/patches/handshake_cutthrough.patch
index 16538a1..e4d3621 100644
--- a/patches/handshake_cutthrough.patch
+++ b/patches/handshake_cutthrough.patch
@@ -1,6 +1,6 @@
diff -uarp openssl-0.9.8k.orig/apps/s_client.c openssl-0.9.8k/apps/s_client.c
--- openssl-0.9.8k.orig/apps/s_client.c 2008-12-20 09:04:08.000000000 -0800
-+++ openssl-0.9.8k/apps/s_client.c 2009-10-01 10:32:25.000000000 -0700
++++ openssl-0.9.8k/apps/s_client.c 2009-10-05 17:00:24.000000000 -0700
@@ -248,6 +248,7 @@ static void sc_usage(void)
BIO_printf(bio_err," -tlsextdebug - hex dump of all TLS extensions received\n");
BIO_printf(bio_err," -status - request certificate status from server\n");
@@ -42,21 +42,24 @@
if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);
if (cipher != NULL)
if(!SSL_CTX_set_cipher_list(ctx,cipher)) {
-diff -uarp openssl-0.9.8k.orig/include/openssl/ssl3.h openssl-0.9.8k/include/openssl/ssl3.h
---- openssl-0.9.8k.orig/include/openssl/ssl3.h 2009-10-01 10:32:15.000000000 -0700
-+++ openssl-0.9.8k/include/openssl/ssl3.h 2009-10-01 10:32:25.000000000 -0700
-@@ -456,6 +456,7 @@ typedef struct ssl3_state_st
- /*client */
- /* extra state */
- #define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
-+#define SSL3_ST_CUTTHROUGH_COMPLETE (0x101|SSL_ST_CONNECT)
- /* write to server */
- #define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
- #define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
diff -uarp openssl-0.9.8k.orig/ssl/s3_clnt.c openssl-0.9.8k/ssl/s3_clnt.c
--- openssl-0.9.8k.orig/ssl/s3_clnt.c 2009-02-14 13:50:14.000000000 -0800
-+++ openssl-0.9.8k/ssl/s3_clnt.c 2009-10-01 10:32:25.000000000 -0700
-@@ -454,14 +454,20 @@ int ssl3_connect(SSL *s)
++++ openssl-0.9.8k/ssl/s3_clnt.c 2009-10-05 17:00:24.000000000 -0700
+@@ -186,6 +186,13 @@ int ssl3_connect(SSL *s)
+
+ s->in_handshake++;
+ if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
++ if (SSL_get_mode(s) & SSL_MODE_HANDSHAKE_CUTTHROUGH)
++ {
++ /* Reneotiation complicates the state machine */
++ s->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;
++ /* Send app data along with CCS/Finished */
++ s->s3->flags |= SSL3_FLAGS_DELAY_CLIENT_FINISHED;
++ }
+
+ for (;;)
+ {
+@@ -454,14 +461,29 @@ int ssl3_connect(SSL *s)
}
else
{
@@ -66,7 +69,16 @@
- s->s3->tmp.next_state=SSL3_ST_CR_SESSION_TICKET_A;
+ if ((SSL_get_mode(s) & SSL_MODE_HANDSHAKE_CUTTHROUGH) && SSL_get_cipher_bits(s, NULL) >= 128)
+ {
-+ s->s3->tmp.next_state=SSL3_ST_CUTTHROUGH_COMPLETE;
++ if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
++ {
++ s->state=SSL3_ST_CUTTHROUGH_COMPLETE;
++ s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
++ s->s3->delay_buf_pop_ret=0;
++ }
++ else
++ {
++ s->s3->tmp.next_state=SSL3_ST_CUTTHROUGH_COMPLETE;
++ }
+ }
else
+ {
@@ -83,7 +95,7 @@
}
s->init_num=0;
break;
-@@ -512,6 +518,22 @@ int ssl3_connect(SSL *s)
+@@ -512,6 +534,24 @@ int ssl3_connect(SSL *s)
s->state=s->s3->tmp.next_state;
break;
@@ -96,9 +108,11 @@
+#endif
+ s->state=SSL3_ST_CR_FINISHED_A;
+
-+ /* Allow application writes to go through. Note that SSL3_FLAGS_DELAY_CLIENT_FINISHED
-+ * is not supported on cutthrough connections (just for simplicity) */
-+ ssl_free_wbio_buffer(s);
++ /* SSL_write() will take care of flushing buffered data if
++ * DELAY_CLIENT_FINISHED is set.
++ */
++ if (!(s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED))
++ ssl_free_wbio_buffer(s);
+ ret = 1;
+ goto end;
+ /* break; */
@@ -106,9 +120,36 @@
case SSL_ST_OK:
/* clean a few things up */
ssl3_cleanup_key_block(s);
+diff -uarp openssl-0.9.8k.orig/ssl/s3_lib.c openssl-0.9.8k/ssl/s3_lib.c
+--- openssl-0.9.8k.orig/ssl/s3_lib.c 2008-06-16 09:56:41.000000000 -0700
++++ openssl-0.9.8k/ssl/s3_lib.c 2009-10-05 17:00:24.000000000 -0700
+@@ -2551,9 +2551,22 @@ int ssl3_write(SSL *s, const void *buf,
+
+ static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
+ {
+- int ret;
++ int n,ret;
+
+ clear_sys_error();
++ if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
++ {
++ /* Deal with an application that calls SSL_read() when handshake data
++ * is yet to be written.
++ */
++ if (BIO_wpending(s->wbio) > 0)
++ {
++ s->rwstate=SSL_WRITING;
++ n=BIO_flush(s->wbio);
++ if (n <= 0) return(n);
++ s->rwstate=SSL_NOTHING;
++ }
++ }
+ if (s->s3->renegotiate) ssl3_renegotiate_check(s);
+ s->s3->in_read_app_data=1;
+ ret=s->method->ssl_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
diff -uarp openssl-0.9.8k.orig/ssl/ssl.h openssl-0.9.8k/ssl/ssl.h
---- openssl-0.9.8k.orig/ssl/ssl.h 2009-10-01 10:32:15.000000000 -0700
-+++ openssl-0.9.8k/ssl/ssl.h 2009-10-01 10:32:25.000000000 -0700
+--- openssl-0.9.8k.orig/ssl/ssl.h 2009-10-05 17:00:39.000000000 -0700
++++ openssl-0.9.8k/ssl/ssl.h 2009-10-05 17:00:24.000000000 -0700
@@ -557,6 +557,10 @@ typedef struct ssl_session_st
/* Use small read and write buffers: (a) lazy allocate read buffers for
* large incoming records, and (b) limit the size of outgoing records. */
@@ -136,8 +177,8 @@
* you should not need these */
Only in openssl-0.9.8k/ssl: ssl.h.orig
diff -uarp openssl-0.9.8k.orig/ssl/ssl3.h openssl-0.9.8k/ssl/ssl3.h
---- openssl-0.9.8k.orig/ssl/ssl3.h 2009-10-01 10:32:15.000000000 -0700
-+++ openssl-0.9.8k/ssl/ssl3.h 2009-10-01 10:32:25.000000000 -0700
+--- openssl-0.9.8k.orig/ssl/ssl3.h 2009-10-05 17:00:39.000000000 -0700
++++ openssl-0.9.8k/ssl/ssl3.h 2009-10-05 17:00:24.000000000 -0700
@@ -456,6 +456,7 @@ typedef struct ssl3_state_st
/*client */
/* extra state */
@@ -148,7 +189,7 @@
#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
diff -uarp openssl-0.9.8k.orig/ssl/ssl_lib.c openssl-0.9.8k/ssl/ssl_lib.c
--- openssl-0.9.8k.orig/ssl/ssl_lib.c 2009-02-23 08:02:47.000000000 -0800
-+++ openssl-0.9.8k/ssl/ssl_lib.c 2009-10-01 10:32:25.000000000 -0700
++++ openssl-0.9.8k/ssl/ssl_lib.c 2009-10-05 17:00:24.000000000 -0700
@@ -2696,7 +2696,17 @@ void SSL_set_msg_callback(SSL *ssl, void
SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
}
@@ -169,9 +210,9 @@
#if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16)
#include "../crypto/bio/bss_file.c"
Only in openssl-0.9.8k/ssl: ssl_lib.c.orig
-diff -uarp openssl-0.9.8k.orig/test/ssltest.c openssl-0.9.8k/test/ssltest.c
---- openssl-0.9.8k.orig/test/ssltest.c 2009-10-01 10:32:15.000000000 -0700
-+++ openssl-0.9.8k/test/ssltest.c 2009-10-01 10:32:25.000000000 -0700
+diff -uarp openssl-0.9.8k.orig/ssl/ssltest.c openssl-0.9.8k/ssl/ssltest.c
+--- openssl-0.9.8k.orig/ssl/ssltest.c 2009-10-05 17:00:39.000000000 -0700
++++ openssl-0.9.8k/ssl/ssltest.c 2009-10-05 17:00:24.000000000 -0700
@@ -279,6 +279,7 @@ static void sv_usage(void)
fprintf(stderr," -test_cipherlist - verifies the order of the ssl cipher lists\n");
fprintf(stderr," -c_small_records - enable client side use of small SSL record buffers\n");
@@ -214,8 +255,8 @@
#ifndef OPENSSL_NO_DH
if (!no_dhe)
diff -uarp openssl-0.9.8k.orig/test/testssl openssl-0.9.8k/test/testssl
---- openssl-0.9.8k.orig/test/testssl 2009-10-01 10:32:15.000000000 -0700
-+++ openssl-0.9.8k/test/testssl 2009-10-01 10:32:25.000000000 -0700
+--- openssl-0.9.8k.orig/test/testssl 2009-10-05 17:00:39.000000000 -0700
++++ openssl-0.9.8k/test/testssl 2009-10-05 17:00:24.000000000 -0700
@@ -79,6 +79,8 @@ $ssltest -server_auth -client_auth -s_sm
echo test sslv2/sslv3 with both client and server authentication and small client and server buffers
$ssltest -server_auth -client_auth -c_small_records -s_small_records $CA $extra || exit 1
diff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c
index 47dd34f..95f7c12 100644
--- a/ssl/s3_clnt.c
+++ b/ssl/s3_clnt.c
@@ -186,6 +186,13 @@
s->in_handshake++;
if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
+ if (SSL_get_mode(s) & SSL_MODE_HANDSHAKE_CUTTHROUGH)
+ {
+ /* Reneotiation complicates the state machine */
+ s->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;
+ /* Send app data along with CCS/Finished */
+ s->s3->flags |= SSL3_FLAGS_DELAY_CLIENT_FINISHED;
+ }
for (;;)
{
@@ -456,7 +463,16 @@
{
if ((SSL_get_mode(s) & SSL_MODE_HANDSHAKE_CUTTHROUGH) && SSL_get_cipher_bits(s, NULL) >= 128)
{
- s->s3->tmp.next_state=SSL3_ST_CUTTHROUGH_COMPLETE;
+ if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
+ {
+ s->state=SSL3_ST_CUTTHROUGH_COMPLETE;
+ s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
+ s->s3->delay_buf_pop_ret=0;
+ }
+ else
+ {
+ s->s3->tmp.next_state=SSL3_ST_CUTTHROUGH_COMPLETE;
+ }
}
else
{
@@ -527,9 +543,11 @@
#endif
s->state=SSL3_ST_CR_FINISHED_A;
- /* Allow application writes to go through. Note that SSL3_FLAGS_DELAY_CLIENT_FINISHED
- * is not supported on cutthrough connections (just for simplicity) */
- ssl_free_wbio_buffer(s);
+ /* SSL_write() will take care of flushing buffered data if
+ * DELAY_CLIENT_FINISHED is set.
+ */
+ if (!(s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED))
+ ssl_free_wbio_buffer(s);
ret = 1;
goto end;
/* break; */
diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c
index 8916a0b..63f1342 100644
--- a/ssl/s3_lib.c
+++ b/ssl/s3_lib.c
@@ -2551,9 +2551,22 @@
static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
{
- int ret;
+ int n,ret;
clear_sys_error();
+ if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
+ {
+ /* Deal with an application that calls SSL_read() when handshake data
+ * is yet to be written.
+ */
+ if (BIO_wpending(s->wbio) > 0)
+ {
+ s->rwstate=SSL_WRITING;
+ n=BIO_flush(s->wbio);
+ if (n <= 0) return(n);
+ s->rwstate=SSL_NOTHING;
+ }
+ }
if (s->s3->renegotiate) ssl3_renegotiate_check(s);
s->s3->in_read_app_data=1;
ret=s->method->ssl_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
diff --git a/ssl/ssltest.c b/ssl/ssltest.c
index 09d3502..438f3ab 100644
--- a/ssl/ssltest.c
+++ b/ssl/ssltest.c
@@ -279,6 +279,7 @@
fprintf(stderr," -test_cipherlist - verifies the order of the ssl cipher lists\n");
fprintf(stderr," -c_small_records - enable client side use of small SSL record buffers\n");
fprintf(stderr," -s_small_records - enable server side use of small SSL record buffers\n");
+ fprintf(stderr," -cutthrough - enable 1-RTT full-handshake for strong ciphers\n");
}
static void print_details(SSL *c_ssl, const char *prefix)
@@ -436,6 +437,7 @@
int ssl_mode = 0;
int c_small_records=0;
int s_small_records=0;
+ int cutthrough = 0;
verbose = 0;
debug = 0;
@@ -632,6 +634,10 @@
{
s_small_records = 1;
}
+ else if (strcmp(*argv, "-cutthrough") == 0)
+ {
+ cutthrough = 1;
+ }
else
{
fprintf(stderr,"unknown option %s\n",*argv);
@@ -782,6 +788,13 @@
ssl_mode |= SSL_MODE_SMALL_BUFFERS;
SSL_CTX_set_mode(s_ctx, ssl_mode);
}
+ ssl_mode = 0;
+ if (cutthrough)
+ {
+ ssl_mode = SSL_CTX_get_mode(c_ctx);
+ ssl_mode = SSL_MODE_HANDSHAKE_CUTTHROUGH;
+ SSL_CTX_set_mode(c_ctx, ssl_mode);
+ }
#ifndef OPENSSL_NO_DH
if (!no_dhe)