6
#include <rutil/Log.hxx>
7
#include <rutil/Logger.hxx>
8
#include <rutil/Timer.hxx>
11
#include <boost/function.hpp>
14
#include "FlowDtlsSocketContext.hxx"
15
#include "FlowManagerSubsystem.hxx"
17
using namespace flowmanager;
18
using namespace resip;
22
#define RESIPROCATE_SUBSYSTEM FlowManagerSubsystem::FLOWMANAGER
24
FlowDtlsSocketContext::FlowDtlsSocketContext(Flow& flow, const asio::ip::address& address, unsigned short port)
25
: mFlow(flow), mAddress(address), mPort(port), mSrtpInitialized(false)
29
FlowDtlsSocketContext::~FlowDtlsSocketContext()
33
// Free the master key memory allocated in DtlsSocket::createSrtpSessionPolicies
34
delete mSRTPPolicyIn.key;
35
delete mSRTPPolicyOut.key;
40
FlowDtlsSocketContext::write(const unsigned char* data, unsigned int len)
42
InfoLog(<< "Dtls write to " << mAddress.to_string() << ":" << mPort << " called. ComponentId=" << mFlow.getComponentId());
43
mFlow.rawSendTo(mAddress, mPort, (const char*)data, len);
47
FlowDtlsSocketContext::handshakeCompleted()
49
InfoLog(<< "Flow Dtls Handshake Completed! ComponentId=" << mFlow.getComponentId());
52
SRTP_PROTECTION_PROFILE *srtp_profile;
55
if(mSocket->getRemoteFingerprint(fprint))
57
Data remoteSDPFingerprint = mFlow.getRemoteSDPFingerprint();
58
if(!remoteSDPFingerprint.empty())
60
if(!mSocket->checkFingerprint(remoteSDPFingerprint.c_str(), remoteSDPFingerprint.size()))
62
InfoLog(<< "Remote fingerprint = " << fprint << " is not valid! ComponentId=" << mFlow.getComponentId());
67
InfoLog(<< "Remote fingerprint = " << fprint << " is valid! ComponentId=" << mFlow.getComponentId());
72
InfoLog(<< "Remote fingerprint = " << fprint << " ComponentId=" << mFlow.getComponentId());
77
InfoLog(<< "Remote fingerprint cannot be obtained from Dtls handshake. ComponentId=" << mFlow.getComponentId());
81
srtp_profile=mSocket->getSrtpProfile();
85
InfoLog(<< "SRTP Extension negotiated profile=" << srtp_profile->name << " ComponentId=" << mFlow.getComponentId());
88
mSocket->createSrtpSessionPolicies(mSRTPPolicyOut, mSRTPPolicyIn);
90
r=srtp_create(&mSRTPSessionIn, &mSRTPPolicyIn);
92
r=srtp_create(&mSRTPSessionOut, &mSRTPPolicyOut);
94
mSrtpInitialized = true;
98
FlowDtlsSocketContext::handshakeFailed(const char *err)
100
ErrLog(<< "Flow Dtls Handshake failed! ComponentId=" << mFlow.getComponentId());
103
void FlowDtlsSocketContext::fingerprintMismatch()
105
// Ensure Srtp is not initalized, so the will not process media packets from this endpoint
108
// Free the master key memory allocated in DtlsSocket::createSrtpSessionPolicies
109
delete mSRTPPolicyIn.key;
110
delete mSRTPPolicyOut.key;
112
mSrtpInitialized = false;
116
FlowDtlsSocketContext::srtpProtect(void* data, int* size, bool rtcp)
118
err_status_t status = err_status_no_ctx;
123
status = srtp_protect_rtcp(mSRTPSessionOut, data, size);
127
status = srtp_protect(mSRTPSessionOut, data, size);
134
FlowDtlsSocketContext::srtpUnprotect(void* data, int* size, bool rtcp)
136
err_status_t status = err_status_no_ctx;
141
status = srtp_unprotect_rtcp(mSRTPSessionIn, data, size);
145
status = srtp_unprotect(mSRTPSessionIn, data, size);
152
/* ====================================================================
154
Copyright (c) 2007-2008, Plantronics, Inc.
157
Redistribution and use in source and binary forms, with or without
158
modification, are permitted provided that the following conditions are
161
1. Redistributions of source code must retain the above copyright
162
notice, this list of conditions and the following disclaimer.
164
2. Redistributions in binary form must reproduce the above copyright
165
notice, this list of conditions and the following disclaimer in the
166
documentation and/or other materials provided with the distribution.
168
3. Neither the name of Plantronics nor the names of its contributors
169
may be used to endorse or promote products derived from this
170
software without specific prior written permission.
172
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
174
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
175
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
176
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
177
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
178
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
179
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
180
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
181
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
182
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
184
==================================================================== */