|
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 DevandTruSrvCertStoreConduit |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "DevandTruSrvCertStoreConduit.h" |
|
21 #include "DevandTruSrvCertStoreServer.h" |
|
22 #include "DevTokenMarshaller.h" |
|
23 #include "DevTokenUtil.h" |
|
24 #include "DevTokenDataTypes.h" |
|
25 |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CDevandTruSrvCertStoreConduit::NewL() |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CDevandTruSrvCertStoreConduit* CDevandTruSrvCertStoreConduit::NewL(CDevandTruSrvCertStoreServer& aServer) |
|
34 { |
|
35 return new (ELeave) CDevandTruSrvCertStoreConduit(aServer); |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CDevandTruSrvCertStoreConduit::CDevandTruSrvCertStoreConduit() |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CDevandTruSrvCertStoreConduit::CDevandTruSrvCertStoreConduit(CDevandTruSrvCertStoreServer& aServer) : |
|
44 iServer(aServer) |
|
45 { |
|
46 } |
|
47 |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CDevandTruSrvCertStoreConduit::~CDevandTruSrvCertStoreConduit() |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CDevandTruSrvCertStoreConduit::~CDevandTruSrvCertStoreConduit() |
|
54 { |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CDevandTruSrvCertStoreConduit::AllocResponseBufferLC() |
|
60 // Allocate a buffer for the externalised response - this is then copied into |
|
61 // the client's buffer. |
|
62 // |
|
63 // This also checks that the client's buffer is big enough (this is assumed to |
|
64 // be in message slot 3). If the client buffer isn't big enough, the required |
|
65 // length is passed back in the first word of the buffer and the method leaves |
|
66 // with KErrOverflow. |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 HBufC8* CDevandTruSrvCertStoreConduit::AllocResponseBufferLC(TInt aSize, const RMessage2& aMessage) |
|
70 { |
|
71 TInt writeBufLen = aMessage.GetDesLengthL(3); |
|
72 |
|
73 if (aSize > writeBufLen) |
|
74 { |
|
75 TPckg<TInt> theRequiredLength(aSize); |
|
76 aMessage.WriteL(3, theRequiredLength); |
|
77 User::Leave(KErrOverflow); |
|
78 } |
|
79 |
|
80 HBufC8* result = HBufC8::NewMaxLC(aSize); |
|
81 TPtr8 ptr = result->Des(); |
|
82 ptr.FillZ(); |
|
83 |
|
84 return result; |
|
85 } |
|
86 |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CDevandTruSrvCertStoreConduit::ServiceCertStoreRequestL() |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CDevandTruSrvCertStoreConduit::ServiceCertStoreRequestL(const RMessage2& aMessage) |
|
93 { |
|
94 TDevTokenMessages request = (TDevTokenMessages) aMessage.Function(); |
|
95 TInt result = KErrNone; |
|
96 |
|
97 switch (request) |
|
98 { |
|
99 case EListCerts: |
|
100 ListCertsL(aMessage); |
|
101 break; |
|
102 |
|
103 case EGetCert: |
|
104 GetCertL(aMessage); |
|
105 break; |
|
106 |
|
107 case EApplications: |
|
108 ApplicationsL(aMessage); |
|
109 break; |
|
110 |
|
111 case EIsApplicable: |
|
112 result = IsApplicableL(aMessage); |
|
113 break; |
|
114 |
|
115 case ETrusted: |
|
116 result = TrustedL(aMessage); |
|
117 break; |
|
118 |
|
119 case ERetrieve: |
|
120 RetrieveL(aMessage); |
|
121 break; |
|
122 |
|
123 case EAddCert: |
|
124 AddCertL(aMessage); |
|
125 break; |
|
126 |
|
127 case ERemoveCert: |
|
128 RemoveCertL(aMessage); |
|
129 break; |
|
130 |
|
131 case ESetApplicability: |
|
132 SetApplicabilityL(aMessage); |
|
133 break; |
|
134 |
|
135 case ESetTrust: |
|
136 SetTrustL(aMessage); |
|
137 break; |
|
138 |
|
139 default: |
|
140 // Client made an illegal request |
|
141 PanicClient(aMessage, EPanicInvalidRequest); |
|
142 return; |
|
143 } |
|
144 |
|
145 aMessage.Complete(result); |
|
146 } |
|
147 |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CDevandTruSrvCertStoreConduit::ListCertsL() |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CDevandTruSrvCertStoreConduit::ListCertsL(const RMessage2& aMessage) |
|
154 { |
|
155 // p[1] has filter as set by the client |
|
156 |
|
157 TInt bufLength = aMessage.GetDesLengthL(1); |
|
158 HBufC8* certFilterBuf = HBufC8::NewMaxLC(bufLength); |
|
159 TPtr8 ptr(certFilterBuf->Des()); |
|
160 aMessage.ReadL(1, ptr); |
|
161 CCertAttributeFilter* certFilter = NULL; |
|
162 DevTokenDataMarshaller::ReadL(*certFilterBuf, certFilter); |
|
163 CleanupStack::PopAndDestroy(certFilterBuf); |
|
164 CleanupStack::PushL(certFilter); |
|
165 |
|
166 RPointerArray<CDevTokenCertInfo> certs; |
|
167 CleanupClosePushL(certs); |
|
168 iServer.ListL(*certFilter, certs, aMessage, EFalse ); |
|
169 |
|
170 HBufC8* clientBuffer = AllocResponseBufferLC(DevTokenDataMarshaller::Size(certs), aMessage); |
|
171 TPtr8 theData(clientBuffer->Des()); |
|
172 DevTokenDataMarshaller::Write(certs, theData); |
|
173 aMessage.WriteL(3, theData); |
|
174 CleanupStack::PopAndDestroy(3, certFilter); |
|
175 } |
|
176 |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CDevandTruSrvCertStoreConduit::GetCertL() |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 void CDevandTruSrvCertStoreConduit::GetCertL(const RMessage2& aMessage) |
|
183 { |
|
184 // p[0] is the cert handle |
|
185 |
|
186 const CDevTokenCertInfo& certInfo = iServer.GetCertL(aMessage.Int0()); |
|
187 |
|
188 HBufC8* clientBuffer = AllocResponseBufferLC(DevTokenDataMarshaller::Size(certInfo), aMessage); |
|
189 TPtr8 ptr(clientBuffer->Des()); |
|
190 DevTokenDataMarshaller::Write(certInfo, ptr); |
|
191 aMessage.WriteL(3, ptr); |
|
192 CleanupStack::PopAndDestroy(clientBuffer); |
|
193 } |
|
194 |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // CDevandTruSrvCertStoreConduit::ApplicationsL() |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CDevandTruSrvCertStoreConduit::ApplicationsL(const RMessage2& aMessage) |
|
201 { |
|
202 // p[0] is the cert handle |
|
203 |
|
204 const RArray<TUid>& apps = iServer.ApplicationsL(aMessage.Int0()); |
|
205 |
|
206 HBufC8* clientBuffer = AllocResponseBufferLC(DevTokenDataMarshaller::Size(apps), aMessage); |
|
207 TPtr8 outPtr(clientBuffer->Des()); |
|
208 DevTokenDataMarshaller::Write(apps, outPtr); |
|
209 aMessage.WriteL(3, outPtr); |
|
210 CleanupStack::PopAndDestroy(clientBuffer); |
|
211 } |
|
212 |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // CDevandTruSrvCertStoreConduit::IsApplicableL() |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 TInt CDevandTruSrvCertStoreConduit::IsApplicableL(const RMessage2& aMessage) |
|
219 { |
|
220 // p[0] is the cert handle |
|
221 // p[2] is the UID |
|
222 // p[3] to return the applicability bool |
|
223 |
|
224 TUid uid = { aMessage.Int2() }; |
|
225 TBool result = iServer.IsApplicableL(aMessage.Int0(), uid); |
|
226 return result ? 1 : 0; // Convert TBool to TInt |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // CDevandTruSrvCertStoreConduit::TrustedL() |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 TInt CDevandTruSrvCertStoreConduit::TrustedL(const RMessage2& aMessage) |
|
235 { |
|
236 // p[1] has CCertInfo in question, p[2] to return the trusted bool |
|
237 |
|
238 TBool result = iServer.TrustedL(aMessage.Int0()); |
|
239 return result ? 1 : 0; // Convert TBool to TInt |
|
240 } |
|
241 |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // CDevandTruSrvCertStoreConduit::RetrieveL() |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 void CDevandTruSrvCertStoreConduit::RetrieveL(const RMessage2& aMessage) |
|
248 { |
|
249 // p[0] is the cert handle |
|
250 // p[3] the buffer to return the retrieved certificate |
|
251 |
|
252 HBufC8* certData = iServer.RetrieveLC(aMessage.Int0(), aMessage, EFalse ); |
|
253 |
|
254 TInt maxSize = aMessage.GetDesLengthL(3); |
|
255 if (maxSize < certData->Size()) |
|
256 { |
|
257 // Client has passed in a descriptor which is too short |
|
258 User::Leave(KErrOverflow); |
|
259 } |
|
260 |
|
261 aMessage.WriteL(3, *certData); |
|
262 CleanupStack::PopAndDestroy(certData); |
|
263 } |
|
264 |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CDevandTruSrvCertStoreConduit::AddCertL() |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 void CDevandTruSrvCertStoreConduit::AddCertL(const RMessage2& aMessage) |
|
271 { |
|
272 // p[1] has TDevTokenAddCertDataStruct, p[3] has certificate data |
|
273 TPckgBuf<TDevTokenAddCertDataStruct> data; |
|
274 aMessage.ReadL(1, data); |
|
275 |
|
276 TInt maxSize = aMessage.GetDesLengthL(3); |
|
277 HBufC8* certData = HBufC8::NewMaxLC(maxSize); |
|
278 TPtr8 ptr(certData->Des()); |
|
279 ptr.FillZ(); |
|
280 aMessage.ReadL(3, ptr); |
|
281 |
|
282 iServer.AddL(data(), *certData, aMessage, EFalse ); |
|
283 |
|
284 CleanupStack::PopAndDestroy(certData); |
|
285 } |
|
286 |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 // CDevandTruSrvCertStoreConduit::RemoveCertL() |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 void CDevandTruSrvCertStoreConduit::RemoveCertL(const RMessage2& aMessage) |
|
293 { |
|
294 // p[0] is the cert handle |
|
295 |
|
296 iServer.RemoveL(aMessage.Int0(), aMessage, EFalse ); |
|
297 } |
|
298 |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // CDevandTruSrvCertStoreConduit::SetApplicabilityL() |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 void CDevandTruSrvCertStoreConduit::SetApplicabilityL(const RMessage2& aMessage) |
|
305 { |
|
306 // p[0] is the cert handle |
|
307 // p[2] the array of UIDs |
|
308 |
|
309 TInt bufLen = aMessage.GetDesLengthL(2); |
|
310 HBufC8* buf = HBufC8::NewLC(bufLen); |
|
311 TPtr8 bufPtr(buf->Des()); |
|
312 aMessage.ReadL(2, bufPtr); |
|
313 |
|
314 RArray<TUid> apps; |
|
315 CleanupClosePushL(apps); |
|
316 DevTokenDataMarshaller::ReadL(*buf, apps); |
|
317 |
|
318 iServer.SetApplicabilityL(aMessage.Int0(), apps, aMessage); |
|
319 CleanupStack::PopAndDestroy(2, buf); |
|
320 } |
|
321 |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CDevandTruSrvCertStoreConduit::SetTrustL() |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 void CDevandTruSrvCertStoreConduit::SetTrustL(const RMessage2& aMessage) |
|
328 { |
|
329 // p[0] is the cert handle |
|
330 // p[2] the trust setting |
|
331 |
|
332 TBool trusted = !!aMessage.Int2(); |
|
333 iServer.SetTrustL(aMessage.Int0(), trusted, aMessage); |
|
334 } |
|
335 |
|
336 //EOF |
|
337 |