reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
UserAgentServerAuthManager.cxx
Go to the documentation of this file.
1#include "rutil/ResipAssert.h"
2
3#include "UserAgent.hxx"
5
12
13#define RESIPROCATE_SUBSYSTEM Subsystem::RECON
14
15using namespace recon;
16using namespace resip;
17
19 ServerAuthManager(userAgent.getDialogUsageManager(), userAgent.getDialogUsageManager().dumIncomingTarget()),
20 mUserAgent(userAgent)
21{
22}
23
27
28bool
30{
31 return true;
32}
33
34bool
36{
37 return false; // Challenge with 401
38}
39
40const Data&
42{
43 return mUserAgent.getIncomingConversationProfile(msg)->getDefaultFrom().uri().host();
44}
45
46bool
48{
49 return true; // .slg. this means we will try to find credentials for any authorization headers
50 // could improve this by looking through all active conversation profiles to see if realm exists
51}
52
53bool
55 const resip::Data &realm,
56 resip::Uri &fromUri)
57{
58 return true; // We don't care who the request came from
59}
60
63{
65 const auto profile = mUserAgent.getIncomingConversationProfile(msg);
66
67 // We want to challenge OOD Refer requests and Invite Requests with Auto-Answer indications
68 switch(msg.method())
69 {
70 case REFER:
71 if(profile->challengeOODReferRequests() && !msg.header(h_To).exists(p_tag))
72 {
73 // Don't challenge OOD Refer requests have a valid TargetDialog header
74 if(!msg.exists(h_TargetDialog) || mUserAgent.getDialogUsageManager().findInviteSession(msg.header(h_TargetDialog)).first == InviteSessionHandle::NotValid())
75 {
76 return True;
77 }
78 }
79 break;
80
81 case INVITE:
82 if(profile->challengeAutoAnswerRequests() && profile->shouldAutoAnswer(msg))
83 {
84 return True;
85 }
86 break;
87 default:
88 break;
89 }
90
91 // Default to not challenge
92 return False;
93}
94
95void
97 const Data& realm,
98 const SipMessage& msg,
99 const Auth& auth,
100 const Data& transactionId )
101{
102 const UserProfile::DigestCredential& digestCredential =
103 mUserAgent.getIncomingConversationProfile(msg)->getDigestCredential(realm);
104
105 DigestStream a1;
106 a1 << digestCredential.user
108 << digestCredential.realm
110 << digestCredential.password;
111 a1.flush();
112 UserAuthInfo* userAuthInfo = new UserAuthInfo(user,realm,a1.getHex(),transactionId);
113 mUserAgent.getDialogUsageManager().post( userAuthInfo );
114}
115
116
117/* ====================================================================
118
119 Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
120 Copyright (c) 2007-2008, Plantronics, Inc.
121 All rights reserved.
122
123 Redistribution and use in source and binary forms, with or without
124 modification, are permitted provided that the following conditions are
125 met:
126
127 1. Redistributions of source code must retain the above copyright
128 notice, this list of conditions and the following disclaimer.
129
130 2. Redistributions in binary form must reproduce the above copyright
131 notice, this list of conditions and the following disclaimer in the
132 documentation and/or other materials provided with the distribution.
133
134 3. Neither the name of Plantronics nor the names of its contributors
135 may be used to endorse or promote products derived from this
136 software without specific prior written permission.
137
138 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
139 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
140 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
141 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
142 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
143 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
144 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
145 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
146 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
147 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
148 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
149
150 ==================================================================== */
#define resip_assert(x)
This file needs to work for both C and C++ code.
virtual bool isMyRealm(const resip::Data &realm)
should return true if realm passed in is ours and we can challenge
virtual const resip::Data & getChallengeRealm(const resip::SipMessage &msg)
returns the realm to be used for the challenge
virtual bool authorizedForThisIdentity(const resip::Data &user, const resip::Data &realm, resip::Uri &fromUri)
should return true if the passed in user is authorized for the provided uri
virtual resip::AsyncBool requiresChallenge(const resip::SipMessage &msg)
should return true if the request must be challenged The default is to challenge all requests - overr...
virtual void requestCredential(const resip::Data &user, const resip::Data &realm, const resip::SipMessage &msg, const resip::Auth &auth, const resip::Data &transactionId)
This class is one of two main classes of concern to an application using the UserAgent library.
Definition UserAgent.hxx:56
resip::DialogUsageManager & getDialogUsageManager()
virtual std::shared_ptr< ConversationProfile > getIncomingConversationProfile(const resip::SipMessage &msg)
Represents the "credentials" and "challenge" elements in the SIP grammar.
Definition Auth.hxx:18
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
InviteSessionHandle findInviteSession(const DialogId &id)
Used to accumlate data written to the stream in a DigestBuffer and convert the data to Digest.
Data getHex()
Calls flush() on itself and returns the Digest data in hex format.
static Handle< InviteSession > NotValid()
Definition Handle.hxx:84
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.
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
static const char * COLON
Definition Symbols.hxx:15
void post(Message *msg)
Posts a Message to this TransactionUser's fifo.
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
dcm! – add UnusedChecking(_enum) below;