12#define RESIPROCATE_SUBSYSTEM Subsystem::DUM
19 mTrustedPeers(trustedPeers),
20 mThirdPartyRequiresCertificate(thirdPartyRequiresCertificate)
26 mTrustedPeers(trustedPeers),
27 mThirdPartyRequiresCertificate(thirdPartyRequiresCertificate),
28 mCommonNameMappings(commonNameMappings)
34 InfoLog(<<
"~TlsPeerAuthManager: " << mMessages.size() <<
" messages in memory when destroying.");
50 switch (
handle(sipMessage) )
53 InfoLog(<<
"TlsPeerAuth rejected request " << sipMessage->
brief());
72 InfoLog(<<
"TlsPeerAuth rejected request " << *tpiMessage);
83 const Data& transactionId,
84 const std::list<resip::Data> &peerNames,
90 std::list<Data>::const_iterator it = peerNames.
begin();
91 for(; it != peerNames.end(); ++it)
96 DebugLog(<<
"Matched certificate name " << i <<
" against full AoR " << aor);
101 DebugLog(<<
"Matched certificate name " << i <<
" against domain " << domain);
104 CommonNameMappings::iterator _mapping =
105 mCommonNameMappings.find(i);
106 if(_mapping != mCommonNameMappings.end())
108 DebugLog(<<
"CN mapping(s) exist for the certificate " << i);
110 if(permitted.find(aor) != permitted.end())
112 DebugLog(<<
"Matched certificate name " << i <<
" against full AoR " << aor <<
" by common name mappings");
115 if(permitted.find(domain) != permitted.end())
117 DebugLog(<<
"Matched certificate name " << i <<
" against domain " << domain <<
" by common name mappings");
121 DebugLog(<<
"Certificate name " << i <<
" doesn't match AoR " << aor <<
" or domain " << domain);
124 if (mCommonNameMappings.empty())
126 DebugLog(<<
"mCommonNameMappings is empty, trying async");
128 for(it = peerNames.begin(); it != peerNames.end(); ++it)
138 DebugLog(<<
"message content didn't match any peer name");
156 sipMessage->
header(h_From).isAllContacts() )
158 InfoLog(<<
"Malformed From header: cannot verify against any certificate. Rejecting.");
159 auto response = std::make_shared<SipMessage>();
165 if(sipMessage->
method() == REFER && sipMessage->
exists(h_ReferredBy))
168 sipMessage->
header(h_ReferredBy).isAllContacts() )
170 InfoLog(<<
"Malformed Referred-By header: cannot verify against any certificate. Rejecting.");
171 auto response = std::make_shared<SipMessage>();
178 claimedUri = sipMessage->
header(h_ReferredBy).
uri();
184 DebugLog(<<
"Can't validate certificate on non-TLS connection");
190 DebugLog(<<
"from trusted node, skipping checks");
194 const std::list<resip::Data> &peerNames = sipMessage->
getTlsPeerNames();
201 DebugLog(<<
"authorization not required for this message");
205 if(peerNames.empty())
207 DebugLog(<<
"peerNames is empty, allowing the message without further inspection");
217 else if(_auth ==
Async)
220 DebugLog(<<
"waiting for async authorization");
224 auto response = std::make_shared<SipMessage>();
233 if(peerNames.empty())
235 if(mThirdPartyRequiresCertificate)
237 DebugLog(<<
"third party requires certificate");
238 auto response = std::make_shared<SipMessage>();
239 Helper::makeResponse(*response, *sipMessage, 403,
"Mutual TLS required to handle that message");
245 DebugLog(<<
"third party does not require certificate, allowing the message without further inspection");
255 else if(_auth ==
Async)
258 DebugLog(<<
"waiting for async authorization");
262 auto response = std::make_shared<SipMessage>();
268 InfoLog(<<
"Skipping some message that we didn't explicitly handle");
289 auto response = std::make_shared<SipMessage>();
317 std::list<Data>::const_iterator it = peerNames.begin();
318 for(; it != peerNames.end(); ++it)
321 if(mTrustedPeers.find(i) != mTrustedPeers.end())
323 DebugLog(<<
"Matched certificate name " << i <<
" is a trusted peer");
#define resip_assert(x)
This file needs to work for both C and C++ code.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * begin() const noexcept
Returns a pointer to the beginning of the buffer used by the Data.
void send(std::shared_ptr< SipMessage > request)
virtual const Data & getTransactionId() const
DialogUsageManager & mDum
virtual void postCommand(std::unique_ptr< Message > message)
@ FeatureDoneAndEventDone
static void makeResponse(SipMessage &response, const SipMessage &request, int responseCode, const Data &reason=Data::Empty, const Data &hostname=Data::Empty, const Data &warning=Data::Empty)
Make a response to a provided request.
bool isWellFormed() const
Returns true iff this element was parsed successfully, according to the implementation of parse().
The base-class used for message-passing.
virtual Brief brief() const
return a facet for brief encoding of message
Represents a SIP message.
const std::list< Data > & getTlsPeerNames() const
bool isRequest() const
Returns true if message is a request, false otherwise.
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
virtual const Data & getTransactionId() const
Returns the transaction id from the branch or if 2543, the computed hash.
bool exists(const HeaderBase &headerType) const
Returns true if the given header field is present, false otherwise.
const Tuple & getSource() const
Returns the source tuple that the message was received from only makes sense for messages received fr...
bool isExternal() const
Check if SipMessage is to be treated as it came off the wire.
resip::MethodTypes method() const
returns the method type of the message
virtual bool isTrustedSource(const SipMessage &msg)
should return true if the request should be trusted based on the source/transport default implementat...
virtual ~TlsPeerAuthManager()
virtual ProcessingResult process(Message *msg)
virtual AsyncBool asyncLookup(TlsPeerIdentityInfoMessage *info)
virtual SipMessage * handleTlsPeerIdentityInfo(TlsPeerIdentityInfoMessage *tpiInfo)
TlsPeerAuthManager(DialogUsageManager &dum, TargetCommand::Target &target, const std::set< Data > &trustedPeers, bool thirdPartyRequiresCertificate=true)
virtual bool requiresAuthorization(const SipMessage &msg)
should return true if the request must be challenged The default is to challenge all requests - overr...
virtual AsyncBool authorizedForThisIdentity(const resip::Data &transactionId, const std::list< resip::Data > &peerNames, resip::Uri &fromUri)
should return true if the passed in user is authorized for the provided uri
virtual Result handle(SipMessage *sipMsg)
const bool authorized() const
const std::set< resip::Data > & identities() const
const std::set< resip::Data > & peerNames() const
bool isMyDomain(const Data &domain) const
Returns true iff domain matches one of the domains that this TransactionUser is responsible for.
TransportType getType() const
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Data getAorNoPort() const
dcm! – add UnusedChecking(_enum) below;
std::map< Data, PermittedFromAddresses > CommonNameMappings
bool isSecure(TransportType type)
Returns true if passed in transport type is a secure transport protocol.
std::set< Data > PermittedFromAddresses
RequestLineType h_RequestLine