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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4062 by derek, Sun Mar 27 02:00:20 2005 UTC revision 4335 by jason, Tue Apr 12 21:40:15 2005 UTC
# Line 1  Line 1 
 #include "ServerAuthManager.hxx"  
1  #include <cassert>  #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  #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
10    
11  using namespace resip;  using namespace resip;
12    
13    ServerAuthManager::ServerAuthManager(DialogUsageManager& dum) :
14       mDum(dum)
15    {
16    }
17    
18    
19    ServerAuthManager::~ServerAuthManager()
20    {
21    }
22    
23  bool  bool
24  ServerAuthManager::handle(UserProfile& userProfile, const SipMessage& response)  ServerAuthManager::handleUserAuthInfo(std::auto_ptr<Message>& msg)
25    {
26       InfoLog( << "Checking for auth result" );
27    
28       std::auto_ptr<UserAuthInfo> userAuth(dynamic_cast<UserAuthInfo*>(msg.get()));
29      
30       if (!userAuth.get())
31       {
32          return false;
33       }
34    
35       MessageMap::iterator it = mMessages.find(userAuth->getTransactionId());
36       assert(it != mMessages.end());
37       SipMessage* requestWithAuth = it->second;
38       mMessages.erase(it);
39       if (userAuth->getA1().empty())
40  {  {
41     assert(0);        InfoLog (<< "Account does not exist " << userAuth->getUser() << " in " << userAuth->getRealm());
42          SipMessage response;
43          Helper::makeResponse(*requestWithAuth, 404, "Account does not exist.");
44          mDum.send(response);
45          delete requestWithAuth;
46     return true;     return true;
47  }  }
48       else
49       {
50          //!dcm! -- need to handle stale/unit test advancedAuthenticateRequest
51          //!dcm! -- delta? deal with.
52          std::pair<Helper::AuthResult,Data> resPair =
53             Helper::advancedAuthenticateRequest(*requestWithAuth,
54                                                 userAuth->getRealm(),
55                                                 userAuth->getA1(),
56                                                 3000);
57          
58          if (resPair.first == Helper::Authenticated)
59          {
60             InfoLog (<< "Retrieved stored message with challenge and passed on to dum");
61             msg = std::auto_ptr<Message>(requestWithAuth);
62             return false;
63          }
64          else
65          {
66             InfoLog (<< "Invalid password provided " << userAuth->getUser() << " in " << userAuth->getRealm());
67    
68             SipMessage response;
69             Helper::makeResponse(*requestWithAuth, 403, "Invalid password provided");
70             mDum.send(response);
71             delete requestWithAuth;
72             return true;
73          }
74       }
75    }
76          
77    // return true if request has been consumed
78    bool
79    ServerAuthManager::handle(std::auto_ptr<Message>& msg)
80    {
81       //InfoLog( << "trying to do auth" );
82    
83       SipMessage* sipMsg = dynamic_cast<SipMessage*>(msg.get());
84       assert(sipMsg);
85      
86       if (sipMsg->isResponse())
87       {
88          return false;
89       }
90    
91       if (!sipMsg->exists(h_ProxyAuthorizations))
92       {
93          //assume TransactionUser has matched/repaired a realm
94          SipMessage* challenge =
95             Helper::makeProxyChallenge(*sipMsg,
96                                        sipMsg->header(h_RequestLine).uri().host(),
97                                        true,
98                                        false);
99          mDum.send(*challenge);
100          delete challenge;
101          return true;
102       }
103    
104       try
105       {
106          for(Auths::iterator it = sipMsg->header(h_ProxyAuthorizations).begin();
107              it  != sipMsg->header(h_ProxyAuthorizations).end(); it++)
108          {
109             if (mDum.isMyDomain(it->param(p_realm)))
110             {
111                requestCredential(it->param(p_username),
112                                  it->param(p_realm),
113                                  sipMsg->getTransactionId());
114                mMessages[sipMsg->getTransactionId()] = sipMsg;
115                msg.release();
116                return true;
117             }
118          }
119          return false;
120       }
121       catch(BaseException& e)
122       {
123          InfoLog (<< "Invalid auth header provided " << e);
124          SipMessage response;
125          Helper::makeResponse(*sipMsg, 400, "Invalid auth header");
126          mDum.send(response);
127          return true;
128       }
129    }
130    
131    
132    
133    
134    
135    
136  /* ====================================================================  /* ====================================================================

Legend:
Removed from v.4062  
changed lines
  Added in v.4335

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27