2#if defined(HAVE_CONFIG_H)
26#define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO
38 bool thirdPartyRequiresCertificate) :
40 mAuthRequestDispatcher(authRequestDispatcher),
42 mThirdPartyRequiresCertificate(thirdPartyRequiresCertificate)
50 bool thirdPartyRequiresCertificate,
53 mAuthRequestDispatcher(authRequestDispatcher),
55 mThirdPartyRequiresCertificate(thirdPartyRequiresCertificate),
56 mCommonNameMappings(commonNameMappings)
67 DebugLog(<<
"Monkey handling request: " << *
this <<
"; reqcontext = " << rc);
77 if (sipMessage->
method() == ACK ||
78 sipMessage->
method() == BYE)
83 if (sipMessage->
header(h_To).exists(p_tag))
87 DebugLog(<<
"To-tag detected, allowing a request that claims to belong to an existing dialog");
98 sipMessage->
header(h_From).isAllContacts() )
100 InfoLog(<<
"Malformed From header: cannot verify against any certificate. Rejecting.");
106 if(sipMessage->
method() == REFER && sipMessage->
exists(h_ReferredBy))
109 sipMessage->
header(h_ReferredBy).isAllContacts() )
111 InfoLog(<<
"Malformed Referred-By header: cannot verify against any certificate. Rejecting.");
118 claimedUri = sipMessage->
header(h_ReferredBy).
uri();
124 DebugLog(<<
"Can't validate certificate on non-TLS connection");
128 const std::list<resip::Data> &peerNames = sipMessage->
getTlsPeerNames();
132 DebugLog(<<
"Matched trusted peer by certificate in ACL");
143 DebugLog(<<
"from trusted node, skipping checks");
148 if(peerNames.empty())
150 DebugLog(<<
"peerNames is empty, allowing the message without further inspection");
160 else if(_auth ==
Async)
162 DebugLog(<<
"waiting for async authorization");
174 if(peerNames.empty())
178 DebugLog(<<
"third party requires certificate");
185 DebugLog(<<
"third party does not require certificate, allowing the message without further inspection");
196 else if(_auth ==
Async)
198 DebugLog(<<
"waiting for async authorization");
209 DebugLog(<<
"handling TlsPeerIdentityInfo");
225 DebugLog(<<
"not a recognized message type");
242 std::list<Data>::const_iterator it = peerNames.
begin();
243 for(; it != peerNames.end(); ++it)
248 DebugLog(<<
"Matched certificate name " << i <<
" against full AoR " << aor);
253 DebugLog(<<
"Matched certificate name " << i <<
" against domain " << domain);
256 CommonNameMappings::iterator _mapping =
260 DebugLog(<<
"CN mapping(s) exist for the certificate " << i);
262 if(permitted.find(aor) != permitted.end())
264 DebugLog(<<
"Matched certificate name " << i <<
" against full AoR " << aor <<
" by common name mappings");
267 if(permitted.find(domain) != permitted.end())
269 DebugLog(<<
"Matched certificate name " << i <<
" against domain " << domain <<
" by common name mappings");
273 DebugLog(<<
"Certificate name " << i <<
" doesn't match AoR " << aor <<
" or domain " << domain);
278 DebugLog(<<
"mCommonNameMappings is empty, trying database");
280 for(it = peerNames.begin(); it != peerNames.end(); ++it)
286 std::unique_ptr<ApplicationMessage> app(tpaInfo);
292 DebugLog(<<
"message content didn't match any peer name");
299 os <<
"CertificateAuthentication monkey" << std::endl;
bool isTlsPeerNameTrusted(const std::list< resip::Data > &tlsPeerNames)
static resip::KeyValueStore::Key mCertificateVerifiedKey
resip::CommonNameMappings mCommonNameMappings
bool isTrustedSource(const std::list< resip::Data > &peerNames)
bool mThirdPartyRequiresCertificate
resip::AsyncBool authorizedForThisIdentity(RequestContext &context, const std::list< resip::Data > &peerNames, resip::Uri &fromUri)
virtual processor_action_t process(RequestContext &)
~CertificateAuthenticator()
virtual void dump(EncodeStream &os) const
CertificateAuthenticator(ProxyConfig &config, resip::Dispatcher *authRequestDispatcher, resip::SipStack *stack, AclStore &aclStore, bool thirdPartyRequiresCertificate=true)
resip::Dispatcher * mAuthRequestDispatcher
static resip::KeyValueStore::Key mFromTrustedNodeKey
static resip::KeyValueStore::Key allocateRequestKeyValueStoreKey()
resip::SipMessage & getOriginalRequest()
Returns the SipMessage associated with the server transaction.
resip::Message * getCurrentEvent()
Returns the event that we are currently working on.
void sendResponse(resip::SipMessage &response)
resip::KeyValueStore & getKeyValueStore()
resip::Data getTransactionId() const
const std::set< resip::Data > & identities() const
const std::set< resip::Data > & peerNames() const
const bool authorized() const
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.
A generic thread-bank class.
virtual bool post(std::unique_ptr< resip::ApplicationMessage > &work)
Posts a message to this thread bank.
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.
void setBoolValue(Key key, bool value)
const bool & getBoolValue(Key key) const
bool isWellFormed() const
Returns true iff this element was parsed successfully, according to the implementation of parse().
The base-class used for message-passing.
Represents a SIP message.
const std::list< Data > & getTlsPeerNames() const
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
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
This is the primary point of interaction between the app-layer and the stack.
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
This Class is used to implement a primitive form of RPC using loose XML formatting.
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