1 |
#if !defined(RESIP_CLIENTAUTHMANAGER_HXX) |
2 |
#define RESIP_CLIENTAUTHMANAGER_HXX |
3 |
|
4 |
#include "resip/dum/DialogSetId.hxx" |
5 |
#include "resip/dum/UserProfile.hxx" |
6 |
#include "rutil/SharedPtr.hxx" |
7 |
|
8 |
#include <map> |
9 |
#include <functional> |
10 |
|
11 |
namespace resip |
12 |
{ |
13 |
|
14 |
class Auth; |
15 |
class SipMessage; |
16 |
class ClientAuthExtension; |
17 |
|
18 |
|
19 |
class ClientAuthManager |
20 |
{ |
21 |
public: |
22 |
ClientAuthManager(); |
23 |
virtual ~ClientAuthManager() {} |
24 |
|
25 |
// For any response received by the UAC, handle will be |
26 |
// called. origRequest is the request that generated the 401/407. |
27 |
// return true if the challenge can be handled with an updated request. |
28 |
// This will increment the CSeq on origRequest |
29 |
virtual bool handle(UserProfile& userProfile, SipMessage& origRequest, const SipMessage& response); |
30 |
|
31 |
// |
32 |
virtual void addAuthentication(SipMessage& origRequest); |
33 |
virtual void clearAuthenticationState(const DialogSetId& dsId); |
34 |
|
35 |
private: |
36 |
friend class DialogSet; |
37 |
virtual void dialogSetDestroyed(const DialogSetId& dsId); |
38 |
|
39 |
// class CompareAuth : public std::binary_function<const Auth&, const Auth&, bool> |
40 |
// { |
41 |
// public: |
42 |
// bool operator()(const Auth& lhs, const Auth& rhs) const; |
43 |
// }; |
44 |
|
45 |
class RealmState |
46 |
{ |
47 |
public: |
48 |
RealmState(); |
49 |
|
50 |
void clear(); |
51 |
|
52 |
bool handleAuth(UserProfile& userProfile, const Auth& auth, bool isProxyCredential); |
53 |
void authSucceeded(); |
54 |
|
55 |
void addAuthentication(SipMessage& origRequest); |
56 |
private: |
57 |
typedef enum |
58 |
{ |
59 |
Invalid, |
60 |
Cached, |
61 |
Current, |
62 |
TryOnce, |
63 |
Failed |
64 |
} State; |
65 |
|
66 |
void transition(State s); |
67 |
static const Data& getStateString(State s); |
68 |
bool findCredential(UserProfile& userProfile, const Auth& auth); |
69 |
UserProfile::DigestCredential mCredential; |
70 |
bool mIsProxyCredential; |
71 |
|
72 |
State mState; |
73 |
unsigned int mNonceCount; |
74 |
Auth mAuth; |
75 |
|
76 |
// FH add the realm state so it can change |
77 |
Auth *mAuthPtr; |
78 |
|
79 |
// .dcm. only one credential per realm per challenge supported |
80 |
// typedef std::map<Auth, UserProfile::DigestCredential, CompareAuth > CredentialMap; |
81 |
// CredentialMap proxyCredentials; |
82 |
// CredentialMap wwwCredentials; |
83 |
}; |
84 |
|
85 |
class AuthState |
86 |
{ |
87 |
public: |
88 |
AuthState(); |
89 |
bool handleChallenge(UserProfile& userProfile, const SipMessage& challenge); |
90 |
void addAuthentication(SipMessage& origRequest); |
91 |
void authSucceeded(); |
92 |
|
93 |
private: |
94 |
typedef std::map<Data, RealmState> RealmStates; |
95 |
RealmStates mRealms; |
96 |
bool mFailed; |
97 |
unsigned long mCacheUseLimit; |
98 |
unsigned long mCacheUseCount; |
99 |
}; |
100 |
|
101 |
typedef std::map<DialogSetId, AuthState> AttemptedAuthMap; |
102 |
AttemptedAuthMap mAttemptedAuths; |
103 |
}; |
104 |
|
105 |
} |
106 |
|
107 |
#endif |
108 |
|
109 |
/* ==================================================================== |
110 |
* The Vovida Software License, Version 1.0 |
111 |
* |
112 |
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. |
113 |
* |
114 |
* Redistribution and use in source and binary forms, with or without |
115 |
* modification, are permitted provided that the following conditions |
116 |
* are met: |
117 |
* |
118 |
* 1. Redistributions of source code must retain the above copyright |
119 |
* notice, this list of conditions and the following disclaimer. |
120 |
* |
121 |
* 2. Redistributions in binary form must reproduce the above copyright |
122 |
* notice, this list of conditions and the following disclaimer in |
123 |
* the documentation and/or other materials provided with the |
124 |
* distribution. |
125 |
* |
126 |
* 3. The names "VOCAL", "Vovida Open Communication Application Library", |
127 |
* and "Vovida Open Communication Application Library (VOCAL)" must |
128 |
* not be used to endorse or promote products derived from this |
129 |
* software without prior written permission. For written |
130 |
* permission, please contact vocal@vovida.org. |
131 |
* |
132 |
* 4. Products derived from this software may not be called "VOCAL", nor |
133 |
* may "VOCAL" appear in their name, without prior written |
134 |
* permission of Vovida Networks, Inc. |
135 |
* |
136 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
137 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
138 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND |
139 |
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA |
140 |
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES |
141 |
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, |
142 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
143 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
144 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
145 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
146 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
147 |
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
148 |
* DAMAGE. |
149 |
* |
150 |
* ==================================================================== |
151 |
* |
152 |
* This software consists of voluntary contributions made by Vovida |
153 |
* Networks, Inc. and many individuals on behalf of Vovida Networks, |
154 |
* Inc. For more information on Vovida Networks, Inc., please see |
155 |
* <http://www.vovida.org/>. |
156 |
* |
157 |
*/ |