reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DtlsTransport.hxx
Go to the documentation of this file.
1
2#if defined(HAVE_CONFIG_H)
3 #include "config.h"
4#endif
5
6#if !defined(RESIP_DTLSTRANSPORT_HXX)
7#define RESIP_DTLSTRANSPORT_HXX
8
9#ifdef USE_DTLS
10
11#ifndef RESIP_UDPTRANSPORT_HXX
13#endif
14
15#ifndef RESIP_TIMERQUEUE_HXX
17#endif
18
19#ifndef RESIP_SENDDATA_HXX
21#endif
22
23#ifndef RESIP_HEAPINSTANCECOUNTER_HXX
25#endif
26
27#include <map>
28#include <unordered_map>
29#include <openssl/ssl.h>
30
32
33#include <array>
34
35namespace resip
36{
37
38class Security;
39class TransactionMessage;
40class UdpTransport;
41class DtlsMessage;
42
44{
45 struct addr_hash
46 {
47 size_t operator()( const struct sockaddr_in sock ) const
48 {
49 return sock.sin_addr.s_addr ;
50 }
51 };
52
53 struct addr_cmp
54 {
55 bool operator()(const struct sockaddr_in& s1,
56 const struct sockaddr_in& s2) const
57 {
58 if ( ( s1.sin_addr.s_addr == s2.sin_addr.s_addr ) &&
59 ( s1.sin_port == s2.sin_port) )
60 {
61 return 1;
62 }
63 else
64 {
65 return 0;
66 }
67 }
68 };
69
70 public:
72 // Specify which udp port to use for send and receive
73 // interface can be an ip address or dns name. If it is an ip address,
74 // only bind to that interface.
76 int portNum,
77 IpVersion version,
78 const Data& interfaceObj,
79 Security& security,
80 const Data& sipDomain,
81 AfterSocketCreationFuncPtr socketFunc = 0,
83 const Data& certificateFilename = "",
84 const Data& privateKeyFilename = "",
85 const Data& privateKeyPassPhrase = "");
86 virtual ~DtlsTransport();
87
88 void process(FdSet& fdset);
89 bool isReliable() const { return false; }
90 bool isDatagram() const { return true; }
91 virtual void buildFdSet( FdSet& fdset);
92
93 static const unsigned long DtlsReceiveTimeout = 250000 ;
94
95 private:
96
97 typedef std::unordered_map<struct sockaddr_in,
98 SSL*,
99 DtlsTransport::addr_hash,
100 DtlsTransport::addr_cmp> DtlsConnectionMap ;
101
102 SSL_CTX *mClientCtx ;
103 SSL_CTX *mServerCtx ;
104 MsgHeaderScanner mMsgHeaderScanner;
105 Fifo<DtlsMessage> mHandshakePending ;
106 DtlsTimerQueue mTimer ;
107 Security* mSecurity ;
108 DtlsConnectionMap mDtlsConnections ; /* IP addr/port -> transport */
109 BIO* mDummyBio ;
110 const Data mDomain;
111
112 SendData *mSendData ;/* Data that was unqueued from mTxFifo,
113 * but unable to send because a handshake
114 * was in progress
115 */
116
117 void _read();
118 void _write( FdSet& fdset ) ;
119 void _doHandshake() ;
120 void _cleanupConnectionState( SSL *ssl, struct sockaddr_in peer ) ;
121
122 void _mapDebug( const char *where, const char *action, SSL *ssl ) ;
123 void _printSock( const struct sockaddr_in *sock ) ;
124
125 std::array<char, MaxMessageSize> mRxSslBuffer{};
126};
127
128}
129
130#endif /* USE_DTLS */
131
132#endif /* ! RESIP_DTLSTRANSPORT_HXX */
133
134/* ====================================================================
135 * The Vovida Software License, Version 1.0
136 *
137 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
138 *
139 * Redistribution and use in source and binary forms, with or without
140 * modification, are permitted provided that the following conditions
141 * are met:
142 *
143 * 1. Redistributions of source code must retain the above copyright
144 * notice, this list of conditions and the following disclaimer.
145 *
146 * 2. Redistributions in binary form must reproduce the above copyright
147 * notice, this list of conditions and the following disclaimer in
148 * the documentation and/or other materials provided with the
149 * distribution.
150 *
151 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
152 * and "Vovida Open Communication Application Library (VOCAL)" must
153 * not be used to endorse or promote products derived from this
154 * software without prior written permission. For written
155 * permission, please contact vocal@vovida.org.
156 *
157 * 4. Products derived from this software may not be called "VOCAL", nor
158 * may "VOCAL" appear in their name, without prior written
159 * permission of Vovida Networks, Inc.
160 *
161 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
162 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
163 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
164 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
165 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
166 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
167 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
168 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
169 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
170 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
171 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
172 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
173 * DAMAGE.
174 *
175 * ====================================================================
176 *
177 * This software consists of voluntary contributions made by Vovida
178 * Networks, Inc. and many individuals on behalf of Vovida Networks,
179 * Inc. For more information on Vovida Networks, Inc., please see
180 * <http://www.vovida.org/>.
181 *
182 */
struct ssl_ctx_st SSL_CTX
struct ssl_st SSL
static Compression Disabled
Represents a compression configuration object with compression disabled.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
RESIP_HeapCount(DtlsTransport)
static const unsigned long DtlsReceiveTimeout
virtual void buildFdSet(FdSet &fdset)
Adds the Transport's socket FD to the appropriate read or write sets as applicable.
Object-oriented wrapper for your platform's file-descriptor set.
Definition Socket.hxx:162
A templated, threadsafe message-queue class.
Definition Fifo.hxx:16
A Transport based on UDP.
virtual void process()
Called after a message is added.
dcm! – add UnusedChecking(_enum) below;
void(* AfterSocketCreationFuncPtr)(Socket s, int transportType, const char *file, int line)
Definition Socket.hxx:107
IpVersion
An enumeration of IP versions.
void list()
Definition userAdmin.cxx:66