summaryrefslogtreecommitdiffstats
path: root/ssl/d1_lib.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2013-03-11 15:34:28 +0000
committerDr. Stephen Henson <steve@openssl.org>2013-09-18 13:46:02 +0100
commit741c9959f621a383055816cb3db37a61fee889e5 (patch)
treee2f34100481b3e36c1c240e5fbd84fe837aa5a26 /ssl/d1_lib.c
parent7c23127fde8fe94af914961eb7702caa7f256a05 (diff)
DTLS revision.
Revise DTLS code. There was a *lot* of code duplication in the DTLS code that generates records. This makes it harder to maintain and sometimes a TLS update is omitted by accident from the DTLS code. Specifically almost all of the record generation functions have code like this: some_pointer = buffer + HANDSHAKE_HEADER_LENGTH; ... Record creation stuff ... set_handshake_header(ssl, SSL_MT_SOMETHING, message_len); ... write_handshake_message(ssl); Where the "Record creation stuff" is identical between SSL/TLS and DTLS or in some cases has very minor differences. By adding a few fields to SSL3_ENC to include the header length, some flags and function pointers for handshake header setting and handshake writing the code can cope with both cases. (cherry picked from commit 173e72e64c6a07ae97660c322396b66215009f33)
Diffstat (limited to 'ssl/d1_lib.c')
-rw-r--r--ssl/d1_lib.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/ssl/d1_lib.c b/ssl/d1_lib.c
index 106939f241..f03a7ee1d8 100644
--- a/ssl/d1_lib.c
+++ b/ssl/d1_lib.c
@@ -67,6 +67,8 @@
#endif
static void get_current_time(struct timeval *t);
+static void dtls1_set_handshake_header(SSL *s, int type, unsigned long len);
+static int dtls1_handshake_write(SSL *s);
const char dtls1_version_str[]="DTLSv1" OPENSSL_VERSION_PTEXT;
int dtls1_listen(SSL *s, struct sockaddr *client);
@@ -83,6 +85,10 @@ SSL3_ENC_METHOD DTLSv1_enc_data={
TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
tls1_alert_code,
tls1_export_keying_material,
+ SSL_ENC_FLAG_DTLS|SSL_ENC_FLAG_EXPLICIT_IV,
+ DTLS1_HM_HEADER_LENGTH,
+ dtls1_set_handshake_header,
+ dtls1_handshake_write
};
long dtls1_default_timeout(void)
@@ -481,3 +487,20 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
(void) BIO_dgram_get_peer(SSL_get_rbio(s), client);
return 1;
}
+
+static void dtls1_set_handshake_header(SSL *s, int htype, unsigned long len)
+ {
+ unsigned char *p = (unsigned char *)s->init_buf->data;
+ dtls1_set_message_header(s, p, htype, len, 0, len);
+ s->init_num = (int)len + DTLS1_HM_HEADER_LENGTH;
+ s->init_off = 0;
+ /* Buffer the message to handle re-xmits */
+ dtls1_buffer_message(s, 0);
+ }
+
+static int dtls1_handshake_write(SSL *s)
+ {
+ return dtls1_do_write(s, SSL3_RT_HANDSHAKE);
+ }
+
+