|
1 /* |
|
2 * Copyright (c) 2003-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: PKI Service API |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <e32math.h> |
|
22 |
|
23 #include "pkiserviceapi.h" |
|
24 #include "clistatic.h" |
|
25 #include "pkcs10.h" |
|
26 #include "pkiserviceclientservercommon.h" |
|
27 #include "pkisession.h" |
|
28 |
|
29 #include <certificateapps.h> |
|
30 |
|
31 |
|
32 /**--------------------------------------------------------- |
|
33 * |
|
34 * RPKIServiceAPI class constructor |
|
35 * |
|
36 *----------------------------------------------------------*/ |
|
37 |
|
38 EXPORT_C RPKIServiceAPI::RPKIServiceAPI() |
|
39 { |
|
40 } |
|
41 |
|
42 EXPORT_C TInt RPKIServiceAPI::Connect() |
|
43 // |
|
44 // Connect to the server attempting to start it if necessary |
|
45 // |
|
46 { |
|
47 TInt retry=2; |
|
48 for (;;) |
|
49 { |
|
50 TInt r=CreateSession(KPkiServerName, |
|
51 TVersion(KPkiMajorVersion, |
|
52 KPkiMinorVersion, |
|
53 KPkiBuildVersion), |
|
54 KDefaultMessageSlots); |
|
55 |
|
56 if (r!=KErrNotFound && r!=KErrServerTerminated) |
|
57 { |
|
58 if (r == KErrNone) |
|
59 { |
|
60 r = SendReceive(PkiService::EInitialize,TIpcArgs(NULL)); |
|
61 if (r != KErrNone) |
|
62 { |
|
63 RSessionBase::Close(); |
|
64 } |
|
65 } |
|
66 return r; |
|
67 } |
|
68 if (--retry==0) |
|
69 return r; |
|
70 r = Launcher::LaunchServer(KPkiServerName, KPkiServerImg, |
|
71 KPkiServiceUid3, KMyServerInitHeapSize, |
|
72 KMyServerMaxHeapSize, KMyServerStackSize); |
|
73 |
|
74 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
75 return r; |
|
76 } |
|
77 } |
|
78 |
|
79 /**--------------------------------------------------------- |
|
80 * |
|
81 * Logon(TRequestStatus& aRequestStatus) |
|
82 * |
|
83 * |
|
84 * |
|
85 *----------------------------------------------------------*/ |
|
86 EXPORT_C void RPKIServiceAPI::Logon(TRequestStatus& aRequestStatus) |
|
87 { |
|
88 SendReceive(PkiService::ELogon,TIpcArgs(NULL), aRequestStatus); |
|
89 } |
|
90 |
|
91 /**---------------------------------------------------------- |
|
92 * Lock keystore |
|
93 * PIN code must be given again to unlock the keystore |
|
94 * |
|
95 * @param aRequestStatus [out] A reference to the request status object. On |
|
96 * request completion, contains the return code of the request. |
|
97 * |
|
98 *-------------------------------------------------------------*/ |
|
99 EXPORT_C void RPKIServiceAPI::Logoff(TRequestStatus& aRequestStatus) |
|
100 { |
|
101 SendReceive(PkiService::ELogoff,TIpcArgs(NULL), aRequestStatus); |
|
102 } |
|
103 |
|
104 |
|
105 |
|
106 /**--------------------------------------------------------- |
|
107 * |
|
108 * ChangePassword(TRequestStatus& aRequestStatus) |
|
109 * |
|
110 * |
|
111 * |
|
112 *----------------------------------------------------------*/ |
|
113 EXPORT_C void RPKIServiceAPI::ChangePassword(TRequestStatus& aRequestStatus) |
|
114 { |
|
115 SendReceive(PkiService::EChangePassword,TIpcArgs(NULL), aRequestStatus); |
|
116 } |
|
117 |
|
118 /**--------------------------------------------------------- |
|
119 * |
|
120 * SignL(const TDesC8& aKeyId, const TDesC8& aHashIn, TDes8& aSignature, |
|
121 * TAny **aResourceObject, TRequestStatus& aRequestStatus) |
|
122 * |
|
123 *----------------------------------------------------------*/ |
|
124 EXPORT_C TInt RPKIServiceAPI::Sign(const TPKIKeyIdentifier& aKeyId, |
|
125 const TDesC8& aHashIn, |
|
126 TDes8& aSignature) const |
|
127 { |
|
128 return SendReceive(PkiService::ESignWithKeyId, TIpcArgs(&aKeyId, &aHashIn, &aSignature)); |
|
129 } |
|
130 |
|
131 /**--------------------------------------------------------- |
|
132 * |
|
133 * SignL(const TDesC8& aTrustedAuthority, const TPKICertificateOwnerType aOwnerType, const TPKIKeyUsage aKeyUsage, |
|
134 * const TUint aKeySize, const TPKIKeyAlgorithm aKeyAlgorithm, const TDesC8& aHashIn, TDes8& aSignature, |
|
135 * TAny **aResourceObject, TRequestStatus& aRequestStatus) |
|
136 * |
|
137 *----------------------------------------------------------*/ |
|
138 EXPORT_C TInt RPKIServiceAPI::Sign(const TDesC8& aTrustedAuthority, |
|
139 const TDesC8& aIdentitySubjectName, |
|
140 const TDesC8& aIdentityRfc822Name, |
|
141 const TPKIKeyUsage aKeyUsage, |
|
142 const TUint aKeySize, |
|
143 const TPKIKeyAlgorithm aKeyAlgorithm, |
|
144 const TDesC8& aHashIn, |
|
145 TDes8& aSignature) const |
|
146 { |
|
147 TInt err = KErrNone; |
|
148 |
|
149 TSecurityObjectDescriptor *privateKeyDesc = new TSecurityObjectDescriptor; |
|
150 if (privateKeyDesc != NULL) |
|
151 { |
|
152 privateKeyDesc->SetTrustedAuthority(aTrustedAuthority); |
|
153 privateKeyDesc->SetIdentitySubjectName(aIdentitySubjectName); |
|
154 privateKeyDesc->SetIdentityRfc822Name(aIdentityRfc822Name); |
|
155 privateKeyDesc->SetOwnerType(EPKIUserCertificate); // Always user cert |
|
156 privateKeyDesc->SetKeyUsage(aKeyUsage); |
|
157 privateKeyDesc->SetKeySize(aKeySize); |
|
158 privateKeyDesc->SetKeyAlgorithm(aKeyAlgorithm); |
|
159 |
|
160 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*privateKeyDesc); |
|
161 |
|
162 //Send request to the server |
|
163 err = SendReceive (PkiService::ESignWithCert, TIpcArgs(&pckgTSecurityObjectDescriptor, &aHashIn, &aSignature)); |
|
164 |
|
165 delete privateKeyDesc; |
|
166 privateKeyDesc = NULL; |
|
167 } |
|
168 else |
|
169 { |
|
170 err = KErrNoMemory; |
|
171 } |
|
172 return err; |
|
173 } |
|
174 |
|
175 |
|
176 /**--------------------------------------------------------- |
|
177 * |
|
178 * TInt DecryptL(const TDesC8& aKeyId, const TDesC8& aDataIn, TDes8& aDataOut, |
|
179 * TAny **aResourceObject, TRequestStatus& aRequestStatus) |
|
180 * |
|
181 *----------------------------------------------------------*/ |
|
182 EXPORT_C TInt RPKIServiceAPI::Decrypt(const TPKIKeyIdentifier& aKeyId, |
|
183 const TDesC8& aDataIn, |
|
184 TDes8& aDataOut) const |
|
185 { |
|
186 return SendReceive (PkiService::EDecrypt, TIpcArgs(&aKeyId, &aDataIn, &aDataOut)); |
|
187 } |
|
188 |
|
189 /**--------------------------------------------------------- |
|
190 * |
|
191 * StoreKeypairL(TDesC8& aKeyId, const TUint aKeySize, const TPKIKeyAlgorithm aKeyAlgorithm, |
|
192 * const TDesC8& aKeyDataIn, TBool aEncrypted, TRequestStatus& aRequestStatus) |
|
193 * |
|
194 *----------------------------------------------------------*/ |
|
195 EXPORT_C void RPKIServiceAPI::StoreKeypair(TPKIKeyIdentifier& aKeyId, |
|
196 const TDesC8& aKeyDataIn, |
|
197 TRequestStatus& aRequestStatus) |
|
198 { |
|
199 |
|
200 SendReceive (PkiService::EStoreKeypair, |
|
201 TIpcArgs(&aKeyId, &aKeyDataIn), |
|
202 aRequestStatus); |
|
203 } |
|
204 |
|
205 /**--------------------------------------------------------- |
|
206 * |
|
207 * GenerateKeypairL(TDesC8& aKeyId, const TUint aKeySize, const TPKIKeyAlgorithm aKeyAlgorithm, |
|
208 * TRequestStatus& requestStatus) |
|
209 * |
|
210 *----------------------------------------------------------*/ |
|
211 EXPORT_C void RPKIServiceAPI::GenerateKeypair(TPKIKeyIdentifier& aKeyId, |
|
212 const TUint aKeySize, |
|
213 const TPKIKeyAlgorithm aKeyAlgorithm, |
|
214 TRequestStatus& aRequestStatus) |
|
215 { |
|
216 |
|
217 __ASSERT_DEBUG(aKeyAlgorithm == EPKIRSA || aKeyAlgorithm == EPKIDSA, User::Invariant()); |
|
218 |
|
219 SendReceive (PkiService::EGenerateKeypair, |
|
220 TIpcArgs(&aKeyId, aKeySize, static_cast<TUint>(aKeyAlgorithm)), |
|
221 aRequestStatus); |
|
222 } |
|
223 |
|
224 |
|
225 /**--------------------------------------------------------- |
|
226 * |
|
227 * CancelPendingOperation() |
|
228 * |
|
229 * |
|
230 * Returns: |
|
231 * |
|
232 *----------------------------------------------------------*/ |
|
233 EXPORT_C TInt RPKIServiceAPI::CancelPendingOperation() |
|
234 { |
|
235 //Send request to the server |
|
236 return SendReceive (PkiService::ECancelPendingOperation, TIpcArgs(NULL)); |
|
237 } |
|
238 |
|
239 /**--------------------------------------------------------- |
|
240 * |
|
241 * GetRequiredBufferSize |
|
242 * |
|
243 * |
|
244 * Returns: |
|
245 * |
|
246 *----------------------------------------------------------*/ |
|
247 EXPORT_C TInt RPKIServiceAPI::GetRequiredBufferSize(TInt &aSize) |
|
248 { |
|
249 TInt size; |
|
250 TPckg<TInt> pckgSize(size); |
|
251 TInt ret = SendReceive (PkiService::EGetRequiredBufferSize, TIpcArgs(&pckgSize)); |
|
252 aSize = size; |
|
253 return ret; |
|
254 } |
|
255 |
|
256 |
|
257 /**--------------------------------------------------------- |
|
258 * |
|
259 * ReadPublicKeyL(const TDesC8& aKeyId, TDes8& aDataOut) |
|
260 * |
|
261 * |
|
262 *----------------------------------------------------------*/ |
|
263 EXPORT_C TInt RPKIServiceAPI::ReadPublicKey(const TPKIKeyIdentifier& aKeyId, |
|
264 TDes8& aDataOut) const |
|
265 { |
|
266 return SendReceive (PkiService::EReadPublicKey, |
|
267 TIpcArgs(&aKeyId, &aDataOut)); |
|
268 } |
|
269 |
|
270 |
|
271 /**--------------------------------------------------------- |
|
272 * |
|
273 * ReadCertificateL(const TDesC8& aTrustedAuthority, const TPKICertificateOwnerType aOwnerType, const TPKIKeyUsage aKeyUsage, |
|
274 * const TUint aKeySize, const TPKIKeyAlgorithm aKeyAlgorithm, HBufC8 *&aCert) |
|
275 * |
|
276 *----------------------------------------------------------*/ |
|
277 EXPORT_C void RPKIServiceAPI::ReadCertificateL(const TDesC8& aTrustedAuthority, |
|
278 const TDesC8& aIdentitySubjectName, |
|
279 const TDesC8& aIdentityRfc822Name, |
|
280 const TPKICertificateOwnerType aOwnerType, |
|
281 const TUint aKeySize, |
|
282 const TPKIKeyAlgorithm aKeyAlgorithm, |
|
283 TDes8 &aCert, |
|
284 TAny **aResourceObject, |
|
285 TRequestStatus& aRequestStatus) |
|
286 { |
|
287 TPckgBuf<TSecurityObjectDescriptor> *pckgTSecurityObjectDescriptor = new (ELeave) TPckgBuf<TSecurityObjectDescriptor>(); |
|
288 CleanupStack::PushL(pckgTSecurityObjectDescriptor); |
|
289 TSecurityObjectDescriptor& certDesc = (*pckgTSecurityObjectDescriptor)(); |
|
290 |
|
291 if (aTrustedAuthority.Length() > 0) |
|
292 { |
|
293 certDesc.SetTrustedAuthority(aTrustedAuthority); |
|
294 } |
|
295 |
|
296 if (aIdentitySubjectName.Length() > 0) |
|
297 { |
|
298 certDesc.SetIdentitySubjectName(aIdentitySubjectName); |
|
299 } |
|
300 |
|
301 if (aIdentityRfc822Name.Length() > 0) |
|
302 { |
|
303 certDesc.SetIdentityRfc822Name(aIdentityRfc822Name); |
|
304 } |
|
305 |
|
306 if (aKeySize != 0) |
|
307 { |
|
308 certDesc.SetKeySize(aKeySize); |
|
309 } |
|
310 |
|
311 if(aOwnerType != EPKICACertificate) |
|
312 { |
|
313 certDesc.SetKeyUsage(EX509DigitalSignature); |
|
314 certDesc.SetKeyAlgorithm(aKeyAlgorithm); |
|
315 } |
|
316 |
|
317 certDesc.SetOwnerType(aOwnerType); |
|
318 |
|
319 //Send request to the server |
|
320 SendReceive (PkiService::EReadCertificate, TIpcArgs(pckgTSecurityObjectDescriptor, &aCert), aRequestStatus); |
|
321 CleanupStack::Pop(); |
|
322 |
|
323 *aResourceObject = pckgTSecurityObjectDescriptor; |
|
324 } |
|
325 |
|
326 /**--------------------------------------------------------- |
|
327 * |
|
328 * ReadCertificateL |
|
329 * |
|
330 *----------------------------------------------------------*/ |
|
331 EXPORT_C TInt RPKIServiceAPI::ReadCertificate(const TDesC8& aTrustedAuthority, |
|
332 const TDesC8& aSerialNumber, |
|
333 TDes8 &aCert) |
|
334 { |
|
335 TInt err = KErrNone; |
|
336 |
|
337 TSecurityObjectDescriptor *certDesc = new TSecurityObjectDescriptor; |
|
338 if (certDesc != NULL) |
|
339 { |
|
340 certDesc->SetTrustedAuthority(aTrustedAuthority); |
|
341 certDesc->SetSerialNumber(aSerialNumber); |
|
342 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
343 |
|
344 //Send request to the server |
|
345 err = SendReceive (PkiService::EReadCertificate, TIpcArgs(&pckgTSecurityObjectDescriptor, |
|
346 &aCert)); |
|
347 |
|
348 delete certDesc; |
|
349 } |
|
350 else |
|
351 { |
|
352 err = KErrNoMemory; |
|
353 } |
|
354 return err; |
|
355 } |
|
356 |
|
357 |
|
358 /**-------------------------------------------------------------------------- |
|
359 * Read a certificate having listed characteristics |
|
360 * @param aKeyId SubjectKeyID. |
|
361 * @param aCert [out] Returned ASN1 encoded certificate. |
|
362 * @param aResourceObject [out] This returned object must be given as a parameter in the Finalize call when this function has completed. |
|
363 * @param aRequestStatus [out] A reference to the request status object. On |
|
364 * request completion, contains the return code of the request. |
|
365 *---------------------------------------------------------------------------*/ |
|
366 EXPORT_C void RPKIServiceAPI::ReadCertificateL(const TPKIKeyIdentifier& aKeyId, |
|
367 TDes8 &aCert, |
|
368 TAny **aResourceObject, |
|
369 TRequestStatus& aRequestStatus) |
|
370 { |
|
371 TPckgBuf<TSecurityObjectDescriptor> *pckgTSecurityObjectDescriptor = new (ELeave) TPckgBuf<TSecurityObjectDescriptor>(); |
|
372 CleanupStack::PushL(pckgTSecurityObjectDescriptor); |
|
373 TSecurityObjectDescriptor& certDesc = (*pckgTSecurityObjectDescriptor)(); |
|
374 |
|
375 certDesc.SetSubjectKeyId(aKeyId); |
|
376 |
|
377 //Send request to the server |
|
378 SendReceive (PkiService::EReadCertificate, TIpcArgs(pckgTSecurityObjectDescriptor, &aCert), aRequestStatus); |
|
379 CleanupStack::Pop(); |
|
380 |
|
381 *aResourceObject = pckgTSecurityObjectDescriptor; |
|
382 } |
|
383 |
|
384 |
|
385 /**--------------------------------------------------------- |
|
386 * |
|
387 * ListCertificatesL |
|
388 * |
|
389 *----------------------------------------------------------*/ |
|
390 EXPORT_C void RPKIServiceAPI::ListCertificatesL(CArrayFix<TCertificateListEntry> *&aCertList) |
|
391 { |
|
392 TInt certCount = SendReceive(PkiService::ECertCount, TIpcArgs(NULL)); |
|
393 |
|
394 TInt certListGranularity = certCount; |
|
395 if (certListGranularity == 0) |
|
396 { |
|
397 certListGranularity = 1; |
|
398 } |
|
399 |
|
400 CArrayFix<TCertificateListEntry>* certList; |
|
401 certList = new (ELeave) CArrayFixFlat<TCertificateListEntry>(certListGranularity); |
|
402 if (certCount == 0) |
|
403 { |
|
404 aCertList = certList; |
|
405 return; |
|
406 } |
|
407 |
|
408 CleanupStack::PushL(certList); |
|
409 |
|
410 CBufFlat* list = CBufFlat::NewL(sizeof(TCertificateListEntry)); |
|
411 CleanupStack::PushL(list); |
|
412 list->ResizeL(certCount * sizeof(TCertificateListEntry)); |
|
413 |
|
414 TPtr8 ptrList = list->Ptr(0); |
|
415 |
|
416 User::LeaveIfError(SendReceive (PkiService::EGetCertList, TIpcArgs(&ptrList))); |
|
417 |
|
418 TCertificateListEntry certInfo; |
|
419 for (TInt i = 0; i < certCount; i++) |
|
420 { |
|
421 list->Read(i * sizeof(TCertificateListEntry), (TAny*)&certInfo, sizeof(TCertificateListEntry)); |
|
422 certList->AppendL(certInfo); |
|
423 } |
|
424 |
|
425 CleanupStack::PopAndDestroy(1); // list |
|
426 CleanupStack::Pop(); // certList |
|
427 |
|
428 aCertList = certList; |
|
429 } |
|
430 |
|
431 /**--------------------------------------------------------- |
|
432 * List CA certificates applicable for all requested applications |
|
433 * @param aApplications List of applications |
|
434 * @param aCertList [out] Returned list of certificates. |
|
435 * @param aRequestStatus [out] A reference to the request status object. On |
|
436 * request completion, contains the return code of the request. |
|
437 *---------------------------------------------------------*/ |
|
438 EXPORT_C void RPKIServiceAPI::ListApplicableCertificatesL(const RArray<TUid>& aApplications, |
|
439 CArrayFix<TCertificateListEntry>*& aCertList) |
|
440 { |
|
441 |
|
442 TPckgC<TInt> applCount(aApplications.Count()); |
|
443 // Allocate a buffer for the application uid list |
|
444 CBufFlat* applList = CBufFlat::NewL(sizeof(TUid)); |
|
445 CleanupStack::PushL(applList); |
|
446 applList->ResizeL(aApplications.Count() * sizeof(TUid)); |
|
447 |
|
448 TInt i = 0; |
|
449 for(i=0;i<aApplications.Count();i++) |
|
450 { |
|
451 applList->Write(i * sizeof(TUid), (TAny*)&(aApplications[i]), sizeof(TUid)); |
|
452 } |
|
453 |
|
454 // Application Uid list |
|
455 TPtr8 ptrList = applList->Ptr(0); |
|
456 |
|
457 TInt certCount = SendReceive(PkiService::EApplicableCertCount, TIpcArgs(&applCount, &ptrList)); |
|
458 |
|
459 CleanupStack::PopAndDestroy(1); // applList |
|
460 TInt certListGranularity = certCount; |
|
461 if (certListGranularity == 0) |
|
462 { |
|
463 certListGranularity = 1; |
|
464 } |
|
465 |
|
466 CArrayFix<TCertificateListEntry>* certList; |
|
467 certList = new (ELeave) CArrayFixFlat<TCertificateListEntry>(certListGranularity); |
|
468 if (certCount == 0) |
|
469 { |
|
470 aCertList = certList; |
|
471 return; |
|
472 } |
|
473 |
|
474 CleanupStack::PushL(certList); |
|
475 |
|
476 CBufFlat* list = CBufFlat::NewL(sizeof(TCertificateListEntry)); |
|
477 CleanupStack::PushL(list); |
|
478 list->ResizeL(certCount * sizeof(TCertificateListEntry)); |
|
479 |
|
480 TPtr8 ptrList2 = list->Ptr(0); |
|
481 |
|
482 User::LeaveIfError(SendReceive (PkiService::EGetApplicableCertList, TIpcArgs(&ptrList2))); |
|
483 |
|
484 TCertificateListEntry certInfo; |
|
485 for (i = 0; i < certCount; i++) |
|
486 { |
|
487 list->Read(i * sizeof(TCertificateListEntry), (TAny*)&certInfo, sizeof(TCertificateListEntry)); |
|
488 certList->AppendL(certInfo); |
|
489 } |
|
490 |
|
491 CleanupStack::PopAndDestroy(1); // list |
|
492 CleanupStack::Pop(); // certList |
|
493 |
|
494 aCertList = certList; |
|
495 } |
|
496 |
|
497 |
|
498 |
|
499 /**--------------------------------------------------------- |
|
500 * |
|
501 * ListKeysL |
|
502 * |
|
503 *----------------------------------------------------------*/ |
|
504 EXPORT_C void RPKIServiceAPI::ListKeysL(CArrayFix<TKeyListEntry> *&aKeyList) |
|
505 { |
|
506 TInt keyCount = SendReceive(PkiService::EKeyCount, TIpcArgs(NULL)); |
|
507 User::LeaveIfError(keyCount); |
|
508 |
|
509 TInt keyListGranularity = keyCount; |
|
510 if (keyListGranularity == 0) |
|
511 { |
|
512 keyListGranularity = 1; |
|
513 } |
|
514 |
|
515 CArrayFix<TKeyListEntry>* keyList; |
|
516 keyList = new (ELeave) CArrayFixFlat<TKeyListEntry>(keyListGranularity); |
|
517 if (keyCount == 0) |
|
518 { |
|
519 aKeyList = keyList; |
|
520 return; |
|
521 } |
|
522 |
|
523 CleanupStack::PushL(keyList); |
|
524 |
|
525 CBufFlat* list = CBufFlat::NewL(sizeof(TKeyListEntry)); |
|
526 CleanupStack::PushL(list); |
|
527 list->ResizeL(keyCount * sizeof(TKeyListEntry)); |
|
528 |
|
529 TPtr8 ptrList = list->Ptr(0); |
|
530 |
|
531 User::LeaveIfError(SendReceive (PkiService::EGetKeyList, TIpcArgs(&ptrList))); |
|
532 |
|
533 TKeyListEntry keyInfo; |
|
534 for (TInt i = 0; i < keyCount; i++) |
|
535 { |
|
536 list->Read(i * sizeof(TKeyListEntry), (TAny*)&keyInfo, sizeof(TKeyListEntry)); |
|
537 keyList->AppendL(keyInfo); |
|
538 } |
|
539 |
|
540 CleanupStack::PopAndDestroy(1); // list |
|
541 CleanupStack::Pop(); // keyList |
|
542 |
|
543 aKeyList = keyList; |
|
544 } |
|
545 |
|
546 |
|
547 /**--------------------------------------------------------- |
|
548 * |
|
549 * StoreCertificateL(const TPKICertificateOwnerType aOwnerType, |
|
550 * const TUint aKeySize, const TPKIKeyAlgorithm aKeyAlgorithm, const TDesC8& aDataIn) |
|
551 * |
|
552 * |
|
553 *----------------------------------------------------------*/ |
|
554 EXPORT_C void RPKIServiceAPI::StoreCertificateL(const TPKICertificateOwnerType aOwnerType, |
|
555 const TUint aKeySize, |
|
556 const TPKIKeyAlgorithm aKeyAlgorithm, |
|
557 const TDesC8& aDataIn, |
|
558 TAny **aResourceObject, |
|
559 TRequestStatus& aRequestStatus) |
|
560 { |
|
561 __ASSERT_DEBUG(aDataIn.Length() > 0, User::Invariant()); |
|
562 |
|
563 TPckgBuf<TSecurityObjectDescriptor> *pckgTSecurityObjectDescriptor = new (ELeave) TPckgBuf<TSecurityObjectDescriptor>(); |
|
564 CleanupStack::PushL(pckgTSecurityObjectDescriptor); |
|
565 TSecurityObjectDescriptor& certDesc = (*pckgTSecurityObjectDescriptor)(); |
|
566 |
|
567 certDesc.SetOwnerType(aOwnerType); |
|
568 certDesc.SetKeySize(aKeySize); |
|
569 certDesc.SetKeyAlgorithm(aKeyAlgorithm); |
|
570 certDesc.SetIsDeletable(ETrue); |
|
571 |
|
572 //Send request to the server |
|
573 SendReceive (PkiService::EStoreCertificate, TIpcArgs(pckgTSecurityObjectDescriptor, &aDataIn), aRequestStatus); |
|
574 CleanupStack::Pop(); |
|
575 |
|
576 *aResourceObject = pckgTSecurityObjectDescriptor; |
|
577 } |
|
578 |
|
579 |
|
580 /**------------------------------------------------------------------------ |
|
581 * Store a certificate having listed characteristics |
|
582 * For CA certificates, only aOwnerType and aDataIn parameters are meaningful. |
|
583 * |
|
584 * @param aOwnerType Type of the certificate. |
|
585 * @param aLabel Label of the key |
|
586 * @param aCertFormat certificate format |
|
587 * @param aIsDeletable true if certificate is deletable |
|
588 * @param aKeySize Size of the key in bits. |
|
589 * @param aKeyAlgorithm Algorithm of the key. |
|
590 * @param aDataIn A descriptor of the buffer conatining ASN1 coded certificate bytes. |
|
591 * @param aResourceObject [out] This returned object must be given as a parameter in the Finalize call when this function has completed. |
|
592 * @param aRequestStatus [out] A reference to the request status object. On |
|
593 * request completion, contains the return code of the request. |
|
594 *----------------------------------------------------------------------------*/ |
|
595 EXPORT_C TInt RPKIServiceAPI::StoreCertificate(const TPKICertificateOwnerType aOwnerType, |
|
596 const TBool& aIsDeletable, |
|
597 const TUint aKeySize, |
|
598 const TPKIKeyAlgorithm aKeyAlgorithm, |
|
599 const TDesC8& aDataIn) const |
|
600 { |
|
601 __ASSERT_DEBUG(aDataIn.Length() > 0, User::Invariant()); |
|
602 |
|
603 TInt err = KErrNone; |
|
604 TSecurityObjectDescriptor *certDesc = new TSecurityObjectDescriptor; |
|
605 if (certDesc != NULL) |
|
606 { |
|
607 certDesc->SetOwnerType(aOwnerType); |
|
608 certDesc->SetKeySize(aKeySize); |
|
609 certDesc->SetKeyAlgorithm(aKeyAlgorithm); |
|
610 certDesc->SetIsDeletable(aIsDeletable); |
|
611 |
|
612 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
613 |
|
614 //Send request to the server |
|
615 err = SendReceive (PkiService::EStoreCertificate, |
|
616 TIpcArgs(&pckgTSecurityObjectDescriptor, &aDataIn)); |
|
617 |
|
618 delete certDesc; |
|
619 certDesc = NULL; |
|
620 } |
|
621 else |
|
622 { |
|
623 err = KErrNoMemory; |
|
624 } |
|
625 |
|
626 return err; |
|
627 } |
|
628 |
|
629 |
|
630 |
|
631 /**--------------------------------------------------------- |
|
632 * |
|
633 * AttachCertificateL(const TDesC8& aKeyId, |
|
634 * const TUint aKeySize, const TPKIKeyAlgorithm aKeyAlgorithm, const TDesC8& aDataIn) |
|
635 * |
|
636 *----------------------------------------------------------*/ |
|
637 EXPORT_C void RPKIServiceAPI::AttachCertificateL(const TPKIKeyIdentifier& aKeyId, |
|
638 const TUint aKeySize, |
|
639 const TPKIKeyAlgorithm aKeyAlgorithm, |
|
640 const TDesC8& aDataIn, |
|
641 TAny **aResourceObject, |
|
642 TRequestStatus& aRequestStatus) |
|
643 { |
|
644 |
|
645 __ASSERT_DEBUG(aDataIn.Length() > 0, User::Invariant()); |
|
646 |
|
647 TPckgBuf<TSecurityObjectDescriptor> *pckgTSecurityObjectDescriptor = new (ELeave) TPckgBuf<TSecurityObjectDescriptor>(); |
|
648 CleanupStack::PushL(pckgTSecurityObjectDescriptor); |
|
649 TSecurityObjectDescriptor& certDesc = (*pckgTSecurityObjectDescriptor)(); |
|
650 |
|
651 certDesc.SetSubjectKeyId(aKeyId); |
|
652 certDesc.SetOwnerType(EPKIUserCertificate); |
|
653 certDesc.SetKeySize(aKeySize); |
|
654 certDesc.SetKeyAlgorithm(aKeyAlgorithm); |
|
655 |
|
656 //Send request to the server |
|
657 SendReceive (PkiService::EAttachCertificate, TIpcArgs(pckgTSecurityObjectDescriptor, &aDataIn), aRequestStatus); |
|
658 CleanupStack::Pop(); |
|
659 |
|
660 *aResourceObject = pckgTSecurityObjectDescriptor; |
|
661 } |
|
662 |
|
663 /**-------------------------------------------------------------------------------- |
|
664 * Attach a user certificate having listed characteristics to a |
|
665 * generated key identified by keyId |
|
666 * |
|
667 * @param aKeyId Idenfies the key to attach the certificate |
|
668 * @param aIsDeletable true if certificate is deletable |
|
669 * @param aKeySize Size of the key in bits. |
|
670 * @param aKeyAlgorithm Algorithm of the key. |
|
671 * @param aDataIn A descriptor of the buffer containing ASN1 |
|
672 * coded certificate bytes. |
|
673 * @return the return code of the request. |
|
674 *---------------------------------------------------------------------------------*/ |
|
675 EXPORT_C TInt RPKIServiceAPI::AttachCertificate(const TPKIKeyIdentifier& aKeyId, |
|
676 const TBool& aIsDeletable, |
|
677 const TUint aKeySize, |
|
678 const TPKIKeyAlgorithm aKeyAlgorithm, |
|
679 const TDesC8& aDataIn) const |
|
680 { |
|
681 |
|
682 __ASSERT_DEBUG(aDataIn.Length() > 0, User::Invariant()); |
|
683 |
|
684 TInt err(KErrNone); |
|
685 TSecurityObjectDescriptor* certDesc = new TSecurityObjectDescriptor; |
|
686 if (certDesc != NULL) |
|
687 { |
|
688 certDesc->SetSubjectKeyId(aKeyId); |
|
689 certDesc->SetOwnerType(EPKIUserCertificate); |
|
690 certDesc->SetKeySize(aKeySize); |
|
691 certDesc->SetKeyAlgorithm(aKeyAlgorithm); |
|
692 certDesc->SetIsDeletable(aIsDeletable); |
|
693 |
|
694 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
695 |
|
696 //Send request to the server |
|
697 err = SendReceive (PkiService::EAttachCertificate, TIpcArgs(&pckgTSecurityObjectDescriptor, &aDataIn)); |
|
698 |
|
699 delete certDesc; |
|
700 certDesc = NULL; |
|
701 } |
|
702 else |
|
703 { |
|
704 err = KErrNoMemory; |
|
705 } |
|
706 |
|
707 return err; |
|
708 } |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 /**--------------------------------------------------------- |
|
714 * |
|
715 * RemoveKeypairL(const TDesC8& aKeyId) |
|
716 * |
|
717 * |
|
718 *----------------------------------------------------------*/ |
|
719 EXPORT_C TInt RPKIServiceAPI::RemoveKeypair(const TPKIKeyIdentifier& aKeyId) const |
|
720 { |
|
721 return SendReceive(PkiService::ERemoveKeypair, TIpcArgs(&aKeyId)); |
|
722 } |
|
723 |
|
724 |
|
725 /**--------------------------------------------------------- |
|
726 * |
|
727 * RemoveCertificateL(const TDesC8& aTrustedAuthority, const TPKICertificateOwnerType aOwnerType, const TPKIKeyUsage aKeyUsage, |
|
728 * const TUint aKeySize, const TPKIKeyAlgorithm aKeyAlgorithm) |
|
729 * |
|
730 *----------------------------------------------------------*/ |
|
731 EXPORT_C TInt RPKIServiceAPI::RemoveCertificate(const TDesC8& aTrustedAuthority, |
|
732 const TDesC8& aSerialNumber) const |
|
733 { |
|
734 TInt err = KErrNone; |
|
735 |
|
736 TSecurityObjectDescriptor *certDesc = new TSecurityObjectDescriptor; |
|
737 if (certDesc != NULL) |
|
738 { |
|
739 certDesc->SetTrustedAuthority(aTrustedAuthority); |
|
740 certDesc->SetSerialNumber(aSerialNumber); |
|
741 |
|
742 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
743 |
|
744 //Send request to the server |
|
745 err = SendReceive (PkiService::ERemoveCertificate, TIpcArgs(&pckgTSecurityObjectDescriptor)); |
|
746 |
|
747 delete certDesc; |
|
748 certDesc = NULL; |
|
749 } |
|
750 else |
|
751 { |
|
752 err = KErrNoMemory; |
|
753 } |
|
754 return err; |
|
755 } |
|
756 |
|
757 /**--------------------------------------------------------- |
|
758 * |
|
759 * Pkcs10SignCallbackL |
|
760 * |
|
761 *----------------------------------------------------------*/ |
|
762 TBool RPKIServiceAPI::Pkcs10SignCallbackL(const TDesC8& aDigest, TDes8& aSignature, |
|
763 const TPKIKeyIdentifier& aKeyId, |
|
764 TAny* aContext) |
|
765 { |
|
766 RPKIServiceAPI *pkiServiceApi = STATIC_CAST(RPKIServiceAPI*, aContext); |
|
767 User::LeaveIfError(pkiServiceApi->Sign(aKeyId, aDigest, aSignature)); |
|
768 return ETrue; |
|
769 } |
|
770 |
|
771 |
|
772 /**--------------------------------------------------------- |
|
773 * |
|
774 * CreateAndSaveCertificateRequestL |
|
775 * |
|
776 *----------------------------------------------------------*/ |
|
777 EXPORT_C void RPKIServiceAPI::CreateAndSaveCertificateRequestL(const TPKIKeyIdentifier& aKeyId, |
|
778 const TDesC8& aSubjectName, |
|
779 const TDesC8& aSubjectAltNameRfc822, |
|
780 const TDesC8& aChallengePw, |
|
781 const TDesC8& aDNSName, |
|
782 TDes& aCertRequestRef, |
|
783 TInt& aRequestLength) |
|
784 { |
|
785 TBuf8<2> testPublicKey; |
|
786 HBufC8 *publicKeyBuffer = NULL; |
|
787 |
|
788 TInt bSize = 0; |
|
789 |
|
790 // Get public key |
|
791 TInt err = ReadPublicKey(aKeyId, testPublicKey); |
|
792 if(err == KPKIErrBufferTooShort) |
|
793 { |
|
794 GetRequiredBufferSize(bSize); |
|
795 } |
|
796 else if(err == KErrNone) |
|
797 { |
|
798 return; |
|
799 } |
|
800 else |
|
801 { |
|
802 User::Leave(err); |
|
803 } |
|
804 |
|
805 publicKeyBuffer = HBufC8::NewLC(bSize); |
|
806 TPtr8 publicKeyBufferDes = publicKeyBuffer->Des(); |
|
807 err = ReadPublicKey(aKeyId, publicKeyBufferDes); |
|
808 User::LeaveIfError(err); |
|
809 |
|
810 CPkcs10Req *pkcs10Instance = new (ELeave) CPkcs10Req; |
|
811 CleanupStack::PushL(pkcs10Instance); |
|
812 |
|
813 if (pkcs10Instance->SetDistinguishedNameExtendedL(aSubjectName) != KErrNone) |
|
814 { |
|
815 User::Leave(KPKIErrCertRequestParam); |
|
816 } |
|
817 if (pkcs10Instance->SetSubjectAltNameRfc822(aSubjectAltNameRfc822) != KErrNone) |
|
818 { |
|
819 User::Leave(KPKIErrCertRequestParam); |
|
820 } |
|
821 if (pkcs10Instance->SetChallengePw(aChallengePw) != KErrNone) |
|
822 { |
|
823 User::Leave(KPKIErrCertRequestParam); |
|
824 } |
|
825 if (pkcs10Instance->SetDNSName(aDNSName) != KErrNone) |
|
826 { |
|
827 User::Leave(KPKIErrCertRequestParam); |
|
828 } |
|
829 if (pkcs10Instance->SetPublicKey(publicKeyBufferDes) != KErrNone) |
|
830 { |
|
831 User::Leave(KPKIErrCertRequestParam); |
|
832 } |
|
833 |
|
834 TSignCallback signCallBackL = Pkcs10SignCallbackL; |
|
835 HBufC8* certRequest = pkcs10Instance->CreateCertificateRequestLC( |
|
836 HASH_TYPE_MD5, aKeyId, ETrue, EFalse, signCallBackL, this); |
|
837 if (!certRequest) |
|
838 { |
|
839 CleanupStack::PopAndDestroy(2); // publicKeyBuffer, pkcs10Instance |
|
840 User::Leave(KPKIErrCertRequest); |
|
841 } |
|
842 //Send request to the server |
|
843 |
|
844 TRequestStatus requestStatus; |
|
845 SendReceive (PkiService::ESaveCertificateRequest, TIpcArgs(certRequest, &aCertRequestRef, &aKeyId), requestStatus); |
|
846 User::WaitForRequest(requestStatus); |
|
847 aRequestLength = certRequest->Length(); |
|
848 CleanupStack::PopAndDestroy(3); // certRequesr, publicKeyBuffer, pkcs10Instance |
|
849 User::LeaveIfError(requestStatus.Int()); |
|
850 } |
|
851 |
|
852 |
|
853 /**--------------------------------------------------------- |
|
854 * |
|
855 * ReadCertificateRequest |
|
856 * |
|
857 *----------------------------------------------------------*/ |
|
858 EXPORT_C TInt RPKIServiceAPI::ReadCertificateRequest(const TDesC& aCertRequestRef, |
|
859 TDes8& aCertRequest) const |
|
860 { |
|
861 //Send request to the server |
|
862 return SendReceive (PkiService::EReadCertificateRequest, TIpcArgs(&aCertRequestRef, &aCertRequest)); |
|
863 } |
|
864 |
|
865 /**--------------------------------------------------------- |
|
866 * |
|
867 * DeleteCertificateRequest |
|
868 * |
|
869 *----------------------------------------------------------*/ |
|
870 EXPORT_C TInt RPKIServiceAPI::DeleteCertificateRequest(const TDesC& aCertRequestRef) const |
|
871 { |
|
872 //Send request to the server |
|
873 return SendReceive (PkiService::EDeleteCertificateRequest, TIpcArgs(&aCertRequestRef)); |
|
874 } |
|
875 |
|
876 /**--------------------------------------------------------- |
|
877 * |
|
878 * Finalize |
|
879 * |
|
880 *----------------------------------------------------------*/ |
|
881 EXPORT_C void RPKIServiceAPI::Finalize(TAny *aResourceObject) |
|
882 { |
|
883 if(aResourceObject != NULL) |
|
884 { |
|
885 delete static_cast<TPckgBuf<TSecurityObjectDescriptor>*>(aResourceObject); |
|
886 } |
|
887 } |
|
888 |
|
889 |
|
890 /**----------------------------------------------------------------------- |
|
891 * Change trust setting of a certificate in Symbian certificate store |
|
892 * |
|
893 * @param aTrustedAuthority Text or ASN1 format subtree name of the CA |
|
894 * @param aSerialNumber serial number of the certificate |
|
895 * @param aTrusted ETrue, if trusted; EFalse, otherwise |
|
896 * @param aResourceObject [out] This returned object must be given as a parameter in the Finalize call when this function has completed. |
|
897 * @param aRequestStatus [out] A reference to the request status object. On |
|
898 * request completion, contains the return code of the request. |
|
899 *------------------------------------------------------------------------*/ |
|
900 EXPORT_C TInt RPKIServiceAPI::SetTrust(const TDesC8& aTrustedAuthority, |
|
901 const TDesC8& aSerialNumber, |
|
902 const TBool& aTrusted) const |
|
903 { |
|
904 TInt err = KErrNone; |
|
905 |
|
906 TSecurityObjectDescriptor *certDesc = new TSecurityObjectDescriptor; |
|
907 if (certDesc != NULL) |
|
908 { |
|
909 certDesc->SetTrustedAuthority(aTrustedAuthority); |
|
910 certDesc->SetSerialNumber(aSerialNumber); |
|
911 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
912 |
|
913 TPckgC<TBool> trust(aTrusted); |
|
914 //Send request to the server |
|
915 err = SendReceive (PkiService::ESetTrust, TIpcArgs(&pckgTSecurityObjectDescriptor, &trust)); |
|
916 |
|
917 delete certDesc; |
|
918 certDesc = NULL; |
|
919 } |
|
920 else |
|
921 { |
|
922 err = KErrNoMemory; |
|
923 } |
|
924 return err; |
|
925 } |
|
926 |
|
927 |
|
928 /**--------------------------------------------------------------------------- |
|
929 * Read trust setting of a certificate in Symbian certificate store |
|
930 * |
|
931 * @param aTrustedAuthority Text or ASN1 format subtree name of the CA |
|
932 * @param aSerialNumber serial number of the certificate |
|
933 * @param aTrusted returns ETrue, if trusted; EFalse, otherwise |
|
934 * @param aResourceObject [out] This returned object must be given as a parameter in the Finalize call when this function has completed. |
|
935 *---------------------------------------------------------------------------*/ |
|
936 EXPORT_C TInt RPKIServiceAPI::Trusted(const TDesC8& aTrustedAuthority, |
|
937 const TDesC8& aSerialNumber, |
|
938 TBool& aTrusted) const |
|
939 { |
|
940 TInt err = KErrNone; |
|
941 TSecurityObjectDescriptor *certDesc = new TSecurityObjectDescriptor; |
|
942 if (certDesc != NULL) |
|
943 { |
|
944 certDesc->SetTrustedAuthority(aTrustedAuthority); |
|
945 certDesc->SetSerialNumber(aSerialNumber); |
|
946 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
947 TPckg<TBool> trust(aTrusted); |
|
948 |
|
949 //Send request to the server |
|
950 err = SendReceive (PkiService::ETrusted, TIpcArgs(&pckgTSecurityObjectDescriptor, &trust)); |
|
951 |
|
952 delete certDesc; |
|
953 certDesc = NULL; |
|
954 } |
|
955 else |
|
956 { |
|
957 err = KErrNoMemory; |
|
958 } |
|
959 return err; |
|
960 } |
|
961 |
|
962 |
|
963 /**--------------------------------------------------------------------------- |
|
964 * Set applications of a certificate in Symbian certificate store |
|
965 * |
|
966 * @param aTrustedAuthority Text or ASN1 format subtree name of the CA |
|
967 * @param aSerialNumber serial number of the certificate |
|
968 * @param aApplications list of applications (uids) for whom the certificate is applicable |
|
969 * @param aResourceObject [out] This returned object must be given as a parameter in the Finalize call when this function has completed. |
|
970 *---------------------------------------------------------------------------*/ |
|
971 EXPORT_C void RPKIServiceAPI::SetApplicabilityL(const TDesC8& aTrustedAuthority, |
|
972 const TDesC8& aSerialNumber, |
|
973 const RArray<TUid>& aApplications) const |
|
974 { |
|
975 TSecurityObjectDescriptor *certDesc = new (ELeave) TSecurityObjectDescriptor; |
|
976 CleanupStack::PushL(certDesc); |
|
977 certDesc->SetTrustedAuthority(aTrustedAuthority); |
|
978 certDesc->SetSerialNumber(aSerialNumber); |
|
979 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
980 |
|
981 |
|
982 TPckgC<TInt> applCount(aApplications.Count()); |
|
983 // Allocate a buffer for the application uid list |
|
984 CBufFlat* applList = CBufFlat::NewL(sizeof(TUid)); |
|
985 CleanupStack::PushL(applList); |
|
986 applList->ResizeL(aApplications.Count() * sizeof(TUid)); |
|
987 |
|
988 TInt i = 0; |
|
989 for(i=0;i<aApplications.Count();i++) |
|
990 { |
|
991 applList->Write(i * sizeof(TUid), (TAny*)&(aApplications[i]), sizeof(TUid)); |
|
992 } |
|
993 |
|
994 // Application Uid list |
|
995 TPtr8 ptrList = applList->Ptr(0); |
|
996 |
|
997 //Send request to the server |
|
998 User::LeaveIfError(SendReceive (PkiService::ESetApplicability, TIpcArgs(&pckgTSecurityObjectDescriptor, &applCount, &ptrList))); |
|
999 CleanupStack::PopAndDestroy(applList); |
|
1000 CleanupStack::PopAndDestroy(); //certDesc |
|
1001 } |
|
1002 |
|
1003 |
|
1004 /**--------------------------------------------------------------------------- |
|
1005 * Get applications of a certificate in Symbian certificate store |
|
1006 * |
|
1007 * @param aTrustedAuthority Text or ASN1 format subtree name of the CA |
|
1008 * @param aSerialNumber serial number of the certificate |
|
1009 * @param aApplications list of applications (uids) for whom the certificate is applicable |
|
1010 * @param aResourceObject [out] This returned object must be given as a parameter in the Finalize call when this function has completed. |
|
1011 *---------------------------------------------------------------------------*/ |
|
1012 EXPORT_C void RPKIServiceAPI::ApplicationsL(const TDesC8& aTrustedAuthority, |
|
1013 const TDesC8& aSerialNumber, |
|
1014 RArray<TUid>& aApplications) const |
|
1015 { |
|
1016 TSecurityObjectDescriptor *certDesc = new (ELeave) TSecurityObjectDescriptor; |
|
1017 CleanupStack::PushL(certDesc); |
|
1018 certDesc->SetTrustedAuthority(aTrustedAuthority); |
|
1019 certDesc->SetSerialNumber(aSerialNumber); |
|
1020 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
1021 |
|
1022 TInt count = 0; |
|
1023 TPckg<TInt> pckgCount(count); |
|
1024 // Allocate a buffer for the application uid list |
|
1025 CBufFlat* applList = CBufFlat::NewL(sizeof(TUid)); |
|
1026 CleanupStack::PushL(applList); |
|
1027 // Reserve space for applications |
|
1028 CCertificateAppInfoManager* appsMan = CCertificateAppInfoManager::NewLC(); |
|
1029 const RArray<TCertificateAppInfo>& apps = appsMan->Applications(); |
|
1030 applList->ResizeL(apps.Count() * sizeof(TUid)); |
|
1031 count = apps.Count(); |
|
1032 CleanupStack::PopAndDestroy(1); // appsMan |
|
1033 |
|
1034 // Application Uid list |
|
1035 TPtr8 ptrList = applList->Ptr(0); |
|
1036 |
|
1037 //Send request to the server |
|
1038 User::LeaveIfError(SendReceive (PkiService::EApplications, TIpcArgs(&pckgTSecurityObjectDescriptor, &pckgCount, &ptrList))); |
|
1039 |
|
1040 TUid temp; |
|
1041 for (TInt i = 0; i < count; i++) |
|
1042 { |
|
1043 applList->Read(i * sizeof(TUid), (TAny*)&temp, sizeof(TUid)); |
|
1044 aApplications.Append(temp); |
|
1045 } |
|
1046 CleanupStack::PopAndDestroy(1); // applList |
|
1047 CleanupStack::PopAndDestroy(); //certDesc |
|
1048 } |
|
1049 |
|
1050 |
|
1051 /**--------------------------------------------------------------------------- |
|
1052 * Get certificate details of a certificate in Symbian certificate store |
|
1053 * |
|
1054 * @param aTrustedAuthority Text or ASN1 format subtree name of the CA |
|
1055 * @param aSerialNumber serial number of the certificate |
|
1056 * @param aCertDetails details of a certificate |
|
1057 * @param aResourceObject [out] This returned object must be given as a parameter in the Finalize call when this function has completed. |
|
1058 *---------------------------------------------------------------------------*/ |
|
1059 EXPORT_C TInt RPKIServiceAPI::CertificateDetails(const TDesC8& aTrustedAuthority, |
|
1060 const TDesC8& aSerialNumber, |
|
1061 TCertificateListEntry &aCertDetails) const |
|
1062 { |
|
1063 TInt err = KErrNone; |
|
1064 TSecurityObjectDescriptor *certDesc = new TSecurityObjectDescriptor; |
|
1065 if (certDesc != NULL) |
|
1066 { |
|
1067 certDesc->SetTrustedAuthority(aTrustedAuthority); |
|
1068 certDesc->SetSerialNumber(aSerialNumber); |
|
1069 TPckg<TSecurityObjectDescriptor> pckgTSecurityObjectDescriptor(*certDesc); |
|
1070 |
|
1071 |
|
1072 TPckg<TCertificateListEntry> certDetails(aCertDetails); |
|
1073 |
|
1074 //Send request to the server |
|
1075 err = SendReceive (PkiService::EGetCertDetails, TIpcArgs(&certDetails, &pckgTSecurityObjectDescriptor)); |
|
1076 delete certDesc; |
|
1077 certDesc = NULL; |
|
1078 } |
|
1079 else |
|
1080 { |
|
1081 err = KErrNoMemory; |
|
1082 } |
|
1083 return err; |
|
1084 } |
|
1085 |
|
1086 |
|
1087 /**------------------------------------------------------------------------- |
|
1088 * Get details of a key |
|
1089 * @param aKeyId SubjectKeyID |
|
1090 * @param aKeyDetails [out] Returned details of a key. |
|
1091 *-------------------------------------------------------------------------*/ |
|
1092 EXPORT_C TInt RPKIServiceAPI::KeyDetails(const TPKIKeyIdentifier& aKeyId, |
|
1093 TKeyListEntry &aKeyDetails) const |
|
1094 { |
|
1095 TPckg<TKeyListEntry> keyDetails(aKeyDetails); |
|
1096 |
|
1097 //Send request to the server |
|
1098 return SendReceive (PkiService::EGetKeyDetails, TIpcArgs(&keyDetails, &aKeyId)); |
|
1099 } |
|
1100 |
|
1101 |
|
1102 /**--------------------------------------------------------------------------- |
|
1103 * List all certificate request |
|
1104 * @param aCertReqList [out] Returned list of certificates. |
|
1105 *---------------------------------------------------------------------------*/ |
|
1106 EXPORT_C void RPKIServiceAPI::ListCertificateRequestsL( |
|
1107 CArrayFix<TCertificateRequestListEntry> *&aCertReqList) const |
|
1108 { |
|
1109 // Get request count |
|
1110 TInt reqCount = SendReceive(PkiService::ECertReqCount, TIpcArgs(NULL)); |
|
1111 |
|
1112 TInt reqListGranularity = reqCount; |
|
1113 if (reqListGranularity == 0) |
|
1114 { |
|
1115 reqListGranularity = 1; |
|
1116 } |
|
1117 |
|
1118 CArrayFix<TCertificateRequestListEntry>* reqList; |
|
1119 reqList = new (ELeave) CArrayFixFlat<TCertificateRequestListEntry>(reqListGranularity); |
|
1120 if (reqCount == 0) |
|
1121 { |
|
1122 aCertReqList = reqList; |
|
1123 return; |
|
1124 } |
|
1125 |
|
1126 CleanupStack::PushL(reqList); |
|
1127 |
|
1128 CBufFlat* list = CBufFlat::NewL(sizeof(TCertificateRequestListEntry)); |
|
1129 CleanupStack::PushL(list); |
|
1130 list->ResizeL(reqCount * sizeof(TCertificateRequestListEntry)); |
|
1131 |
|
1132 TPtr8 ptrList = list->Ptr(0); |
|
1133 |
|
1134 User::LeaveIfError(SendReceive (PkiService::EGetCertReqList, TIpcArgs(&ptrList))); |
|
1135 |
|
1136 TCertificateRequestListEntry reqRef; |
|
1137 for (TInt i = 0; i < reqCount; i++) |
|
1138 { |
|
1139 list->Read(i * sizeof(TCertificateRequestListEntry), (TAny*)&reqRef, sizeof(TCertificateRequestListEntry)); |
|
1140 reqList->AppendL(reqRef); |
|
1141 } |
|
1142 |
|
1143 CleanupStack::PopAndDestroy(1); // list |
|
1144 CleanupStack::Pop(); // reqList |
|
1145 |
|
1146 aCertReqList = reqList; |
|
1147 } |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 /**--------------------------------------------------------- |
|
1153 * |
|
1154 * Close() |
|
1155 * |
|
1156 * Closes a session to PKIService |
|
1157 * |
|
1158 * |
|
1159 *----------------------------------------------------------*/ |
|
1160 EXPORT_C void RPKIServiceAPI::Close(void) |
|
1161 { |
|
1162 RSessionBase::Close(); |
|
1163 } |
|
1164 |
|
1165 |
|
1166 /** |
|
1167 * Set store types (either device or user stores used) |
|
1168 * |
|
1169 */ |
|
1170 EXPORT_C TInt RPKIServiceAPI::SetStoreType(TPkiServiceStoreType aStoreType) const |
|
1171 { |
|
1172 TInt ret = KErrNone; |
|
1173 TInt type(aStoreType); |
|
1174 // Make sure a valid store type has been specified |
|
1175 TPckgC<TInt> storeType(aStoreType); |
|
1176 |
|
1177 // Use the requested store type for both cert and key stores. |
|
1178 ret = SendReceive(PkiService::ESetCertStoreType, TIpcArgs(type)); |
|
1179 if (ret == KErrNone) |
|
1180 { |
|
1181 ret = SendReceive(PkiService::ESetKeyStoreType, TIpcArgs(type)); |
|
1182 } |
|
1183 |
|
1184 return ret; |
|
1185 } |
|
1186 |
|
1187 EXPORT_C TInt RPKIServiceAPI::SetStoreType(TInt aStore, |
|
1188 TPkiServiceStoreType aStoreType) const |
|
1189 { |
|
1190 TInt ret = KErrNone; |
|
1191 |
|
1192 switch (aStore) |
|
1193 { |
|
1194 case STORE_KEYSTORE: |
|
1195 ret = SendReceive (PkiService::ESetKeyStoreType, TIpcArgs(aStoreType)); |
|
1196 break; |
|
1197 case STORE_CERTSTORE: |
|
1198 ret = SendReceive (PkiService::ESetCertStoreType, TIpcArgs(aStoreType)); |
|
1199 break; |
|
1200 default: |
|
1201 ret = KErrNotSupported; |
|
1202 } |
|
1203 |
|
1204 return ret; |
|
1205 } |
|
1206 |
|
1207 EXPORT_C TInt RPKIServiceAPI::CertStoreType(TPkiServiceStoreType& aStoreType) const |
|
1208 { |
|
1209 aStoreType = static_cast<TPkiServiceStoreType>(SendReceive(PkiService::EGetCertStoreType)); |
|
1210 return KErrNone; |
|
1211 } |
|
1212 |
|
1213 EXPORT_C TInt RPKIServiceAPI::KeyStoreType(TPkiServiceStoreType& aStoreType) const |
|
1214 { |
|
1215 aStoreType = static_cast<TPkiServiceStoreType>(SendReceive(PkiService::EGetKeyStoreType)); |
|
1216 return KErrNone; |
|
1217 } |
|
1218 |
|
1219 EXPORT_C void RPKIServiceAPI::SetInformational(const TBool aInfoOnly) |
|
1220 { |
|
1221 SendReceive(PkiService::ESetInformational, TIpcArgs(aInfoOnly)); |
|
1222 } |
|
1223 |