|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : CSIPSecDigestCacheEntry.cpp |
|
15 // Part of : SIPSec |
|
16 // Version : SIP/6.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CSIPSecDigestCacheEntry.h" |
|
22 #include "sipsecplugincontext.h" |
|
23 #include "CSIPSecUserRecord.h" |
|
24 #include "CSIPSecSIMRecord.h" |
|
25 #include "MSIPSecUser.h" |
|
26 #include <uri8.h> |
|
27 |
|
28 |
|
29 const TInt CSIPSecDigestCacheEntry::iSIPSecOffset = |
|
30 _FOFF( CSIPSecDigestCacheEntry, iLink ); |
|
31 |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ---------------------------------------------------------------------------- |
|
36 // CSIPSecDigestCacheEntry::CSIPSecDigestCacheEntry |
|
37 // ---------------------------------------------------------------------------- |
|
38 // |
|
39 CSIPSecDigestCacheEntry::CSIPSecDigestCacheEntry( const MSIPSecUser& aUser ) : |
|
40 iUser( aUser ) |
|
41 { |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CSIPSecDigestCacheEntry::ConstructL |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
|
48 void CSIPSecDigestCacheEntry::ConstructL( CSIPSecDigest::TChallengeType aType, |
|
49 const CUri8& aRemoteTarget ) |
|
50 { |
|
51 if ( aType == CSIPSecDigest::EEndPoint ) |
|
52 { |
|
53 iRemoteTarget = CUri8::NewL( aRemoteTarget.Uri() ); |
|
54 } |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CSIPSecDigestCacheEntry::~CSIPSecDigestCacheEntry |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 CSIPSecDigestCacheEntry::~CSIPSecDigestCacheEntry() |
|
62 { |
|
63 delete iRemoteTarget; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CSIPSecDigestCacheEntry::UserData |
|
68 // Once CSIPSecDigestCacheEntry has been constructed, iUserCredentials always |
|
69 // exist. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CSIPSecUserRecord& CSIPSecDigestCacheEntry::UserData() |
|
73 { |
|
74 __ASSERT_ALWAYS( iUserCredentials, |
|
75 User::Panic( _L( "DigestCacheEntry:UserData !cred" ), KErrNotFound ) ); |
|
76 |
|
77 return *iUserCredentials; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CSIPSecDigestCacheEntry::HoldsUserData |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 TBool CSIPSecDigestCacheEntry::HoldsUserData( |
|
85 const CSIPSecUserRecord& aUserData ) const |
|
86 { |
|
87 return iUserCredentials == &aUserData; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CSIPSecDigestCacheEntry::SetUserData |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CSIPSecDigestCacheEntry::SetUserData( CSIPSecUserRecord& aUserData ) |
|
95 { |
|
96 iUserCredentials = &aUserData; |
|
97 iUserCredentials->CredentialsAttach(); |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // CSIPSecDigestCacheEntry::Match |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 TBool CSIPSecDigestCacheEntry::Match( TSIPSecPluginContext& aContext ) const |
|
105 { |
|
106 __ASSERT_ALWAYS( iUserCredentials, |
|
107 User::Panic( _L( "DigestCacheEntry:Match !cred" ), KErrNotFound ) ); |
|
108 |
|
109 if ( IsUsedByUser( aContext.SIPSecUser(), |
|
110 aContext.AlsoTrustedUser(), |
|
111 aContext.RegistrationId() ) ) |
|
112 { |
|
113 switch ( Type( aContext ) ) |
|
114 { |
|
115 case CSIPSecDigest::EOutboundProxy: |
|
116 return iUserCredentials->OutboundProxy().CompareF( |
|
117 aContext.OutboundProxy() ) == 0; |
|
118 |
|
119 case CSIPSecDigest::EProxy: |
|
120 return ETrue; // IsUsedByUser checked that SIPSec user is same |
|
121 |
|
122 default: // CSIPSecDigest::EEndPoint: |
|
123 return iRemoteTarget && |
|
124 ( iRemoteTarget->Uri().Equivalent( |
|
125 aContext.RemoteTarget().Uri() ) == KErrNone ); |
|
126 } |
|
127 } |
|
128 |
|
129 return EFalse; |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // CSIPSecDigestCacheEntry::IsUsedByUser |
|
134 // ---------------------------------------------------------------------------- |
|
135 // |
|
136 TBool CSIPSecDigestCacheEntry::IsUsedByUser( const MSIPSecUser& aUser, |
|
137 TBool aAlsoTrustedUser, |
|
138 TRegistrationId aRegistrationId ) const |
|
139 { |
|
140 return CompareUsers( aUser, iUser, aAlsoTrustedUser, aRegistrationId ); |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // CSIPSecDigestCacheEntry::CompareUsers |
|
145 // SIPSec user can have only one trusted user. I.e. a trusted user doesn't |
|
146 // have another trusted user. |
|
147 // ---------------------------------------------------------------------------- |
|
148 // |
|
149 TBool CSIPSecDigestCacheEntry::CompareUsers( const MSIPSecUser& aUser, |
|
150 const MSIPSecUser& aCachedUser, |
|
151 TBool aAlsoTrustedUser, |
|
152 TRegistrationId aRegistrationId ) |
|
153 { |
|
154 MSIPSecUser* user = const_cast< MSIPSecUser* >( &aUser ); |
|
155 return ( user == &aCachedUser ) || |
|
156 ( aAlsoTrustedUser && |
|
157 user->TrustedUser( aRegistrationId ) == &aCachedUser ); |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // CSIPSecDigestCacheEntry::SIPSecUser |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 const MSIPSecUser& CSIPSecDigestCacheEntry::SIPSecUser() const |
|
165 { |
|
166 return iUser; |
|
167 } |