reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
RADIUSAuthenticator.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2 #include "config.h"
3#endif
4
5#include "rutil/DnsUtil.hxx"
10#include "rutil/Logger.hxx"
11
15#include "repro/Proxy.hxx"
17#include "repro/UserStore.hxx"
20#include "rutil/ParseBuffer.hxx"
22
23#define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO
24
25using namespace resip;
26using namespace repro;
27using namespace std;
28
29#ifdef USE_RADIUS_CLIENT
30
31RADIUSAuthenticator::RADIUSAuthenticator(ProxyConfig& config,
32 const resip::Data& configurationFile,
33 const Data& staticRealm,
34 const std::vector<resip::DigestType>& challengeDigestTypes) :
35 DigestAuthenticator(config, 0, staticRealm, challengeDigestTypes)
36{
37 RADIUSDigestAuthenticator::init(
38 configurationFile.empty() ? 0 : configurationFile.c_str());
39}
40
41RADIUSAuthenticator::~RADIUSAuthenticator()
42{
43}
44
45// Start a RADIUS query to check the response supplied by the user
46// Based on the code in resip/dum/RADIUSServerAuthManager.cxx
48RADIUSAuthenticator::requestUserAuthInfo(RequestContext &rc, const Auth& auth, UserInfoMessage *userInfo)
49{
50 ReproRADIUSDigestAuthListener *radiusListener = 0;
51 Message *message = rc.getCurrentEvent();
52 SipMessage *sipMessage = dynamic_cast<SipMessage*>(message);
53 resip_assert(sipMessage);
54
55 try
56 {
57 radiusListener = new ReproRADIUSDigestAuthListener(userInfo, rc.getProxy());
58 const Data& user = userInfo->user();
59 const Data& realm = userInfo->realm();
60 Data radiusUser = user;
61 DebugLog(<< "radiusUser = " << radiusUser.c_str() << ", " << "user = " << user.c_str());
62 resip_assert(sipMessage->isRequest());
63 Data reqUri = auth.param(p_uri);
64 Data reqMethod = resip::getMethodName(sipMessage->header(h_RequestLine).getMethod());
65 RADIUSDigestAuthenticator *radius = NULL;
66 if(auth.exists(p_qop))
67 {
68 if(auth.param(p_qop) == Symbols::auth)
69 {
70 Data myQop("auth");
71 radius = new RADIUSDigestAuthenticator(
72 radiusUser, user, realm, auth.param(p_nonce),
73 reqUri, reqMethod, myQop, auth.param(p_nc), auth.param(p_cnonce),
74 auth.param(p_response),
75 radiusListener);
76 }
77 else if(auth.param(p_qop) == Symbols::authInt)
78 {
79 Data myQop("auth-int");
80 radius = new RADIUSDigestAuthenticator(
81 radiusUser, user, realm, auth.param(p_nonce),
82 reqUri, reqMethod, myQop, auth.param(p_nc), auth.param(p_cnonce),
83 auth.param(p_opaque),
84 auth.param(p_response),
85 radiusListener);
86 }
87 }
88 if(radius == NULL)
89 {
90 radius = new RADIUSDigestAuthenticator(
91 radiusUser, user, realm, auth.param(p_nonce),
92 reqUri, reqMethod,
93 auth.param(p_response),
94 radiusListener);
95 }
96 int result = radius->doRADIUSCheck();
97 if(result < 0)
98 {
99 ErrLog(<<"RADIUSServerAuthManager::requestCredential, uri = " << reqUri <<" failed to start thread, error = " << result);
100 rc.sendResponse(*unique_ptr<SipMessage>
101 (Helper::makeResponse(*sipMessage, 500, "Auth failed")));
102 return SkipAllChains;
103 }
104 }
105 catch(...)
106 {
107 WarningLog(<<"RADIUSServerAuthManager::requestCredential, unexpected exception thrown");
108 delete radiusListener;
109 rc.sendResponse(*unique_ptr<SipMessage>
110 (Helper::makeResponse(*sipMessage, 500, "Auth failed")));
111 return SkipAllChains;
112 }
113 return WaitingForEvent;
114}
115
116ReproRADIUSDigestAuthListener::ReproRADIUSDigestAuthListener(
118 mUserInfo(userInfo),
119 mTu(tu)
120{
121}
122
123ReproRADIUSDigestAuthListener::~ReproRADIUSDigestAuthListener()
124{
125}
126
127void
128ReproRADIUSDigestAuthListener::onSuccess(const resip::Data& rpid)
129{
130 DebugLog(<<"ReproRADIUSDigestAuthListener::onSuccess");
131 if(!rpid.empty())
132 {
133 DebugLog(<<"ReproRADIUSDigestAuthListener::onSuccess rpid = " << rpid.c_str());
134 }
135 else
136 {
137 DebugLog(<<"ReproRADIUSDigestAuthListener::onSuccess, no rpid");
138 }
139 mUserInfo->setMode(UserAuthInfo::DigestAccepted);
140 mTu.post(mUserInfo);
141}
142
143void
144ReproRADIUSDigestAuthListener::onAccessDenied()
145{
146 DebugLog(<<"ReproRADIUSDigestAuthListener::onAccessDenied");
147 mUserInfo->setMode(UserAuthInfo::DigestNotAccepted);
148 mTu.post(mUserInfo);
149}
150
151void
152ReproRADIUSDigestAuthListener::onError()
153{
154 WarningLog(<<"ReproRADIUSDigestAuthListener::onError");
155 mUserInfo->setMode(UserAuthInfo::Error);
156 mTu.post(mUserInfo);
157}
158
159#endif
160
161/* ====================================================================
162 *
163 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
164 * Copyright 2013 Daniel Pocock http://danielpocock.com
165 * All rights reserved.
166 *
167 * Redistribution and use in source and binary forms, with or without
168 * modification, are permitted provided that the following conditions
169 * are met:
170 *
171 * 1. Redistributions of source code must retain the above copyright
172 * notice, this list of conditions and the following disclaimer.
173 *
174 * 2. Redistributions in binary form must reproduce the above copyright
175 * notice, this list of conditions and the following disclaimer in
176 * the documentation and/or other materials provided with the
177 * distribution.
178 *
179 * 3. Neither the name of the author(s) nor the names of any contributors
180 * may be used to endorse or promote products derived from this software
181 * without specific prior written permission.
182 *
183 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
184 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
185 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
186 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
187 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
188 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
189 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
190 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
191 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
192 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
193 * SUCH DAMAGE.
194 *
195 * ====================================================================
196 *
197 *
198 */
199
#define DebugLog(args_)
Definition Logger.hxx:128
#define WarningLog(args_)
Definition Logger.hxx:134
#define ErrLog(args_)
Definition Logger.hxx:137
#define resip_assert(x)
This file needs to work for both C and C++ code.
resip::Message * getCurrentEvent()
Returns the event that we are currently working on.
void sendResponse(resip::SipMessage &response)
const resip::Data & user() const
const resip::Data & realm() const
Represents the "credentials" and "challenge" elements in the SIP grammar.
Definition Auth.hxx:18
bool exists(const Param< Auth > &paramType) const
Definition Auth.cxx:225
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
const char * c_str() const
Returns a null-terminated string representing.
Definition Data.cxx:1097
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
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.
Definition Helper.cxx:412
The base-class used for message-passing.
Definition Message.hxx:21
MethodTypes getMethod() const
Represents a SIP message.
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.
static const char * auth
Definition Symbols.hxx:72
static const char * authInt
Definition Symbols.hxx:73
The base-class for an RFC 3261 Transaction User.
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;
const Data & getMethodName(MethodTypes t)
RequestLineType h_RequestLine
Definition Headers.cxx:347