22#define RESIPROCATE_SUBSYSTEM FlowManagerSubsystem::FLOWMANAGER
25 : mFlow(flow), mAddress(address), mPort(port), mSrtpInitialized(false)
31 destroySrtpSessions();
37 InfoLog(<<
"Dtls write to " << mAddress.to_string() <<
":" << mPort <<
" called. ComponentId=" << mFlow.
getComponentId());
38 mFlow.
rawSendTo(mAddress, mPort, (
const char*)data, len);
55 InfoLog(<<
"SRTP Extension negotiated profile=" << srtp_profile->name <<
" ComponentId=" << mFlow.
getComponentId());
69std::shared_ptr<std::mutex>
73 return mFlow.mSharedMutex;
84 if(fingerprint.
empty())
86 InfoLog(<<
"Waiting for the remote SDP fingerprint before setting up SRTP. ComponentId=" << mFlow.
getComponentId());
94 InfoLog(<<
"Remote certificate matches the SDP fingerprint (" << hashFunction <<
" " << fingerprint <<
"), setting up SRTP. ComponentId=" << mFlow.
getComponentId());
95 if(!createSrtpSessions())
97 ErrLog(<<
"Unable to set up SRTP from the Dtls handshake. ComponentId=" << mFlow.
getComponentId());
104 char fprint[EVP_MAX_MD_SIZE * 3];
106 Data(fprint) :
Data(
"unavailable (unsupported hash function)");
107 WarningLog(<<
"Remote certificate does not match the SDP fingerprint, "
108 << (mSrtpInitialized ?
"tearing down SRTP" :
"not setting up SRTP")
109 <<
". SDP fingerprint=" << hashFunction <<
" " << fingerprint
110 <<
", certificate fingerprint=" << remoteFingerprint <<
" ComponentId=" << mFlow.
getComponentId());
112 destroySrtpSessions();
117FlowDtlsSocketContext::createSrtpSessions()
119 srtp_policy_t policyIn;
120 srtp_policy_t policyOut;
126 bool created =
false;
127 if(srtp_create(&mSRTPSessionIn, &policyIn) == srtp_err_status_ok)
129 if(srtp_create(&mSRTPSessionOut, &policyOut) == srtp_err_status_ok)
135 srtp_dealloc(mSRTPSessionIn);
141 delete[] policyIn.key;
142 delete[] policyOut.key;
144 mSrtpInitialized = created;
149FlowDtlsSocketContext::destroySrtpSessions()
153 mSrtpInitialized =
false;
154 srtp_dealloc(mSRTPSessionIn);
155 srtp_dealloc(mSRTPSessionOut);
162 srtp_err_status_t status = srtp_err_status_no_ctx;
167 status = srtp_protect_rtcp(mSRTPSessionOut, data, size);
171 status = srtp_protect(mSRTPSessionOut, data, size);
180 srtp_err_status_t status = srtp_err_status_no_ctx;
185 status = srtp_unprotect_rtcp(mSRTPSessionIn, data, size);
189 status = srtp_unprotect(mSRTPSessionIn, data, size);
#define WarningLog(args_)
static const size_t FingerprintSize
bool createSrtpSessionPolicies(srtp_policy_t &outboundPolicy, srtp_policy_t &inboundPolicy)
bool checkFingerprint(const char *hashFunction, const char *fingerprint)
SRTP_PROTECTION_PROFILE * getSrtpProfile()
bool getRemoteFingerprint(const char *hashFunction, char *fingerprint, size_t fingerprintSize)
bool handshakeCompleted()
srtp_err_status_t srtpUnprotect(void *data, int *size, bool rtcp)
virtual ~FlowDtlsSocketContext()
virtual void handshakeFailed(const char *err)
virtual std::shared_ptr< std::mutex > timerLock()
void checkRemoteFingerprint(const resip::Data &hashFunction, const resip::Data &fingerprint)
virtual void handshakeCompleted()
virtual void write(const unsigned char *data, unsigned int len)
srtp_err_status_t srtpProtect(void *data, int *size, bool rtcp)
FlowDtlsSocketContext(Flow &flow, const asio::ip::address &address, unsigned short port)
This class represents a Flow that is created by the Flow Manager.
void rawSendTo(const asio::ip::address &address, unsigned short port, const char *buffer, unsigned int size)
unsigned int getComponentId()
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * c_str() const
Returns a null-terminated string representing.
bool empty() const noexcept
Checks whether the Data is empty.
This class is used during media sessions that use Dtls-Srtp for a media transport.
dcm! – add UnusedChecking(_enum) below;