Skip to content

Commit ec48af4

Browse files
committed
Make SSL_MODE_AUTO_RETRY the default.
Without SSL_MODE_AUTO_RETRY, even blocking mode will return SSL_ERROR_WANT_{READ|WRITE} in the event of a renegotiation. The comments in the code speak only of "nasty problems" unless this is done. The original commit that added SSL_MODE_AUTO_RETRY (54f10e6adce56eb2e59936e32216162aadc5d050) gives a little more detail: The [...] behaviour is needed by applications such as s_client and s_server that use select() to determine when to use SSL_read. Without the -nbio flag, s_client will use select() to find when the socket is readable and then call SSL_read with a blocking socket. However, this will still block in the event of an incomplete record, so the delay is already unbounded. This it's very unclear what the point of this behaviour ever was. Perhaps if the read and write paths were different sockets where the read socket was non-blocking but the write socket was blocking. But that seems like an implausible situation to worry too much about. Change-Id: I9d9f2526afc2e0fd0e5440e9a047f419a2d61afa Reviewed-on: https://boringssl-review.googlesource.com/2140 Reviewed-by: Adam Langley <[email protected]>
1 parent 8cfd8ad commit ec48af4

File tree

3 files changed

+4
-69
lines changed

3 files changed

+4
-69
lines changed

include/openssl/ssl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,16 +508,17 @@ struct ssl_session_st
508508
* the misconception that non-blocking SSL_write() behaves like
509509
* non-blocking write(): */
510510
#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
511-
/* Never bother the application with retries if the transport
512-
* is blocking: */
513-
#define SSL_MODE_AUTO_RETRY 0x00000004L
514511
/* Don't attempt to automatically build certificate chain */
515512
#define SSL_MODE_NO_AUTO_CHAIN 0x00000008L
516513
/* Save RAM by releasing read and write buffers when they're empty. (SSL3 and
517514
* TLS only.) "Released" buffers are put onto a free-list in the context or
518515
* just freed (depending on the context's setting for freelist_max_len). */
519516
#define SSL_MODE_RELEASE_BUFFERS 0x00000010L
520517

518+
/* The following flags do nothing and are included only to make it easier to
519+
* compile code with BoringSSL. */
520+
#define SSL_MODE_AUTO_RETRY 0
521+
521522
/* Send the current time in the Random fields of the ClientHello and
522523
* ServerHello records for compatibility with hypothetical implementations
523524
* that require it.

ssl/d1_pkt.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -976,23 +976,6 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
976976
OPENSSL_PUT_ERROR(SSL, dtls1_read_bytes, SSL_R_SSL_HANDSHAKE_FAILURE);
977977
return(-1);
978978
}
979-
980-
if (!(s->mode & SSL_MODE_AUTO_RETRY))
981-
{
982-
if (s->s3->rbuf.left == 0) /* no read-ahead left? */
983-
{
984-
BIO *bio;
985-
/* In the case where we try to read application data,
986-
* but we trigger an SSL handshake, we return -1 with
987-
* the retry option set. Otherwise renegotiation may
988-
* cause nasty problems in the blocking world */
989-
s->rwstate=SSL_READING;
990-
bio=SSL_get_rbio(s);
991-
BIO_clear_retry_flags(bio);
992-
BIO_set_retry_read(bio);
993-
return(-1);
994-
}
995-
}
996979
}
997980
}
998981
/* we either finished a handshake or ignored the request,
@@ -1155,22 +1138,6 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
11551138
return(-1);
11561139
}
11571140

1158-
if (!(s->mode & SSL_MODE_AUTO_RETRY))
1159-
{
1160-
if (s->s3->rbuf.left == 0) /* no read-ahead left? */
1161-
{
1162-
BIO *bio;
1163-
/* In the case where we try to read application data,
1164-
* but we trigger an SSL handshake, we return -1 with
1165-
* the retry option set. Otherwise renegotiation may
1166-
* cause nasty problems in the blocking world */
1167-
s->rwstate=SSL_READING;
1168-
bio=SSL_get_rbio(s);
1169-
BIO_clear_retry_flags(bio);
1170-
BIO_set_retry_read(bio);
1171-
return(-1);
1172-
}
1173-
}
11741141
goto start;
11751142
}
11761143

ssl/s3_pkt.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,23 +1151,6 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
11511151
OPENSSL_PUT_ERROR(SSL, ssl3_read_bytes, SSL_R_SSL_HANDSHAKE_FAILURE);
11521152
return(-1);
11531153
}
1154-
1155-
if (!(s->mode & SSL_MODE_AUTO_RETRY))
1156-
{
1157-
if (s->s3->rbuf.left == 0) /* no read-ahead left? */
1158-
{
1159-
BIO *bio;
1160-
/* In the case where we try to read application data,
1161-
* but we trigger an SSL handshake, we return -1 with
1162-
* the retry option set. Otherwise renegotiation may
1163-
* cause nasty problems in the blocking world */
1164-
s->rwstate=SSL_READING;
1165-
bio=SSL_get_rbio(s);
1166-
BIO_clear_retry_flags(bio);
1167-
BIO_set_retry_read(bio);
1168-
return(-1);
1169-
}
1170-
}
11711154
}
11721155
}
11731156
/* we either finished a handshake or ignored the request,
@@ -1335,22 +1318,6 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
13351318
return(-1);
13361319
}
13371320

1338-
if (!(s->mode & SSL_MODE_AUTO_RETRY))
1339-
{
1340-
if (s->s3->rbuf.left == 0) /* no read-ahead left? */
1341-
{
1342-
BIO *bio;
1343-
/* In the case where we try to read application data,
1344-
* but we trigger an SSL handshake, we return -1 with
1345-
* the retry option set. Otherwise renegotiation may
1346-
* cause nasty problems in the blocking world */
1347-
s->rwstate=SSL_READING;
1348-
bio=SSL_get_rbio(s);
1349-
BIO_clear_retry_flags(bio);
1350-
BIO_set_retry_read(bio);
1351-
return(-1);
1352-
}
1353-
}
13541321
goto start;
13551322
}
13561323

0 commit comments

Comments
 (0)