Home | History | Annotate | Download | only in patches
      1 diff -uarp openssl-0.9.8k.orig/apps/s_client.c openssl-0.9.8k/apps/s_client.c
      2 --- openssl-0.9.8k.orig/apps/s_client.c	2008-12-20 09:04:08.000000000 -0800
      3 +++ openssl-0.9.8k/apps/s_client.c	2009-10-05 17:00:24.000000000 -0700
      4 @@ -248,6 +248,7 @@ static void sc_usage(void)
      5  	BIO_printf(bio_err," -tlsextdebug      - hex dump of all TLS extensions received\n");
      6  	BIO_printf(bio_err," -status           - request certificate status from server\n");
      7  	BIO_printf(bio_err," -no_ticket        - disable use of RFC4507bis session tickets\n");
      8 +	BIO_printf(bio_err," -cutthrough       - enable 1-RTT full-handshake for strong ciphers\n");
      9  #endif
     10  	}
     11  
     12 @@ -304,6 +305,7 @@ int MAIN(int argc, char **argv)
     13  	EVP_PKEY *key = NULL;
     14  	char *CApath=NULL,*CAfile=NULL,*cipher=NULL;
     15  	int reconnect=0,badop=0,verify=SSL_VERIFY_NONE,bugs=0;
     16 +	int cutthrough=0;
     17  	int crlf=0;
     18  	int write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending;
     19  	SSL_CTX *ctx=NULL;
     20 @@ -533,6 +535,8 @@ int MAIN(int argc, char **argv)
     21  		else if	(strcmp(*argv,"-no_ticket") == 0)
     22  			{ off|=SSL_OP_NO_TICKET; }
     23  #endif
     24 +		else if (strcmp(*argv,"-cutthrough") == 0)
     25 +			cutthrough=1;
     26  		else if (strcmp(*argv,"-serverpref") == 0)
     27  			off|=SSL_OP_CIPHER_SERVER_PREFERENCE;
     28  		else if	(strcmp(*argv,"-cipher") == 0)
     29 @@ -714,6 +718,15 @@ bad:
     30  	 */
     31  	if (sock_type == SOCK_DGRAM) SSL_CTX_set_read_ahead(ctx, 1);
     32  
     33 +	/* Enable handshake cutthrough for client connections using
     34 +	 * strong ciphers. */
     35 +	if (cutthrough)
     36 +		{
     37 +		int ssl_mode = SSL_CTX_get_mode(ctx);
     38 +		ssl_mode |= SSL_MODE_HANDSHAKE_CUTTHROUGH;
     39 +		SSL_CTX_set_mode(ctx, ssl_mode);
     40 +		}
     41 +
     42  	if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);
     43  	if (cipher != NULL)
     44  		if(!SSL_CTX_set_cipher_list(ctx,cipher)) {
     45 diff -uarp openssl-0.9.8k.orig/ssl/s3_clnt.c openssl-0.9.8k/ssl/s3_clnt.c
     46 --- openssl-0.9.8k.orig/ssl/s3_clnt.c	2009-02-14 13:50:14.000000000 -0800
     47 +++ openssl-0.9.8k/ssl/s3_clnt.c	2009-10-05 17:00:24.000000000 -0700
     48 @@ -186,6 +186,20 @@ int ssl3_connect(SSL *s)
     49  	
     50  	s->in_handshake++;
     51  	if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); 
     52 +	if (SSL_get_mode(s) & SSL_MODE_HANDSHAKE_CUTTHROUGH)
     53 +		{
     54 +		/* Renegotiation complicates the state machine */
     55 +		s->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;
     56 +#if 0	/* Send app data in separate packet, otherwise, some particular site
     57 +	 * (only one site so far) closes the socket.
     58 +	 * Note: there is a very small chance that two TCP packets
     59 +	 * could be arriving at server combined into a single TCP packet,
     60 +	 * then trigger that site to break. We haven't encounter that though.
     61 +	 */
     62 +		/* Send app data along with CCS/Finished */
     63 +		s->s3->flags |= SSL3_FLAGS_DELAY_CLIENT_FINISHED;
     64 +#endif
     65 +		}
     66  
     67  	for (;;)
     68  		{
     69 @@ -454,14 +468,29 @@ int ssl3_connect(SSL *s)
     70  				}
     71  			else
     72  				{
     73 -#ifndef OPENSSL_NO_TLSEXT
     74 -				/* Allow NewSessionTicket if ticket expected */
     75 -				if (s->tlsext_ticket_expected)
     76 -					s->s3->tmp.next_state=SSL3_ST_CR_SESSION_TICKET_A;
     77 +				if ((SSL_get_mode(s) & SSL_MODE_HANDSHAKE_CUTTHROUGH) && SSL_get_cipher_bits(s, NULL) >= 128)
     78 +					{
     79 +					if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
     80 +						{
     81 +						s->state=SSL3_ST_CUTTHROUGH_COMPLETE;
     82 +						s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
     83 +						s->s3->delay_buf_pop_ret=0;
     84 +						}
     85 +					else
     86 +						{
     87 +						s->s3->tmp.next_state=SSL3_ST_CUTTHROUGH_COMPLETE;
     88 +						}
     89 +					}
     90  				else
     91 +					{
     92 +#ifndef OPENSSL_NO_TLSEXT
     93 +					/* Allow NewSessionTicket if ticket expected */
     94 +					if (s->tlsext_ticket_expected)
     95 +						s->s3->tmp.next_state=SSL3_ST_CR_SESSION_TICKET_A;
     96 +					else
     97  #endif
     98 -				
     99 -				s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
    100 +						s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
    101 +					}
    102  				}
    103  			s->init_num=0;
    104  			break;
    105 @@ -512,6 +541,24 @@ int ssl3_connect(SSL *s)
    106  			s->state=s->s3->tmp.next_state;
    107  			break;
    108  
    109 +		case SSL3_ST_CUTTHROUGH_COMPLETE:
    110 +#ifndef OPENSSL_NO_TLSEXT
    111 +			/* Allow NewSessionTicket if ticket expected */
    112 +			if (s->tlsext_ticket_expected)
    113 +				s->state=SSL3_ST_CR_SESSION_TICKET_A;
    114 +			else
    115 +#endif
    116 +				s->state=SSL3_ST_CR_FINISHED_A;
    117 +
    118 +			/* SSL_write() will take care of flushing buffered data if
    119 +			 * DELAY_CLIENT_FINISHED is set.
    120 +			 */
    121 +			if (!(s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED))
    122 +				ssl_free_wbio_buffer(s);
    123 +			ret = 1;
    124 +			goto end;
    125 +			/* break; */
    126 +
    127  		case SSL_ST_OK:
    128  			/* clean a few things up */
    129  			ssl3_cleanup_key_block(s);
    130 diff -uarp openssl-0.9.8k.orig/ssl/s3_lib.c openssl-0.9.8k/ssl/s3_lib.c
    131 --- openssl-0.9.8k.orig/ssl/s3_lib.c	2008-06-16 09:56:41.000000000 -0700
    132 +++ openssl-0.9.8k/ssl/s3_lib.c	2009-10-05 17:00:24.000000000 -0700
    133 @@ -2551,9 +2551,22 @@ int ssl3_write(SSL *s, const void *buf, 
    134  
    135  static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
    136  	{
    137 -	int ret;
    138 +	int n,ret;
    139  	
    140  	clear_sys_error();
    141 +	if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
    142 +		{
    143 +		/* Deal with an application that calls SSL_read() when handshake data
    144 +		 * is yet to be written.
    145 +		 */
    146 +		if (BIO_wpending(s->wbio) > 0)
    147 +			{
    148 +			s->rwstate=SSL_WRITING;
    149 +			n=BIO_flush(s->wbio);
    150 +			if (n <= 0) return(n);
    151 +			s->rwstate=SSL_NOTHING;
    152 +			}
    153 +		}
    154  	if (s->s3->renegotiate) ssl3_renegotiate_check(s);
    155  	s->s3->in_read_app_data=1;
    156  	ret=s->method->ssl_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
    157 diff -uarp openssl-0.9.8k.orig/ssl/ssl.h openssl-0.9.8k/ssl/ssl.h
    158 --- openssl-0.9.8k.orig/ssl/ssl.h	2009-10-05 17:00:39.000000000 -0700
    159 +++ openssl-0.9.8k/ssl/ssl.h	2009-10-05 17:00:24.000000000 -0700
    160 @@ -557,6 +557,10 @@ typedef struct ssl_session_st
    161  /* Use small read and write buffers: (a) lazy allocate read buffers for
    162   * large incoming records, and (b) limit the size of outgoing records. */
    163  #define SSL_MODE_SMALL_BUFFERS 0x00000010L
    164 +/* When set, clients may send application data before receipt of CCS
    165 + * and Finished.  This mode enables full-handshakes to 'complete' in
    166 + * one RTT. */
    167 +#define SSL_MODE_HANDSHAKE_CUTTHROUGH 0x00000020L
    168  
    169  /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
    170   * they cannot be used to clear bits. */
    171 @@ -1097,10 +1101,12 @@ extern "C" {
    172  /* Is the SSL_connection established? */
    173  #define SSL_get_state(a)		SSL_state(a)
    174  #define SSL_is_init_finished(a)		(SSL_state(a) == SSL_ST_OK)
    175 -#define SSL_in_init(a)			(SSL_state(a)&SSL_ST_INIT)
    176 +#define SSL_in_init(a)			((SSL_state(a)&SSL_ST_INIT) && \
    177 +                                  !SSL_cutthrough_complete(a))
    178  #define SSL_in_before(a)		(SSL_state(a)&SSL_ST_BEFORE)
    179  #define SSL_in_connect_init(a)		(SSL_state(a)&SSL_ST_CONNECT)
    180  #define SSL_in_accept_init(a)		(SSL_state(a)&SSL_ST_ACCEPT)
    181 +int SSL_cutthrough_complete(const SSL *s);
    182  
    183  /* The following 2 states are kept in ssl->rstate when reads fail,
    184   * you should not need these */
    185 Only in openssl-0.9.8k/ssl: ssl.h.orig
    186 diff -uarp openssl-0.9.8k.orig/ssl/ssl3.h openssl-0.9.8k/ssl/ssl3.h
    187 --- openssl-0.9.8k.orig/ssl/ssl3.h	2009-10-05 17:00:39.000000000 -0700
    188 +++ openssl-0.9.8k/ssl/ssl3.h	2009-10-05 17:00:24.000000000 -0700
    189 @@ -456,6 +456,7 @@ typedef struct ssl3_state_st
    190  /*client */
    191  /* extra state */
    192  #define SSL3_ST_CW_FLUSH		(0x100|SSL_ST_CONNECT)
    193 +#define SSL3_ST_CUTTHROUGH_COMPLETE	(0x101|SSL_ST_CONNECT)
    194  /* write to server */
    195  #define SSL3_ST_CW_CLNT_HELLO_A		(0x110|SSL_ST_CONNECT)
    196  #define SSL3_ST_CW_CLNT_HELLO_B		(0x111|SSL_ST_CONNECT)
    197 diff -uarp openssl-0.9.8k.orig/ssl/ssl_lib.c openssl-0.9.8k/ssl/ssl_lib.c
    198 --- openssl-0.9.8k.orig/ssl/ssl_lib.c	2009-02-23 08:02:47.000000000 -0800
    199 +++ openssl-0.9.8k/ssl/ssl_lib.c	2009-10-05 17:00:24.000000000 -0700
    200 @@ -2696,7 +2696,17 @@ void SSL_set_msg_callback(SSL *ssl, void
    201  	SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
    202  	}
    203  
    204 -
    205 +int SSL_cutthrough_complete(const SSL *s)
    206 +	{
    207 +	return (!s->server &&                 /* cutthrough only applies to clients */
    208 +		!s->hit &&                        /* full-handshake */
    209 +		s->version >= SSL3_VERSION &&
    210 +		s->s3->in_read_app_data == 0 &&   /* cutthrough only applies to write() */
    211 +		(SSL_get_mode((SSL*)s) & SSL_MODE_HANDSHAKE_CUTTHROUGH) &&  /* cutthrough enabled */
    212 +		SSL_get_cipher_bits(s, NULL) >= 128 &&                      /* strong cipher choosen */
    213 +		(s->state == SSL3_ST_CR_SESSION_TICKET_A ||                 /* ready to write app-data*/
    214 +			s->state == SSL3_ST_CR_FINISHED_A));
    215 +	}
    216  
    217  #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16)
    218  #include "../crypto/bio/bss_file.c"
    219 Only in openssl-0.9.8k/ssl: ssl_lib.c.orig
    220 diff -uarp openssl-0.9.8k.orig/ssl/ssltest.c openssl-0.9.8k/ssl/ssltest.c
    221 --- openssl-0.9.8k.orig/ssl/ssltest.c	2009-10-05 17:00:39.000000000 -0700
    222 +++ openssl-0.9.8k/ssl/ssltest.c	2009-10-05 17:00:24.000000000 -0700
    223 @@ -279,6 +279,7 @@ static void sv_usage(void)
    224  	fprintf(stderr," -test_cipherlist - verifies the order of the ssl cipher lists\n");
    225  	fprintf(stderr," -c_small_records - enable client side use of small SSL record buffers\n");
    226  	fprintf(stderr," -s_small_records - enable server side use of small SSL record buffers\n");
    227 +	fprintf(stderr," -cutthrough      - enable 1-RTT full-handshake for strong ciphers\n");
    228  	}
    229  
    230  static void print_details(SSL *c_ssl, const char *prefix)
    231 @@ -436,6 +437,7 @@ int main(int argc, char *argv[])
    232  	int ssl_mode = 0;
    233  	int c_small_records=0;
    234  	int s_small_records=0;
    235 +	int cutthrough = 0;
    236  
    237  	verbose = 0;
    238  	debug = 0;
    239 @@ -632,6 +634,10 @@ int main(int argc, char *argv[])
    240  			{
    241  			s_small_records = 1;
    242  			}
    243 +		else if (strcmp(*argv, "-cutthrough") == 0)
    244 +			{
    245 +			cutthrough = 1;
    246 +			}
    247  		else
    248  			{
    249  			fprintf(stderr,"unknown option %s\n",*argv);
    250 @@ -782,6 +788,13 @@ bad:
    251  		ssl_mode |= SSL_MODE_SMALL_BUFFERS;
    252  		SSL_CTX_set_mode(s_ctx, ssl_mode);
    253  		}
    254 +	ssl_mode = 0;
    255 +	if (cutthrough)
    256 +		{
    257 +		ssl_mode = SSL_CTX_get_mode(c_ctx);
    258 +		ssl_mode = SSL_MODE_HANDSHAKE_CUTTHROUGH;
    259 +		SSL_CTX_set_mode(c_ctx, ssl_mode);
    260 +		}
    261  
    262  #ifndef OPENSSL_NO_DH
    263  	if (!no_dhe)
    264 diff -uarp openssl-0.9.8k.orig/test/testssl openssl-0.9.8k/test/testssl
    265 --- openssl-0.9.8k.orig/test/testssl	2009-10-05 17:00:39.000000000 -0700
    266 +++ openssl-0.9.8k/test/testssl	2009-10-05 17:00:24.000000000 -0700
    267 @@ -79,6 +79,8 @@ $ssltest -server_auth -client_auth -s_sm
    268  echo test sslv2/sslv3 with both client and server authentication and small client and server buffers
    269  $ssltest -server_auth -client_auth -c_small_records -s_small_records $CA $extra || exit 1
    270  
    271 +echo test sslv2/sslv3 with both client and server authentication and handshake cutthrough
    272 +$ssltest -server_auth -client_auth -cutthrough $CA $extra || exit 1
    273  
    274  echo test sslv2 via BIO pair
    275  $ssltest -bio_pair -ssl2 $extra || exit 1
    276