From 07ed3281a22942e6f12d90c428ffd29e5f4f1ddb Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sun, 14 Dec 2014 16:07:26 +0000 Subject: Provide functions for starting, finishing and writing SSL handshake messages. This will allow for removal of repeated/duplicated code. Additionally, DTLS was written by wholesale copying of the SSL/TLS code, with some DTLS specifics being added to the duplicated code. Since these SSL handshake message functions know how to handle both SSL/TLS and DTLS, upon conversion the duplicate versions will become identical (or close to), at which point the DTLS versions can be removed and the SSL/TLS versions used for both protocols. Partially based on similar changes in OpenSSL. ok miod@ --- src/lib/libssl/s3_lib.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/lib/libssl/s3_lib.c') diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c index e60f004e57..f372b6523c 100644 --- a/src/lib/libssl/s3_lib.c +++ b/src/lib/libssl/s3_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s3_lib.c,v 1.89 2014/12/14 15:30:50 jsing Exp $ */ +/* $OpenBSD: s3_lib.c,v 1.90 2014/12/14 16:07:26 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1837,6 +1837,58 @@ ssl3_pending(const SSL *s) s->s3->rrec.length : 0; } +unsigned char * +ssl3_handshake_msg_start(SSL *s, uint8_t msg_type) +{ + unsigned char *d, *p; + int hdr_len; + + d = p = (unsigned char *)s->init_buf->data; + + hdr_len = SSL_IS_DTLS(s) ? DTLS1_HM_HEADER_LENGTH : + SSL3_HM_HEADER_LENGTH; + + /* Handshake message type and length. */ + *(p++) = msg_type; + l2n3(0, p); + + return (d + hdr_len); +} + +void +ssl3_handshake_msg_finish(SSL *s, unsigned int len) +{ + unsigned char *d, *p; + uint8_t msg_type; + int hdr_len; + + d = p = (unsigned char *)s->init_buf->data; + + hdr_len = SSL_IS_DTLS(s) ? DTLS1_HM_HEADER_LENGTH : + SSL3_HM_HEADER_LENGTH; + + /* Handshake message length. */ + msg_type = *(p++); + l2n3(len, p); + + s->init_num = hdr_len + (int)len; + s->init_off = 0; + + if (SSL_IS_DTLS(s)) { + dtls1_set_message_header(s, d, msg_type, len, 0, len); + dtls1_buffer_message(s, 0); + } +} + +int +ssl3_handshake_write(SSL *s) +{ + if (SSL_IS_DTLS(s)) + return dtls1_do_write(s, SSL3_RT_HANDSHAKE); + + return ssl3_do_write(s, SSL3_RT_HANDSHAKE); +} + int ssl3_new(SSL *s) { -- cgit v1.2.3-55-g6feb