/[resiprocate]/main/sip/resiprocate/dum/ServerAuthManager.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/dum/ServerAuthManager.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4599 - (show annotations) (download)
Wed May 11 23:10:19 2005 UTC (14 years, 8 months ago) by derek
File size: 6558 byte(s)
set svn:eol-style to LF
1 #include <cassert>
2
3 #include "resiprocate/dum/ServerAuthManager.hxx"
4 #include "resiprocate/dum/DialogUsageManager.hxx"
5 #include "resiprocate/os/Logger.hxx"
6 #include "resiprocate/dum/UserAuthInfo.hxx"
7 #include "resiprocate/Helper.hxx"
8
9 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
10
11 using namespace resip;
12
13 ServerAuthManager::ServerAuthManager(DialogUsageManager& dum) :
14 mDum(dum)
15 {
16 }
17
18
19 ServerAuthManager::~ServerAuthManager()
20 {
21 }
22
23 SipMessage*
24 ServerAuthManager::handleUserAuthInfo(UserAuthInfo* userAuth)
25 {
26 assert(userAuth);
27
28 MessageMap::iterator it = mMessages.find(userAuth->getTransactionId());
29 assert(it != mMessages.end());
30 SipMessage* requestWithAuth = it->second;
31 mMessages.erase(it);
32
33 InfoLog( << "Checking for auth result in realm=" << userAuth->getRealm()
34 << " A1=" << userAuth->getA1());
35
36 if (userAuth->getA1().empty())
37 {
38 InfoLog (<< "Account does not exist " << userAuth->getUser() << " in " << userAuth->getRealm());
39 SipMessage response;
40 Helper::makeResponse(response, *requestWithAuth, 404, "Account does not exist.");
41 mDum.send(response);
42 delete requestWithAuth;
43 return 0;
44 }
45 else
46 {
47 //!dcm! -- need to handle stale/unit test advancedAuthenticateRequest
48 //!dcm! -- delta? deal with.
49 std::pair<Helper::AuthResult,Data> resPair =
50 Helper::advancedAuthenticateRequest(*requestWithAuth,
51 userAuth->getRealm(),
52 userAuth->getA1(),
53 3000);
54 if (resPair.first == Helper::Authenticated)
55 {
56 InfoLog (<< "Authorized request for " << userAuth->getRealm());
57 return requestWithAuth;
58 }
59 else
60 {
61 InfoLog (<< "Invalid password provided " << userAuth->getUser() << " in " << userAuth->getRealm());
62
63 SipMessage response;
64 Helper::makeResponse(response, *requestWithAuth, 403, "Invalid password provided");
65 mDum.send(response);
66 delete requestWithAuth;
67 return 0;
68 }
69 }
70 }
71
72 // return true if request has been consumed
73 ServerAuthManager::Result
74 ServerAuthManager::handle(const SipMessage& sipMsg)
75 {
76 //InfoLog( << "trying to do auth" );
77 if (sipMsg.isRequest())
78 {
79 if (!sipMsg.exists(h_ProxyAuthorizations))
80 {
81 //assume TransactionUser has matched/repaired a realm
82 SipMessage* challenge = Helper::makeProxyChallenge(sipMsg,
83 sipMsg.header(h_RequestLine).uri().host(),
84 true,
85 false);
86 InfoLog (<< "Sending challenge to " << sipMsg.brief());
87 mDum.send(*challenge);
88 delete challenge;
89 return Challenged;
90 }
91
92 try
93 {
94 for(Auths::const_iterator it = sipMsg.header(h_ProxyAuthorizations).begin();
95 it != sipMsg.header(h_ProxyAuthorizations).end(); it++)
96 {
97 if (mDum.isMyDomain(it->param(p_realm)))
98 {
99 InfoLog (<< "Requesting credential for "
100 << it->param(p_username) << " @ " << it->param(p_realm));
101
102 requestCredential(it->param(p_username),
103 it->param(p_realm),
104 sipMsg.getTransactionId());
105 mMessages[sipMsg.getTransactionId()] = static_cast<SipMessage*>(sipMsg.clone());
106 return RequestedCredentials;
107 }
108 }
109
110 InfoLog (<< "Didn't find matching realm ");
111 SipMessage response;
112 Helper::makeResponse(response, sipMsg, 404, "Account does not exist");
113 mDum.send(response);
114 return Rejected;
115 }
116 catch(BaseException& e)
117 {
118 InfoLog (<< "Invalid auth header provided " << e);
119 SipMessage response;
120 Helper::makeResponse(response, sipMsg, 400, "Invalid auth header");
121 mDum.send(response);
122 return Rejected;
123 }
124 }
125 return Skipped;
126 }
127
128
129
130
131
132
133 /* ====================================================================
134 * The Vovida Software License, Version 1.0
135 *
136 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
137 *
138 * Redistribution and use in source and binary forms, with or without
139 * modification, are permitted provided that the following conditions
140 * are met:
141 *
142 * 1. Redistributions of source code must retain the above copyright
143 * notice, this list of conditions and the following disclaimer.
144 *
145 * 2. Redistributions in binary form must reproduce the above copyright
146 * notice, this list of conditions and the following disclaimer in
147 * the documentation and/or other materials provided with the
148 * distribution.
149 *
150 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
151 * and "Vovida Open Communication Application Library (VOCAL)" must
152 * not be used to endorse or promote products derived from this
153 * software without prior written permission. For written
154 * permission, please contact vocal@vovida.org.
155 *
156 * 4. Products derived from this software may not be called "VOCAL", nor
157 * may "VOCAL" appear in their name, without prior written
158 * permission of Vovida Networks, Inc.
159 *
160 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
161 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
162 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
163 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
164 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
165 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
166 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
167 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
168 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
169 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
170 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
171 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
172 * DAMAGE.
173 *
174 * ====================================================================
175 *
176 * This software consists of voluntary contributions made by Vovida
177 * Networks, Inc. and many individuals on behalf of Vovida Networks,
178 * Inc. For more information on Vovida Networks, Inc., please see
179 * <http://www.vovida.org/>.
180 *
181 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27