From 43e9e1a16054e50a850c3d884e0d432b532fc90d Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Wed, 9 Sep 2009 17:06:13 +0000 Subject: [PATCH] PR: 2033 Submitted by: Robin Seggelmann Approved by: steve@openssl.org DTLS listen support. --- ssl/d1_lib.c | 18 ++++++++++++++++++ ssl/d1_srvr.c | 9 +++++++++ ssl/dtls1.h | 3 +++ ssl/ssl.h | 3 +++ 4 files changed, 33 insertions(+) diff --git a/ssl/d1_lib.c b/ssl/d1_lib.c index 183717624c..63bfbacc82 100644 --- a/ssl/d1_lib.c +++ b/ssl/d1_lib.c @@ -68,6 +68,7 @@ static void get_current_time(struct timeval *t); const char dtls1_version_str[]="DTLSv1" OPENSSL_VERSION_PTEXT; +int dtls1_listen(SSL *s, struct sockaddr *client); SSL3_ENC_METHOD DTLSv1_enc_data={ dtls1_enc, @@ -225,6 +226,9 @@ long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg) case DTLS_CTRL_HANDLE_TIMEOUT: ret = dtls1_handle_timeout(s); break; + case DTLS_CTRL_LISTEN: + ret = dtls1_listen(s, parg); + break; default: ret = ssl3_ctrl(s, cmd, larg, parg); @@ -386,3 +390,17 @@ static void get_current_time(struct timeval *t) gettimeofday(t, NULL); #endif } + +int dtls1_listen(SSL *s, struct sockaddr *client) + { + int ret; + + SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE); + s->d1->listen = 1; + + ret = SSL_accept(s); + if (ret <= 0) return ret; + + (void) BIO_dgram_get_peer(SSL_get_rbio(s), client); + return 1; + } diff --git a/ssl/d1_srvr.c b/ssl/d1_srvr.c index 526cc9c745..9098e2eb5a 100644 --- a/ssl/d1_srvr.c +++ b/ssl/d1_srvr.c @@ -272,6 +272,15 @@ int dtls1_accept(SSL *s) s->state = SSL3_ST_SW_SRVR_HELLO_A; s->init_num=0; + + /* If we're just listening, stop here */ + if (s->d1->listen && s->state == SSL3_ST_SW_SRVR_HELLO_A) + { + ret = 2; + s->d1->listen = 0; + goto end; + } + break; case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A: diff --git a/ssl/dtls1.h b/ssl/dtls1.h index 8909dc9ee0..a8ce51ac3e 100644 --- a/ssl/dtls1.h +++ b/ssl/dtls1.h @@ -214,6 +214,9 @@ typedef struct dtls1_state_st */ record_pqueue buffered_app_data; + /* Is set when listening for new connections with dtls1_listen() */ + unsigned int listen; + unsigned int mtu; /* max DTLS packet size */ struct hm_header_st w_msg_hdr; diff --git a/ssl/ssl.h b/ssl/ssl.h index 9e2b439476..b60f52be5e 100644 --- a/ssl/ssl.h +++ b/ssl/ssl.h @@ -1273,11 +1273,14 @@ size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); #define DTLS_CTRL_GET_TIMEOUT 73 #define DTLS_CTRL_HANDLE_TIMEOUT 74 +#define DTLS_CTRL_LISTEN 75 #define DTLSv1_get_timeout(ssl, arg) \ SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)arg) #define DTLSv1_handle_timeout(ssl) \ SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL) +#define DTLSv1_listen(ssl, peer) \ + SSL_ctrl(ssl,DTLS_CTRL_LISTEN,0, (void *)peer) #define SSL_session_reused(ssl) \ SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL) -- 2.25.1