Blame SOURCES/openssl-1.0.1e-sctp-updates.patch

1c5d99
diff -up openssl-1.0.1e/crypto/bio/bio.h.sctp openssl-1.0.1e/crypto/bio/bio.h
1c5d99
--- openssl-1.0.1e/crypto/bio/bio.h.sctp	2016-04-07 13:54:03.296270801 +0200
1c5d99
+++ openssl-1.0.1e/crypto/bio/bio.h	2016-04-07 14:02:53.436214294 +0200
1c5d99
@@ -175,6 +175,8 @@ extern "C" {
1c5d99
 #define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT   45 /* Next DTLS handshake timeout to
1c5d99
                                               * adjust socket timeouts */
1c5d99
 
1c5d99
+#define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD   49
1c5d99
+
1c5d99
 #ifndef OPENSSL_NO_SCTP
1c5d99
 /* SCTP stuff */
1c5d99
 #define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE	50
1c5d99
@@ -607,6 +609,8 @@ int BIO_ctrl_reset_read_request(BIO *b);
1c5d99
          (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)peer)
1c5d99
 #define BIO_dgram_set_peer(b,peer) \
1c5d99
          (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer)
1c5d99
+#define BIO_dgram_get_mtu_overhead(b) \
1c5d99
+         (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU_OVERHEAD, 0, NULL)
1c5d99
 
1c5d99
 /* These two aren't currently implemented */
1c5d99
 /* int BIO_get_ex_num(BIO *bio); */
1c5d99
diff -up openssl-1.0.1e/crypto/bio/bss_dgram.c.sctp openssl-1.0.1e/crypto/bio/bss_dgram.c
1c5d99
--- openssl-1.0.1e/crypto/bio/bss_dgram.c.sctp	2013-02-11 16:26:04.000000000 +0100
1c5d99
+++ openssl-1.0.1e/crypto/bio/bss_dgram.c	2016-04-07 14:02:53.437214317 +0200
1c5d99
@@ -454,6 +454,36 @@ static int dgram_write(BIO *b, const cha
1c5d99
 	return(ret);
1c5d99
 	}
1c5d99
 
1c5d99
+static long dgram_get_mtu_overhead(bio_dgram_data *data)
1c5d99
+	{
1c5d99
+	long ret;
1c5d99
+
1c5d99
+	switch (data->peer.sa.sa_family)
1c5d99
+		{
1c5d99
+		case AF_INET:
1c5d99
+			/* Assume this is UDP - 20 bytes for IP, 8 bytes for UDP */
1c5d99
+			ret = 28;
1c5d99
+			break;
1c5d99
+#if OPENSSL_USE_IPV6
1c5d99
+		case AF_INET6:
1c5d99
+#ifdef IN6_IS_ADDR_V4MAPPED
1c5d99
+			if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
1c5d99
+				/* Assume this is UDP - 20 bytes for IP, 8 bytes for UDP */
1c5d99
+				ret = 28;
1c5d99
+			else
1c5d99
+#endif
1c5d99
+				/* Assume this is UDP - 40 bytes for IP, 8 bytes for UDP */
1c5d99
+				ret = 48;
1c5d99
+			break;
1c5d99
+#endif
1c5d99
+		default:
1c5d99
+			/* We don't know. Go with the historical default */
1c5d99
+			ret = 28;
1c5d99
+			break;
1c5d99
+		}
1c5d99
+	return ret;
1c5d99
+	}
1c5d99
+
1c5d99
 static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
1c5d99
 	{
1c5d99
 	long ret=1;
1c5d99
@@ -630,23 +660,24 @@ static long dgram_ctrl(BIO *b, int cmd,
1c5d99
 #endif
1c5d99
 		break;
1c5d99
 	case BIO_CTRL_DGRAM_GET_FALLBACK_MTU:
1c5d99
+		ret = -dgram_get_mtu_overhead(data);
1c5d99
 		switch (data->peer.sa.sa_family)
1c5d99
 			{
1c5d99
 			case AF_INET:
1c5d99
-				ret = 576 - 20 - 8;
1c5d99
+				ret += 576;
1c5d99
 				break;
1c5d99
 #if OPENSSL_USE_IPV6
1c5d99
 			case AF_INET6:
1c5d99
 #ifdef IN6_IS_ADDR_V4MAPPED
1c5d99
 				if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
1c5d99
-					ret = 576 - 20 - 8;
1c5d99
+					ret += 576;
1c5d99
 				else
1c5d99
 #endif
1c5d99
-					ret = 1280 - 40 - 8;
1c5d99
+					ret += 1280;
1c5d99
 				break;
1c5d99
 #endif
1c5d99
 			default:
1c5d99
-				ret = 576 - 20 - 8;
1c5d99
+				ret += 576;
1c5d99
 				break;
1c5d99
 			}
1c5d99
 		break;
1c5d99
@@ -847,6 +878,9 @@ static long dgram_ctrl(BIO *b, int cmd,
1c5d99
 			ret = 0;
1c5d99
 		break;
1c5d99
 #endif
1c5d99
+	case BIO_CTRL_DGRAM_GET_MTU_OVERHEAD:
1c5d99
+		ret = dgram_get_mtu_overhead(data);
1c5d99
+		break;
1c5d99
 	default:
1c5d99
 		ret=0;
1c5d99
 		break;
1c5d99
@@ -906,8 +940,8 @@ BIO *BIO_new_dgram_sctp(int fd, int clos
1c5d99
 	memset(authchunks, 0, sizeof(sockopt_len));
1c5d99
 	ret = getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks, &sockopt_len);
1c5d99
 	OPENSSL_assert(ret >= 0);
1c5d99
-	
1c5d99
-	for (p = (unsigned char*) authchunks + sizeof(sctp_assoc_t);
1c5d99
+
1c5d99
+	for (p = (unsigned char*) authchunks->gauth_chunks;
1c5d99
 	     p < (unsigned char*) authchunks + sockopt_len;
1c5d99
 	     p += sizeof(uint8_t))
1c5d99
 		{
1c5d99
@@ -1197,7 +1231,7 @@ static int dgram_sctp_read(BIO *b, char
1c5d99
 			ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, authchunks, &optlen);
1c5d99
 			OPENSSL_assert(ii >= 0);
1c5d99
 
1c5d99
-			for (p = (unsigned char*) authchunks + sizeof(sctp_assoc_t);
1c5d99
+			for (p = (unsigned char*) authchunks->gauth_chunks;
1c5d99
 				 p < (unsigned char*) authchunks + optlen;
1c5d99
 				 p += sizeof(uint8_t))
1c5d99
 				{
1c5d99
@@ -1367,6 +1401,10 @@ static long dgram_sctp_ctrl(BIO *b, int
1c5d99
 		 * Returns always 1.
1c5d99
 		 */
1c5d99
 		break;
1c5d99
+	case BIO_CTRL_DGRAM_GET_MTU_OVERHEAD:
1c5d99
+		/* We allow transport protocol fragmentation so this is irrelevant */
1c5d99
+		ret = 0;
1c5d99
+		break;
1c5d99
 	case BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE:
1c5d99
 		if (num > 0)
1c5d99
 			data->in_handshake = 1;
1c5d99
@@ -1399,6 +1437,7 @@ static long dgram_sctp_ctrl(BIO *b, int
1c5d99
 		memcpy(&authkey->sca_key[0], ptr, 64 * sizeof(uint8_t));
1c5d99
 
1c5d99
 		ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len);
1c5d99
+		OPENSSL_free(authkey);
1c5d99
 		if (ret < 0) break;
1c5d99
 
1c5d99
 		/* Reset active key */
1c5d99
diff -up openssl-1.0.1e/ssl/d1_both.c.sctp openssl-1.0.1e/ssl/d1_both.c
1c5d99
--- openssl-1.0.1e/ssl/d1_both.c.sctp	2016-04-07 14:09:35.193261496 +0200
1c5d99
+++ openssl-1.0.1e/ssl/d1_both.c	2016-04-07 14:11:18.838592357 +0200
1c5d99
@@ -1458,14 +1458,17 @@ int dtls1_shutdown(SSL *s)
1c5d99
 	{
1c5d99
 	int ret;
1c5d99
 #ifndef OPENSSL_NO_SCTP
1c5d99
-	if (BIO_dgram_is_sctp(SSL_get_wbio(s)) &&
1c5d99
+	BIO *wbio;
1c5d99
+
1c5d99
+	wbio = SSL_get_wbio(s);
1c5d99
+	if (wbio != NULL && BIO_dgram_is_sctp(wbio) &&
1c5d99
 	    !(s->shutdown & SSL_SENT_SHUTDOWN))
1c5d99
 		{
1c5d99
-		ret = BIO_dgram_sctp_wait_for_dry(SSL_get_wbio(s));
1c5d99
+		ret = BIO_dgram_sctp_wait_for_dry(wbio);
1c5d99
 		if (ret < 0) return -1;
1c5d99
 
1c5d99
 		if (ret == 0)
1c5d99
-			BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN, 1, NULL);
1c5d99
+			BIO_ctrl(wbio, BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN, 1, NULL);
1c5d99
 		}
1c5d99
 #endif
1c5d99
 	ret = ssl3_shutdown(s);
1c5d99
diff -up openssl-1.0.1e/ssl/d1_clnt.c.sctp openssl-1.0.1e/ssl/d1_clnt.c
1c5d99
--- openssl-1.0.1e/ssl/d1_clnt.c.sctp	2016-04-07 13:54:03.505275509 +0200
1c5d99
+++ openssl-1.0.1e/ssl/d1_clnt.c	2016-04-07 14:06:48.581511870 +0200
1c5d99
@@ -338,9 +338,13 @@ int dtls1_connect(SSL *s)
1c5d99
 					snprintf((char*) labelbuffer, sizeof(DTLS1_SCTP_AUTH_LABEL),
1c5d99
 					         DTLS1_SCTP_AUTH_LABEL);
1c5d99
 
1c5d99
-					SSL_export_keying_material(s, sctpauthkey,
1c5d99
+					if (SSL_export_keying_material(s, sctpauthkey,
1c5d99
 					                           sizeof(sctpauthkey), labelbuffer,
1c5d99
-					                           sizeof(labelbuffer), NULL, 0, 0);
1c5d99
+					                           sizeof(labelbuffer), NULL, 0, 0) <= 0)
1c5d99
+						{
1c5d99
+						ret = -1;
1c5d99
+						goto end;
1c5d99
+						}
1c5d99
 
1c5d99
 					BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY,
1c5d99
 							 sizeof(sctpauthkey), sctpauthkey);
1c5d99
@@ -479,9 +483,13 @@ int dtls1_connect(SSL *s)
1c5d99
 			snprintf((char*) labelbuffer, sizeof(DTLS1_SCTP_AUTH_LABEL),
1c5d99
 			         DTLS1_SCTP_AUTH_LABEL);
1c5d99
 
1c5d99
-			SSL_export_keying_material(s, sctpauthkey,
1c5d99
+			if (SSL_export_keying_material(s, sctpauthkey,
1c5d99
 			                           sizeof(sctpauthkey), labelbuffer,
1c5d99
-			                           sizeof(labelbuffer), NULL, 0, 0);
1c5d99
+			                           sizeof(labelbuffer), NULL, 0, 0) <= 0)
1c5d99
+				{
1c5d99
+				ret = -1;
1c5d99
+				goto end;
1c5d99
+				}
1c5d99
 
1c5d99
 			BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY,
1c5d99
 					 sizeof(sctpauthkey), sctpauthkey);
1c5d99
@@ -538,13 +546,6 @@ int dtls1_connect(SSL *s)
1c5d99
 				SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
1c5d99
 			if (ret <= 0) goto end;
1c5d99
 
1c5d99
-#ifndef OPENSSL_NO_SCTP
1c5d99
-			/* Change to new shared key of SCTP-Auth,
1c5d99
-			 * will be ignored if no SCTP used.
1c5d99
-			 */
1c5d99
-			BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY, 0, NULL);
1c5d99
-#endif
1c5d99
-
1c5d99
 			s->state=SSL3_ST_CW_FINISHED_A;
1c5d99
 			s->init_num=0;
1c5d99
 
1c5d99
@@ -571,6 +572,16 @@ int dtls1_connect(SSL *s)
1c5d99
 				goto end;
1c5d99
 				}
1c5d99
 			
1c5d99
+#ifndef OPENSSL_NO_SCTP
1c5d99
+				if (s->hit)
1c5d99
+					{
1c5d99
+					/* Change to new shared key of SCTP-Auth,
1c5d99
+					 * will be ignored if no SCTP used.
1c5d99
+					 */
1c5d99
+					BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY, 0, NULL);
1c5d99
+					}
1c5d99
+#endif
1c5d99
+
1c5d99
 			dtls1_reset_seq_numbers(s, SSL3_CC_WRITE);
1c5d99
 			break;
1c5d99
 
1c5d99
@@ -613,6 +624,13 @@ int dtls1_connect(SSL *s)
1c5d99
 				}
1c5d99
 			else
1c5d99
 				{
1c5d99
+#ifndef OPENSSL_NO_SCTP
1c5d99
+				/* Change to new shared key of SCTP-Auth,
1c5d99
+				 * will be ignored if no SCTP used.
1c5d99
+				 */
1c5d99
+				BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY, 0, NULL);
1c5d99
+#endif
1c5d99
+
1c5d99
 #ifndef OPENSSL_NO_TLSEXT
1c5d99
 				/* Allow NewSessionTicket if ticket expected */
1c5d99
 				if (s->tlsext_ticket_expected)
1c5d99
diff -up openssl-1.0.1e/ssl/d1_srvr.c.sctp openssl-1.0.1e/ssl/d1_srvr.c
1c5d99
--- openssl-1.0.1e/ssl/d1_srvr.c.sctp	2016-04-07 13:54:03.529276050 +0200
1c5d99
+++ openssl-1.0.1e/ssl/d1_srvr.c	2016-04-07 14:08:56.110382568 +0200
1c5d99
@@ -395,9 +395,13 @@ int dtls1_accept(SSL *s)
1c5d99
 				snprintf((char*) labelbuffer, sizeof(DTLS1_SCTP_AUTH_LABEL),
1c5d99
 				         DTLS1_SCTP_AUTH_LABEL);
1c5d99
 
1c5d99
-				SSL_export_keying_material(s, sctpauthkey,
1c5d99
+				if (SSL_export_keying_material(s, sctpauthkey,
1c5d99
 				                           sizeof(sctpauthkey), labelbuffer,
1c5d99
-				                           sizeof(labelbuffer), NULL, 0, 0);
1c5d99
+				                           sizeof(labelbuffer), NULL, 0, 0) <= 0)
1c5d99
+					{
1c5d99
+					ret = -1;
1c5d99
+					goto end;
1c5d99
+					}
1c5d99
 				
1c5d99
 				BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY,
1c5d99
                          sizeof(sctpauthkey), sctpauthkey);
1c5d99
@@ -609,9 +613,13 @@ int dtls1_accept(SSL *s)
1c5d99
 			snprintf((char *) labelbuffer, sizeof(DTLS1_SCTP_AUTH_LABEL),
1c5d99
 			         DTLS1_SCTP_AUTH_LABEL);
1c5d99
 
1c5d99
-			SSL_export_keying_material(s, sctpauthkey,
1c5d99
+			if (SSL_export_keying_material(s, sctpauthkey,
1c5d99
 			                           sizeof(sctpauthkey), labelbuffer,
1c5d99
-			                           sizeof(labelbuffer), NULL, 0, 0);
1c5d99
+			                           sizeof(labelbuffer), NULL, 0, 0) <= 0)
1c5d99
+				{
1c5d99
+				ret = -1;
1c5d99
+				goto end;
1c5d99
+				}
1c5d99
 
1c5d99
 			BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY,
1c5d99
 			         sizeof(sctpauthkey), sctpauthkey);
1c5d99
@@ -713,10 +721,13 @@ int dtls1_accept(SSL *s)
1c5d99
 			if (ret <= 0) goto end;
1c5d99
 
1c5d99
 #ifndef OPENSSL_NO_SCTP
1c5d99
-			/* Change to new shared key of SCTP-Auth,
1c5d99
-			 * will be ignored if no SCTP used.
1c5d99
-			 */
1c5d99
-			BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY, 0, NULL);
1c5d99
+			if (!s->hit)
1c5d99
+				{
1c5d99
+				/* Change to new shared key of SCTP-Auth,
1c5d99
+				 * will be ignored if no SCTP used.
1c5d99
+				 */
1c5d99
+				BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY, 0, NULL);
1c5d99
+				}
1c5d99
 #endif
1c5d99
 
1c5d99
 			s->state=SSL3_ST_SW_FINISHED_A;
1c5d99
@@ -741,7 +752,16 @@ int dtls1_accept(SSL *s)
1c5d99
 			if (ret <= 0) goto end;
1c5d99
 			s->state=SSL3_ST_SW_FLUSH;
1c5d99
 			if (s->hit)
1c5d99
+				{
1c5d99
 				s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
1c5d99
+
1c5d99
+#ifndef OPENSSL_NO_SCTP
1c5d99
+				/* Change to new shared key of SCTP-Auth,
1c5d99
+				 * will be ignored if no SCTP used.
1c5d99
+				 */
1c5d99
+				BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY, 0, NULL);
1c5d99
+#endif
1c5d99
+				}
1c5d99
 			else
1c5d99
 				{
1c5d99
 				s->s3->tmp.next_state=SSL_ST_OK;