reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
RADIUSServerAuthManager.cxx
Go to the documentation of this file.
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5
6#include <sstream>
7
14#include "rutil/Data.hxx"
15#include "rutil/Logger.hxx"
16
17#ifdef USE_RADIUS_CLIENT
18
19using namespace resip;
20using namespace std;
21
22#define RESIPROCATE_SUBSYSTEM Subsystem::DUM
23
24RADIUSServerAuthManager::RADIUSServerAuthManager(
29 const Data& staticRealm,
30 const std::vector<DigestType>& challengeDigestTypes) :
32 dum(dum)
33{
34 RADIUSDigestAuthenticator::init(
35 configurationFile.empty() ? 0 : configurationFile.c_str());
36}
37
38RADIUSServerAuthManager::~RADIUSServerAuthManager()
39{
40}
41
42void
43RADIUSServerAuthManager::requestCredential(
44 const resip::Data& user,
45 const resip::Data& realm,
46 const resip::SipMessage& msg,
47 const resip::Auth& auth,
48 const resip::Data& transactionId)
49{
50 DebugLog(<<"RADIUSServerAuthManager::requestCredential, uri = " << msg.header(h_RequestLine).uri() << " authUser = " << user);
51
53 try
54 {
55 radiusListener = new MyRADIUSDigestAuthListener(user, realm, dum, transactionId);
56 Data radiusUser = user;
57 DebugLog(<< "radiusUser = " << radiusUser.c_str() << ", " << "user = " << user.c_str());
58
60 Data reqUri = auth.param(p_uri);
61 Data reqMethod = Data(resip::getMethodName(msg.header(h_RequestLine).getMethod()));
62
64 if(auth.exists(p_qop))
65 {
66 if(auth.param(p_qop) == Symbols::auth)
67 {
68 Data myQop("auth");
70 radiusUser, user, realm, auth.param(p_nonce),
72 auth.param(p_response),
74 }
75 else if(auth.param(p_qop) == Symbols::authInt)
76 {
77 Data myQop("auth-int");
79 radiusUser, user, realm, auth.param(p_nonce),
81 auth.param(p_opaque),
82 auth.param(p_response),
84 }
85 }
86 if(radius == NULL)
87 {
89 radiusUser, user, realm, auth.param(p_nonce),
91 auth.param(p_response),
93 }
94 int result = radius->doRADIUSCheck();
95 if(result < 0)
96 {
97 ErrLog(<<"RADIUSServerAuthManager::requestCredential, uri = " << msg.header(h_RequestLine).uri() <<" failed to start thread, error = " << result);
98 }
99 }
100 catch(...)
101 {
102 WarningLog(<<"RADIUSServerAuthManager::requestCredential, uri = " << msg.header(h_RequestLine).uri() <<" exception");
103 delete radiusListener;
104 }
105}
106
107bool
108RADIUSServerAuthManager::useAuthInt() const
109{
110 return true;
111}
112
113void
114RADIUSServerAuthManager::onAuthSuccess(const resip::SipMessage& msg)
115{
116}
117
118void
119RADIUSServerAuthManager::onAuthFailure(resip::ServerAuthManager::AuthFailureReason reason, const resip::SipMessage& msg)
120{
121 Data failureMsg("unknown failure");
122 switch(reason) {
123 case InvalidRequest:
124 failureMsg = Data("InvalidRequest");
125 break;
126 case BadCredentials:
127 failureMsg = Data("BadCredentials");
128 break;
129 case Error:
130 failureMsg = Data("Error");
131 break;
132 }
134 Data sourceIp = Data(inet_ntoa(sourceTuple.toGenericIPAddress().v4Address.sin_addr));
135 WarningLog(<<"auth failure: " << failureMsg
136 << ": src IP=" << sourceIp
137 << ", uri=" << msg.header(h_RequestLine).uri().user()
138 << ", from=" <<msg.header(h_From).uri().user()
139 << ", to=" << msg.header(h_To).uri().user());
140}
141
142MyRADIUSDigestAuthListener::MyRADIUSDigestAuthListener(
143 const resip::Data& user,
144 const resip::Data& realm,
146 const resip::Data& transactionId) :
147 user(user),
148 realm(realm),
149 tu(tu),
150 transactionId(transactionId)
151{
152}
153
154MyRADIUSDigestAuthListener::~MyRADIUSDigestAuthListener()
155{
156}
157
158void
159MyRADIUSDigestAuthListener::onSuccess(const resip::Data& rpid)
160{
161 DebugLog(<<"MyRADIUSDigestAuthListener::onSuccess");
162 if(!rpid.empty())
163 {
164 DebugLog(<<"MyRADIUSDigestAuthListener::onSuccess rpid = " << rpid.c_str());
165 }
166 else
167 {
168 DebugLog(<<"MyRADIUSDigestAuthListener::onSuccess, no rpid");
169 }
170 UserAuthInfo *uai = new UserAuthInfo(user, realm, UserAuthInfo::DigestAccepted, transactionId);
171 tu.post(uai);
172}
173
174void
175MyRADIUSDigestAuthListener::onAccessDenied()
176{
177 DebugLog(<<"MyRADIUSDigestAuthListener::onAccessDenied");
178 UserAuthInfo *uai = new UserAuthInfo(user, realm, UserAuthInfo::DigestNotAccepted, transactionId);
179 tu.post(uai);
180}
181
182void
183MyRADIUSDigestAuthListener::onError()
184{
185 WarningLog(<<"MyRADIUSDigestAuthListener::onError");
186 UserAuthInfo *uai = new UserAuthInfo(user, realm, UserAuthInfo::Error, transactionId);
187 tu.post(uai);
188}
189
190#endif
191
192/* ====================================================================
193 *
194 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
195 * Copyright 2008-2013 Daniel Pocock http://danielpocock.com
196 * All rights reserved.
197 *
198 * Redistribution and use in source and binary forms, with or without
199 * modification, are permitted provided that the following conditions
200 * are met:
201 *
202 * 1. Redistributions of source code must retain the above copyright
203 * notice, this list of conditions and the following disclaimer.
204 *
205 * 2. Redistributions in binary form must reproduce the above copyright
206 * notice, this list of conditions and the following disclaimer in
207 * the documentation and/or other materials provided with the
208 * distribution.
209 *
210 * 3. Neither the name of the author(s) nor the names of any contributors
211 * may be used to endorse or promote products derived from this software
212 * without specific prior written permission.
213 *
214 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
215 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
216 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
217 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
218 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
220 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
222 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
223 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
224 * SUCH DAMAGE.
225 *
226 * ====================================================================
227 *
228 *
229 */
230
#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.
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
MethodTypes getMethod() const
const Uri & uri() 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.
const Tuple & getSource() const
Returns the source tuple that the message was received from only makes sense for messages received fr...
The base-class for an RFC 3261 Transaction User.
Represents a network address.
Definition Tuple.hxx:59
Data & user()
Definition Uri.hxx:42
dcm! – add UnusedChecking(_enum) below;
const Data & getMethodName(MethodTypes t)
void list()
Definition userAdmin.cxx:66