summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2014-12-14 16:07:26 +0000
committerjsing <>2014-12-14 16:07:26 +0000
commit07ed3281a22942e6f12d90c428ffd29e5f4f1ddb (patch)
tree0b3f794835578b05409792e2fce6c456572f9896
parent4756f9cf06b8309fcf4d75e1791149090f6740cd (diff)
downloadopenbsd-07ed3281a22942e6f12d90c428ffd29e5f4f1ddb.tar.gz
openbsd-07ed3281a22942e6f12d90c428ffd29e5f4f1ddb.tar.bz2
openbsd-07ed3281a22942e6f12d90c428ffd29e5f4f1ddb.zip
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@
-rw-r--r--src/lib/libssl/d1_both.c4
-rw-r--r--src/lib/libssl/s3_lib.c54
-rw-r--r--src/lib/libssl/src/ssl/d1_both.c4
-rw-r--r--src/lib/libssl/src/ssl/s3_lib.c54
-rw-r--r--src/lib/libssl/src/ssl/ssl3.h6
-rw-r--r--src/lib/libssl/ssl3.h6
6 files changed, 120 insertions, 8 deletions
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c
index 2dc26e38cb..bff683d06c 100644
--- a/src/lib/libssl/d1_both.c
+++ b/src/lib/libssl/d1_both.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_both.c,v 1.30 2014/11/16 14:12:47 jsing Exp $ */ 1/* $OpenBSD: d1_both.c,v 1.31 2014/12/14 16:07:26 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -1140,6 +1140,8 @@ dtls1_buffer_message(SSL *s, int is_ccs)
1140 hm_fragment *frag; 1140 hm_fragment *frag;
1141 unsigned char seq64be[8]; 1141 unsigned char seq64be[8];
1142 1142
1143 /* Buffer the messsage in order to handle DTLS retransmissions. */
1144
1143 /* 1145 /*
1144 * This function is called immediately after a message has 1146 * This function is called immediately after a message has
1145 * been serialized 1147 * been serialized
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 @@
1/* $OpenBSD: s3_lib.c,v 1.89 2014/12/14 15:30:50 jsing Exp $ */ 1/* $OpenBSD: s3_lib.c,v 1.90 2014/12/14 16:07:26 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1837,6 +1837,58 @@ ssl3_pending(const SSL *s)
1837 s->s3->rrec.length : 0; 1837 s->s3->rrec.length : 0;
1838} 1838}
1839 1839
1840unsigned char *
1841ssl3_handshake_msg_start(SSL *s, uint8_t msg_type)
1842{
1843 unsigned char *d, *p;
1844 int hdr_len;
1845
1846 d = p = (unsigned char *)s->init_buf->data;
1847
1848 hdr_len = SSL_IS_DTLS(s) ? DTLS1_HM_HEADER_LENGTH :
1849 SSL3_HM_HEADER_LENGTH;
1850
1851 /* Handshake message type and length. */
1852 *(p++) = msg_type;
1853 l2n3(0, p);
1854
1855 return (d + hdr_len);
1856}
1857
1858void
1859ssl3_handshake_msg_finish(SSL *s, unsigned int len)
1860{
1861 unsigned char *d, *p;
1862 uint8_t msg_type;
1863 int hdr_len;
1864
1865 d = p = (unsigned char *)s->init_buf->data;
1866
1867 hdr_len = SSL_IS_DTLS(s) ? DTLS1_HM_HEADER_LENGTH :
1868 SSL3_HM_HEADER_LENGTH;
1869
1870 /* Handshake message length. */
1871 msg_type = *(p++);
1872 l2n3(len, p);
1873
1874 s->init_num = hdr_len + (int)len;
1875 s->init_off = 0;
1876
1877 if (SSL_IS_DTLS(s)) {
1878 dtls1_set_message_header(s, d, msg_type, len, 0, len);
1879 dtls1_buffer_message(s, 0);
1880 }
1881}
1882
1883int
1884ssl3_handshake_write(SSL *s)
1885{
1886 if (SSL_IS_DTLS(s))
1887 return dtls1_do_write(s, SSL3_RT_HANDSHAKE);
1888
1889 return ssl3_do_write(s, SSL3_RT_HANDSHAKE);
1890}
1891
1840int 1892int
1841ssl3_new(SSL *s) 1893ssl3_new(SSL *s)
1842{ 1894{
diff --git a/src/lib/libssl/src/ssl/d1_both.c b/src/lib/libssl/src/ssl/d1_both.c
index 2dc26e38cb..bff683d06c 100644
--- a/src/lib/libssl/src/ssl/d1_both.c
+++ b/src/lib/libssl/src/ssl/d1_both.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_both.c,v 1.30 2014/11/16 14:12:47 jsing Exp $ */ 1/* $OpenBSD: d1_both.c,v 1.31 2014/12/14 16:07:26 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -1140,6 +1140,8 @@ dtls1_buffer_message(SSL *s, int is_ccs)
1140 hm_fragment *frag; 1140 hm_fragment *frag;
1141 unsigned char seq64be[8]; 1141 unsigned char seq64be[8];
1142 1142
1143 /* Buffer the messsage in order to handle DTLS retransmissions. */
1144
1143 /* 1145 /*
1144 * This function is called immediately after a message has 1146 * This function is called immediately after a message has
1145 * been serialized 1147 * been serialized
diff --git a/src/lib/libssl/src/ssl/s3_lib.c b/src/lib/libssl/src/ssl/s3_lib.c
index e60f004e57..f372b6523c 100644
--- a/src/lib/libssl/src/ssl/s3_lib.c
+++ b/src/lib/libssl/src/ssl/s3_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_lib.c,v 1.89 2014/12/14 15:30:50 jsing Exp $ */ 1/* $OpenBSD: s3_lib.c,v 1.90 2014/12/14 16:07:26 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1837,6 +1837,58 @@ ssl3_pending(const SSL *s)
1837 s->s3->rrec.length : 0; 1837 s->s3->rrec.length : 0;
1838} 1838}
1839 1839
1840unsigned char *
1841ssl3_handshake_msg_start(SSL *s, uint8_t msg_type)
1842{
1843 unsigned char *d, *p;
1844 int hdr_len;
1845
1846 d = p = (unsigned char *)s->init_buf->data;
1847
1848 hdr_len = SSL_IS_DTLS(s) ? DTLS1_HM_HEADER_LENGTH :
1849 SSL3_HM_HEADER_LENGTH;
1850
1851 /* Handshake message type and length. */
1852 *(p++) = msg_type;
1853 l2n3(0, p);
1854
1855 return (d + hdr_len);
1856}
1857
1858void
1859ssl3_handshake_msg_finish(SSL *s, unsigned int len)
1860{
1861 unsigned char *d, *p;
1862 uint8_t msg_type;
1863 int hdr_len;
1864
1865 d = p = (unsigned char *)s->init_buf->data;
1866
1867 hdr_len = SSL_IS_DTLS(s) ? DTLS1_HM_HEADER_LENGTH :
1868 SSL3_HM_HEADER_LENGTH;
1869
1870 /* Handshake message length. */
1871 msg_type = *(p++);
1872 l2n3(len, p);
1873
1874 s->init_num = hdr_len + (int)len;
1875 s->init_off = 0;
1876
1877 if (SSL_IS_DTLS(s)) {
1878 dtls1_set_message_header(s, d, msg_type, len, 0, len);
1879 dtls1_buffer_message(s, 0);
1880 }
1881}
1882
1883int
1884ssl3_handshake_write(SSL *s)
1885{
1886 if (SSL_IS_DTLS(s))
1887 return dtls1_do_write(s, SSL3_RT_HANDSHAKE);
1888
1889 return ssl3_do_write(s, SSL3_RT_HANDSHAKE);
1890}
1891
1840int 1892int
1841ssl3_new(SSL *s) 1893ssl3_new(SSL *s)
1842{ 1894{
diff --git a/src/lib/libssl/src/ssl/ssl3.h b/src/lib/libssl/src/ssl/ssl3.h
index 9270ded96f..b5df1056ab 100644
--- a/src/lib/libssl/src/ssl/ssl3.h
+++ b/src/lib/libssl/src/ssl/ssl3.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl3.h,v 1.31 2014/12/14 15:30:50 jsing Exp $ */ 1/* $OpenBSD: ssl3.h,v 1.32 2014/12/14 16:07:26 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -231,9 +231,11 @@ extern "C" {
231#define SSL3_RANDOM_SIZE 32 231#define SSL3_RANDOM_SIZE 32
232#define SSL3_SEQUENCE_SIZE 8 232#define SSL3_SEQUENCE_SIZE 8
233#define SSL3_SESSION_ID_SIZE 32 233#define SSL3_SESSION_ID_SIZE 32
234#define SSL3_RT_HEADER_LENGTH 5
235#define SSL3_CIPHER_VALUE_SIZE 2 234#define SSL3_CIPHER_VALUE_SIZE 2
236 235
236#define SSL3_RT_HEADER_LENGTH 5
237#define SSL3_HM_HEADER_LENGTH 4
238
237#ifndef SSL3_ALIGN_PAYLOAD 239#ifndef SSL3_ALIGN_PAYLOAD
238 /* Some will argue that this increases memory footprint, but it's 240 /* Some will argue that this increases memory footprint, but it's
239 * not actually true. Point is that malloc has to return at least 241 * not actually true. Point is that malloc has to return at least
diff --git a/src/lib/libssl/ssl3.h b/src/lib/libssl/ssl3.h
index 9270ded96f..b5df1056ab 100644
--- a/src/lib/libssl/ssl3.h
+++ b/src/lib/libssl/ssl3.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl3.h,v 1.31 2014/12/14 15:30:50 jsing Exp $ */ 1/* $OpenBSD: ssl3.h,v 1.32 2014/12/14 16:07:26 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -231,9 +231,11 @@ extern "C" {
231#define SSL3_RANDOM_SIZE 32 231#define SSL3_RANDOM_SIZE 32
232#define SSL3_SEQUENCE_SIZE 8 232#define SSL3_SEQUENCE_SIZE 8
233#define SSL3_SESSION_ID_SIZE 32 233#define SSL3_SESSION_ID_SIZE 32
234#define SSL3_RT_HEADER_LENGTH 5
235#define SSL3_CIPHER_VALUE_SIZE 2 234#define SSL3_CIPHER_VALUE_SIZE 2
236 235
236#define SSL3_RT_HEADER_LENGTH 5
237#define SSL3_HM_HEADER_LENGTH 4
238
237#ifndef SSL3_ALIGN_PAYLOAD 239#ifndef SSL3_ALIGN_PAYLOAD
238 /* Some will argue that this increases memory footprint, but it's 240 /* Some will argue that this increases memory footprint, but it's
239 * not actually true. Point is that malloc has to return at least 241 * not actually true. Point is that malloc has to return at least