/[resiprocate]/main/reflow/FlowDtlsSocketContext.cxx
ViewVC logotype

Contents of /main/reflow/FlowDtlsSocketContext.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11159 - (show annotations) (download)
Fri Apr 25 14:03:32 2014 UTC (5 years, 8 months ago) by sgodin
File MIME type: text/plain
File size: 5784 byte(s)
-modified asio and boost include file ordering to avoid multiply defined symbol errors on linking
 -in preparation for upgrade of asio drop and support for latest boost 
 -include asio/ssh.hpp everywhere asio.hpp is included
 -include boost headers before others, to ensure we are not redefining stdint definitions in some includes
  and not others

1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #ifdef USE_SSL
6 #include <asio.hpp>
7 #include <asio/ssl.hpp>
8 #include <boost/function.hpp>
9 #include <iostream>
10
11 #include <rutil/Log.hxx>
12 #include <rutil/Logger.hxx>
13 #include <rutil/Timer.hxx>
14
15 #include "FlowDtlsSocketContext.hxx"
16 #include "FlowManagerSubsystem.hxx"
17
18 using namespace flowmanager;
19 using namespace resip;
20 using namespace dtls;
21 using namespace std;
22
23 #define RESIPROCATE_SUBSYSTEM FlowManagerSubsystem::FLOWMANAGER
24
25 FlowDtlsSocketContext::FlowDtlsSocketContext(Flow& flow, const asio::ip::address& address, unsigned short port)
26 : mFlow(flow), mAddress(address), mPort(port), mSrtpInitialized(false)
27 {
28 }
29
30 FlowDtlsSocketContext::~FlowDtlsSocketContext()
31 {
32 if(mSrtpInitialized)
33 {
34 // Free the master key memory allocated in DtlsSocket::createSrtpSessionPolicies
35 delete mSRTPPolicyIn.key;
36 delete mSRTPPolicyOut.key;
37 }
38 }
39
40 void
41 FlowDtlsSocketContext::write(const unsigned char* data, unsigned int len)
42 {
43 InfoLog(<< "Dtls write to " << mAddress.to_string() << ":" << mPort << " called. ComponentId=" << mFlow.getComponentId());
44 mFlow.rawSendTo(mAddress, mPort, (const char*)data, len);
45 }
46
47 void
48 FlowDtlsSocketContext::handshakeCompleted()
49 {
50 InfoLog(<< "Flow Dtls Handshake Completed! ComponentId=" << mFlow.getComponentId());
51
52 char fprint[100];
53 SRTP_PROTECTION_PROFILE *srtp_profile;
54 int r;
55
56 if(mSocket->getRemoteFingerprint(fprint))
57 {
58 Data remoteSDPFingerprint = mFlow.getRemoteSDPFingerprint();
59 if(!remoteSDPFingerprint.empty())
60 {
61 if(!mSocket->checkFingerprint(remoteSDPFingerprint.c_str(), remoteSDPFingerprint.size()))
62 {
63 InfoLog(<< "Remote fingerprint = " << fprint << " is not valid! ComponentId=" << mFlow.getComponentId());
64 return;
65 }
66 else
67 {
68 InfoLog(<< "Remote fingerprint = " << fprint << " is valid! ComponentId=" << mFlow.getComponentId());
69 }
70 }
71 else
72 {
73 InfoLog(<< "Remote fingerprint = " << fprint << " ComponentId=" << mFlow.getComponentId());
74 }
75 }
76 else
77 {
78 InfoLog(<< "Remote fingerprint cannot be obtained from Dtls handshake. ComponentId=" << mFlow.getComponentId());
79 return;
80 }
81
82 srtp_profile=mSocket->getSrtpProfile();
83
84 if(srtp_profile)
85 {
86 InfoLog(<< "SRTP Extension negotiated profile=" << srtp_profile->name << " ComponentId=" << mFlow.getComponentId());
87 }
88
89 // !slg! TODO - we should probably be basing the policy creation off of what is returned from getSrtpProfile
90 mSocket->createSrtpSessionPolicies(mSRTPPolicyOut, mSRTPPolicyIn);
91
92 r=srtp_create(&mSRTPSessionIn, &mSRTPPolicyIn);
93 assert(r==0);
94 r=srtp_create(&mSRTPSessionOut, &mSRTPPolicyOut);
95 assert(r==0);
96 mSrtpInitialized = true;
97 }
98
99 void
100 FlowDtlsSocketContext::handshakeFailed(const char *err)
101 {
102 ErrLog(<< "Flow Dtls Handshake failed! ComponentId=" << mFlow.getComponentId());
103 }
104
105 void FlowDtlsSocketContext::fingerprintMismatch()
106 {
107 // Ensure Srtp is not initalized, so the will not process media packets from this endpoint
108 if(mSrtpInitialized)
109 {
110 // Free the master key memory allocated in DtlsSocket::createSrtpSessionPolicies
111 delete mSRTPPolicyIn.key;
112 delete mSRTPPolicyOut.key;
113 }
114 mSrtpInitialized = false;
115 }
116
117 err_status_t
118 FlowDtlsSocketContext::srtpProtect(void* data, int* size, bool rtcp)
119 {
120 err_status_t status = err_status_no_ctx;
121 if(mSrtpInitialized)
122 {
123 if(rtcp)
124 {
125 status = srtp_protect_rtcp(mSRTPSessionOut, data, size);
126 }
127 else
128 {
129 status = srtp_protect(mSRTPSessionOut, data, size);
130 }
131 }
132 return status;
133 }
134
135 err_status_t
136 FlowDtlsSocketContext::srtpUnprotect(void* data, int* size, bool rtcp)
137 {
138 err_status_t status = err_status_no_ctx;
139 if(mSrtpInitialized)
140 {
141 if(rtcp)
142 {
143 status = srtp_unprotect_rtcp(mSRTPSessionIn, data, size);
144 }
145 else
146 {
147 status = srtp_unprotect(mSRTPSessionIn, data, size);
148 }
149 }
150 return status;
151 }
152
153 #endif
154 /* ====================================================================
155
156 Copyright (c) 2007-2008, Plantronics, Inc.
157 All rights reserved.
158
159 Redistribution and use in source and binary forms, with or without
160 modification, are permitted provided that the following conditions are
161 met:
162
163 1. Redistributions of source code must retain the above copyright
164 notice, this list of conditions and the following disclaimer.
165
166 2. Redistributions in binary form must reproduce the above copyright
167 notice, this list of conditions and the following disclaimer in the
168 documentation and/or other materials provided with the distribution.
169
170 3. Neither the name of Plantronics nor the names of its contributors
171 may be used to endorse or promote products derived from this
172 software without specific prior written permission.
173
174 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
176 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
177 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
178 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
179 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
180 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
181 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
182 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
183 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
184 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
185
186 ==================================================================== */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27