|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of TrustedSitesStore |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <x509cert.h> |
|
21 #include "TrustedSitesStore.h" |
|
22 #include "DevandTruSrvCertStore.h" |
|
23 #include "DevTokenType.h" |
|
24 #include "DevToken.h" |
|
25 #include "DevTokenUtils.h" |
|
26 #include "DevTokenImplementationUID.hrh" |
|
27 |
|
28 const TInt KSHA1Length = 20; |
|
29 |
|
30 // Define the default size. If overflow, the function |
|
31 // SendSyncRequestAndHandleOverflowL() will handle. |
|
32 const TInt KDefaultBufferSize = 256; |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CTrustSitesStore::NewL() |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CTrustSitesStore* CTrustSitesStore::NewL() |
|
41 { |
|
42 CTrustSitesStore* me = new (ELeave) CTrustSitesStore(); |
|
43 CleanupStack::PushL(me); |
|
44 me->ConstructL(); |
|
45 CleanupStack::Pop(me); |
|
46 return (me); |
|
47 } |
|
48 |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CTrustSitesStore::CTrustSitesStore() |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CTrustSitesStore::CTrustSitesStore() : |
|
55 iRequestPtr(NULL, 0, 0) |
|
56 { |
|
57 } |
|
58 |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CTrustSitesStore::~CTrustSitesStore() |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C CTrustSitesStore::~CTrustSitesStore() |
|
65 { |
|
66 FreeRequestBuffer(); |
|
67 if ( iClientSession ) |
|
68 { |
|
69 iClientSession->Close(); |
|
70 delete iClientSession; |
|
71 } |
|
72 } |
|
73 |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CTrustSitesStore::ConstructL() |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CTrustSitesStore::ConstructL() |
|
80 { |
|
81 iClientSession = RDevTokenClientSession::ClientSessionL(); |
|
82 User::LeaveIfError(iClientSession->Connect(ETruSitesStore)); |
|
83 } |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CTrustSitesStore::AddL() |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C TInt CTrustSitesStore::AddL( const TDesC8& aCertificate, const TDesC& aTrustedSite ) |
|
91 { |
|
92 if( !(aCertificate.Length() > KSHA1Length) || !( aTrustedSite.Length() > 0) ) |
|
93 { |
|
94 User::LeaveIfError(KErrArgument); |
|
95 } |
|
96 |
|
97 CX509Certificate* cert = CX509Certificate::NewL(aCertificate); |
|
98 TBuf8<KSHA1Length> certHash; |
|
99 certHash.Copy(cert->Fingerprint()); |
|
100 delete cert; |
|
101 |
|
102 TIpcArgs args(&certHash, &aTrustedSite, NULL, NULL); |
|
103 TInt r = iClientSession->SendRequest(EAddTrustSite, args); |
|
104 return r; |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CTrustSitesStore::AddForgivenSiteL() |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C TInt CTrustSitesStore::AddForgivenSiteL( const TDesC& aSite, const TBool& aIsOutOfDateAllowed ) |
|
113 { |
|
114 if( !( aSite.Length() > 0) ) |
|
115 { |
|
116 User::LeaveIfError(KErrArgument); |
|
117 } |
|
118 |
|
119 TIpcArgs args( &aSite, aIsOutOfDateAllowed ); |
|
120 TInt r = iClientSession->SendRequest(EAddForgivenSite, args); |
|
121 return r; |
|
122 } |
|
123 |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CTrustSitesStore::RemoveForgivenSiteL() |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 EXPORT_C TInt CTrustSitesStore::RemoveForgivenSiteL( const TDesC& aSite ) |
|
130 { |
|
131 TIpcArgs args( &aSite ); |
|
132 TInt r = iClientSession->SendRequest(ERemoveForgivenSite, args); |
|
133 return r; |
|
134 } |
|
135 |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CTrustSitesStore::IsOutOfDateAllowedL() |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C TBool CTrustSitesStore::IsOutOfDateAllowedL( const TDesC8& aCertificate, const TDesC& aTrustedSite ) |
|
142 { |
|
143 if( !(aCertificate.Length() > 0) || !( aTrustedSite.Length() > 0) ) |
|
144 { |
|
145 User::LeaveIfError(KErrArgument); |
|
146 } |
|
147 |
|
148 CX509Certificate* cert = CX509Certificate::NewL(aCertificate); |
|
149 TBuf8<KSHA1Length> certHash; |
|
150 certHash.Copy(cert->Fingerprint()); |
|
151 delete cert; |
|
152 cert = NULL; |
|
153 |
|
154 TIpcArgs args(&certHash, &aTrustedSite ); |
|
155 TInt r = iClientSession->SendRequest(EIsOutOfDateAllowed, args); |
|
156 if( r > 0 ) |
|
157 { |
|
158 return ETrue; |
|
159 } |
|
160 else |
|
161 { |
|
162 return EFalse; |
|
163 } |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CTrustSitesStore::IsTrustedSiteL() |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C TBool CTrustSitesStore::IsTrustedSiteL( const TDesC8& aCertificate, const TDesC& aTrustedSite ) |
|
171 { |
|
172 if( !(aCertificate.Length() > 0) || !( aTrustedSite.Length() > 0) ) |
|
173 { |
|
174 User::LeaveIfError(KErrArgument); |
|
175 } |
|
176 |
|
177 CX509Certificate* cert = CX509Certificate::NewL(aCertificate); |
|
178 TBuf8<KSHA1Length> certHash; |
|
179 certHash.Copy(cert->Fingerprint()); |
|
180 delete cert; |
|
181 cert = NULL; |
|
182 |
|
183 TIpcArgs args(&certHash, &aTrustedSite, &aCertificate ); |
|
184 TInt r = iClientSession->SendRequest(EIsTrustedSite, args); |
|
185 if( r > 0 ) |
|
186 { |
|
187 return ETrue; |
|
188 } |
|
189 else |
|
190 { |
|
191 return EFalse; |
|
192 } |
|
193 } |
|
194 |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CTrustSitesStore::GetTrustedSitesL() |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 EXPORT_C TInt CTrustSitesStore::GetTrustedSitesL( const TDesC8& aCertificate, RPointerArray<HBufC>& aListOfSites ) |
|
201 { |
|
202 if( !(aCertificate.Length() > 0 ) ) |
|
203 { |
|
204 User::LeaveIfError(KErrArgument); |
|
205 } |
|
206 |
|
207 CX509Certificate* cert = CX509Certificate::NewL(aCertificate); |
|
208 TBuf8<KSHA1Length> certHash; |
|
209 certHash.Copy(cert->Fingerprint()); |
|
210 delete cert; |
|
211 cert = NULL; |
|
212 |
|
213 TIpcArgs args( &certHash, &iRequestPtr, NULL, NULL ); |
|
214 |
|
215 TRAPD(err, SendSyncRequestAndHandleOverflowL(KDefaultBufferSize, args)); |
|
216 if(err!=KErrNone) |
|
217 { |
|
218 return err; |
|
219 } |
|
220 |
|
221 TRAP(err, DevTokenDataMarshaller::ReadL( iRequestPtr, aListOfSites )); |
|
222 if( err!= KErrNone ) |
|
223 { |
|
224 return err; |
|
225 } |
|
226 return KErrNone; |
|
227 } |
|
228 |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CTrustSitesStore::RemoveL() |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 /*EXPORT_C TInt CTrustSitesStore::RemoveL( const TDesC8& aCertificate ) |
|
235 { |
|
236 if( !(aCertificate.Length() > 0 ) ) |
|
237 { |
|
238 User::LeaveIfError(KErrArgument); |
|
239 } |
|
240 |
|
241 CX509Certificate* cert = CX509Certificate::NewL(aCertificate); |
|
242 TBuf8<KSHA1Length> certHash; |
|
243 certHash.Copy(cert->Fingerprint()); |
|
244 |
|
245 TIpcArgs args( &certHash, NULL, NULL, NULL ); |
|
246 |
|
247 TInt r = iClientSession->SendRequest(ERemove, args); |
|
248 return r; |
|
249 }*/ |
|
250 |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CTrustSitesStore::FreeRequestBuffer() |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 void CTrustSitesStore::FreeRequestBuffer() |
|
257 { |
|
258 delete iRequestDataBuf; |
|
259 iRequestDataBuf = NULL; |
|
260 iRequestPtr.Set(NULL, 0, 0); |
|
261 } |
|
262 |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CTrustSitesStore::AllocRequestBuffer() |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 TInt CTrustSitesStore::AllocRequestBuffer(TInt aReqdSize) |
|
269 { |
|
270 ASSERT(aReqdSize > 0); |
|
271 TInt result = KErrNoMemory; |
|
272 |
|
273 FreeRequestBuffer(); |
|
274 iRequestDataBuf = HBufC8::NewMax(aReqdSize); |
|
275 if (iRequestDataBuf) |
|
276 { |
|
277 iRequestPtr.Set(iRequestDataBuf->Des()); |
|
278 iRequestPtr.FillZ(); |
|
279 result = KErrNone; |
|
280 } |
|
281 |
|
282 return result; |
|
283 } |
|
284 |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CTrustSitesStore::SendSyncRequestAndHandleOverflowL() |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CTrustSitesStore::SendSyncRequestAndHandleOverflowL(TInt aInitialBufSize, |
|
291 const TIpcArgs& aArgs) |
|
292 { |
|
293 |
|
294 TDevTokenMessages message; |
|
295 message = EGetTrustedSites; |
|
296 |
|
297 User::LeaveIfError(AllocRequestBuffer(aInitialBufSize)); |
|
298 |
|
299 TInt err = iClientSession->SendRequest(message, aArgs); |
|
300 if (err == KErrOverflow) |
|
301 { |
|
302 TInt sizeReqd = 0; |
|
303 TPckg<TInt> theSize(sizeReqd); |
|
304 theSize.Copy(iRequestPtr); |
|
305 User::LeaveIfError(AllocRequestBuffer(sizeReqd)); |
|
306 err = iClientSession->SendRequest(message, aArgs); |
|
307 } |
|
308 |
|
309 User::LeaveIfError(err); |
|
310 } |
|
311 |
|
312 //EOF |
|
313 |
|
314 |
|
315 |