reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
StaticRoute.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
7#include "repro/Proxy.hxx"
13
14#include "rutil/Logger.hxx"
15#include "repro/RouteStore.hxx"
16
17#define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO
18
19using namespace resip;
20using namespace repro;
21using namespace std;
22
24 Processor("StaticRoute"),
25 mRouteStore(config.getDataStore()->mRouteStore),
26 mNoChallenge(config.getConfigBool("DisableAuth", false) || !config.getConfigBool("ChallengeThirdPartiesCallingLocalDomains", true)),
27 mParallelForkStaticRoutes(config.getConfigBool("ParallelForkStaticRoutes", false)),
28 mContinueProcessingAfterRoutesFound(config.getConfigBool("ContinueProcessingAfterRoutesFound", false)),
29 mUseAuthInt(!config.getConfigBool("DisableAuthInt", false))
30{
31 std::vector<resip::Data> digestTypeStrings;
32 if (config.getConfigValue("DigestChallengeAlgorithms", digestTypeStrings))
33 {
34 DigestType digestType;
35 for (auto it = digestTypeStrings.begin(); it != digestTypeStrings.end(); ++it)
36 {
37 if (Helper::isDigestAlgorithmSupported(*it, digestType))
38 {
39 mChallengeDigestTypes.push_back(digestType);
40 }
41 }
42 }
43}
44
47
50{
51 DebugLog(<< "Monkey handling request: " << *this
52 << "; reqcontext = " << context);
53 Proxy &proxy = context.getProxy();
54
55 SipMessage& msg = context.getOriginalRequest();
56
57 Uri ruri(msg.header(h_RequestLine).uri());
59 Data event;
60 if ( msg.exists(h_Event) && msg.header(h_Event).isWellFormed())
61 {
62 event = msg.header(h_Event).value() ;
63 }
64
66 method,
67 event));
68 bool requireAuth = false;
69 bool externalTarget = false;
71 msg.method() != ACK && // Don't challenge ACK and BYE requests
72 msg.method() != BYE)
73 {
74 requireAuth = !mNoChallenge;
75 for ( RouteStore::UriList::const_iterator i = targets.begin();
76 i != targets.end(); i++ )
77 {
78 const Data& targetDomain = i->host();
79 if(!proxy.isMyDomain(targetDomain))
80 {
81 DebugLog(<<"target domain " << targetDomain << " is not local");
82 externalTarget = true;
83 requireAuth |= !mNoChallenge;
84 }
85 }
86 }
87
88 // Allow third-parties verified by their domain certificate, just as long
89 // as they don't try to use us as a relay to external targets
90 // not in our local domain list
92 && !externalTarget && requireAuth)
93 {
94 DebugLog(<< "overriding requireAuth because certificate validation succeeded and no targets are external");
95 requireAuth = false;
96 }
97
98 if (requireAuth && context.getDigestIdentity().empty())
99 {
100 // !rwm! TODO do we need anything more sophisticated to figure out the realm?
101 Data realm = msg.header(h_RequestLine).uri().host();
102
103 challengeRequest(context, realm);
105 }
106 else
107 {
108 TargetPtrList parallelBatch;
109 for (RouteStore::UriList::const_iterator i = targets.begin();
110 i != targets.end(); i++ )
111 {
112 //Targets are only added after authentication
113 InfoLog(<< "Adding target " << *i );
114
116 {
117 Target* target = new Target(*i);
118 parallelBatch.push_back(target);
119 }
120 else
121 {
122 // Add Simple Target
124 }
125 }
126 if(parallelBatch.size() > 0)
127 {
128 context.getResponseContext().addTargetBatch(parallelBatch, false /* highPriority */);
129 }
130
131 if(!targets.empty() && !mContinueProcessingAfterRoutesFound)
132 {
134 }
135 }
136
137 return Processor::Continue;
138}
139
140void
142{
143 SipMessage& sipMessage = rc.getOriginalRequest();
144
145 SipMessage *challenge = Helper::makeProxyChallenge(sipMessage, realm, mUseAuthInt /*auth-int*/, false /*stale*/, mChallengeDigestTypes);
146 rc.sendResponse(*challenge);
147
148 delete challenge;
149}
150
151
152/* ====================================================================
153 * The Vovida Software License, Version 1.0
154 *
155 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
156 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
157 *
158 * Redistribution and use in source and binary forms, with or without
159 * modification, are permitted provided that the following conditions
160 * are met:
161 *
162 * 1. Redistributions of source code must retain the above copyright
163 * notice, this list of conditions and the following disclaimer.
164 *
165 * 2. Redistributions in binary form must reproduce the above copyright
166 * notice, this list of conditions and the following disclaimer in
167 * the documentation and/or other materials provided with the
168 * distribution.
169 *
170 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
171 * and "Vovida Open Communication Application Library (VOCAL)" must
172 * not be used to endorse or promote products derived from this
173 * software without prior written permission. For written
174 * permission, please contact vocal@vovida.org.
175 *
176 * 4. Products derived from this software may not be called "VOCAL", nor
177 * may "VOCAL" appear in their name, without prior written
178 * permission of Vovida Networks, Inc.
179 *
180 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
181 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
182 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
183 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
184 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
185 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
186 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
187 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
188 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
189 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
190 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
191 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
192 * DAMAGE.
193 *
194 * ====================================================================
195 */
#define DebugLog(args_)
Definition Logger.hxx:128
#define InfoLog(args_)
Definition Logger.hxx:131
static resip::KeyValueStore::Key mCertificateVerifiedKey
static resip::KeyValueStore::Key mFromTrustedNodeKey
resip::SipMessage & getOriginalRequest()
Returns the SipMessage associated with the server transaction.
ResponseContext & getResponseContext()
const resip::Data & getDigestIdentity() const
void sendResponse(resip::SipMessage &response)
resip::KeyValueStore & getKeyValueStore()
resip::Data addTarget(const resip::NameAddr &target, bool beginImmediately=false)
Adds this Target as a SimpleTarget to the collection of Targets.
bool addTargetBatch(TargetPtrList &targets, bool highPriority=false)
Adds a batch of Targets.
std::vector< resip::Uri > UriList
UriList process(const resip::Uri &ruri, const resip::Data &method, const resip::Data &event)
void challengeRequest(repro::RequestContext &rc, resip::Data &realm)
bool mContinueProcessingAfterRoutesFound
virtual processor_action_t process(RequestContext &)
RouteStore & mRouteStore
std::vector< resip::DigestType > mChallengeDigestTypes
StaticRoute(ProxyConfig &config)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
static SipMessage * makeProxyChallenge(const SipMessage &request, const Data &realm, bool useAuth=true, bool stale=false, const std::vector< DigestType > &digestTypes=std::vector< DigestType >())
Definition Helper.cxx:1212
static bool isDigestAlgorithmSupported(const Auth &auth, DigestType &digestType)
Definition Helper.cxx:742
const bool & getBoolValue(Key key) const
bool isWellFormed() const
Returns true iff this element was parsed successfully, according to the implementation of parse().
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
const Uri & uri() const
MethodTypes & method()
bool getConfigValue(const resip::Data &name, resip::Uri &value)
Represents a SIP message.
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.
resip::MethodTypes method() const
returns the method type of the message
bool isMyDomain(const Data &domain) const
Returns true iff domain matches one of the domains that this TransactionUser is responsible for.
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
Data & host()
Definition Uri.hxx:40
This Class is used to implement a primitive form of RPC using loose XML formatting.
std::list< Target * > TargetPtrList
Definition Target.hxx:81
dcm! – add UnusedChecking(_enum) below;
const Data & getMethodName(MethodTypes t)
RequestLineType h_RequestLine
Definition Headers.cxx:347