|
1 /* |
|
2 * Copyright (c) 2002 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 CDmAdPrivKey. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <asn1dec.h> |
|
20 |
|
21 #include "dmadstoreprivkey.h" |
|
22 #include "vpnlogger.h" |
|
23 |
|
24 CDmAdPrivKey* CDmAdPrivKey::NewL(RPKIServiceAPI& aPkiServiceApi) |
|
25 { |
|
26 TRACE("CDmAdPrivKey::NewL"); |
|
27 |
|
28 CDmAdPrivKey* self = NewLC(aPkiServiceApi); |
|
29 CleanupStack::Pop(self); |
|
30 return self; |
|
31 } |
|
32 |
|
33 CDmAdPrivKey* CDmAdPrivKey::NewLC(RPKIServiceAPI& aPkiServiceApi) |
|
34 { |
|
35 CDmAdPrivKey* self = new (ELeave) CDmAdPrivKey(aPkiServiceApi); |
|
36 CleanupStack::PushL(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CDmAdPrivKey::CDmAdPrivKey(RPKIServiceAPI& aPkiServiceApi) : iPkiServiceApi(&aPkiServiceApi) |
|
41 { |
|
42 TRACE("CDmAdPrivKey::CDmAdPrivKey"); |
|
43 } |
|
44 |
|
45 CDmAdPrivKey::~CDmAdPrivKey() |
|
46 { |
|
47 TRACE("CDmAdPrivKey::~CDmAdPrivKey"); |
|
48 } |
|
49 |
|
50 TBool CDmAdPrivKey::FindL(const TDesC8& aLuid) |
|
51 { |
|
52 TRACE("CDmAdPrivKey::FindL"); |
|
53 |
|
54 TBool found = EFalse; |
|
55 |
|
56 const TInt KMaxPublicKeyLth = 512; |
|
57 HBufC8* privKeyData = HBufC8::NewLC(KMaxPublicKeyLth); |
|
58 TPtr8 privKeyDataPtr(privKeyData->Des()); |
|
59 |
|
60 TInt status = iPkiServiceApi->ReadPublicKey(aLuid, |
|
61 privKeyDataPtr); |
|
62 if (status == KErrNone) |
|
63 { |
|
64 found = ETrue; |
|
65 } |
|
66 |
|
67 CleanupStack::PopAndDestroy(privKeyData); |
|
68 return found; |
|
69 } |
|
70 |
|
71 void CDmAdPrivKey::FetchL(const TDesC8& aLuid, CDmAdPrivKeyParms& aParms) |
|
72 { |
|
73 TRACE("CDmAdPrivKey::FetchL"); |
|
74 |
|
75 TPkiServiceStoreType currentKeyStore; |
|
76 User::LeaveIfError(iPkiServiceApi->KeyStoreType(currentKeyStore)); |
|
77 User::LeaveIfError(iPkiServiceApi->SetStoreType(STORE_KEYSTORE, EPkiStoreTypeAny)); |
|
78 |
|
79 TKeyListEntry* entry = new (ELeave) TKeyListEntry(); |
|
80 CleanupStack::PushL(entry); |
|
81 User::LeaveIfError(iPkiServiceApi->KeyDetails(aLuid, *entry)); |
|
82 |
|
83 User::LeaveIfError(iPkiServiceApi->SetStoreType(STORE_KEYSTORE, currentKeyStore)); |
|
84 |
|
85 aParms.SetKeyTypeL(entry->iKeyAlgorithm); |
|
86 aParms.SetKeyIdL(entry->iSubjectKeyId); |
|
87 aParms.SetKeyLength(entry->iKeySize); |
|
88 |
|
89 CleanupStack::PopAndDestroy(); // entry |
|
90 } |
|
91 |
|
92 void CDmAdPrivKey::DeleteL(const TDesC8& aLuid) |
|
93 { |
|
94 TRACE("CDmAdPrivKey::DeleteL"); |
|
95 |
|
96 User::LeaveIfError(iPkiServiceApi->RemoveKeypair(aLuid)); |
|
97 } |
|
98 |
|
99 void CDmAdPrivKey::ListL(RPointerArray<HBufC8>& aLuidList) |
|
100 { |
|
101 TRACE("CDmAdPrivKey::ListL"); |
|
102 |
|
103 TPkiServiceStoreType currentKeyStore; |
|
104 User::LeaveIfError(iPkiServiceApi->KeyStoreType(currentKeyStore)); |
|
105 User::LeaveIfError(iPkiServiceApi->SetStoreType(STORE_KEYSTORE, EPkiStoreTypeAny)); |
|
106 |
|
107 CArrayFix<TKeyListEntry>* keyList; |
|
108 iPkiServiceApi->ListKeysL(keyList); |
|
109 CleanupStack::PushL(keyList); |
|
110 |
|
111 User::LeaveIfError(iPkiServiceApi->SetStoreType(STORE_KEYSTORE, currentKeyStore)); |
|
112 |
|
113 for (TInt i=0; i<keyList->Count(); ++i) |
|
114 { |
|
115 TKeyListEntry& entry = keyList->At(i); |
|
116 HBufC8* luidElem = entry.iSubjectKeyId.AllocLC(); |
|
117 aLuidList.AppendL(luidElem); |
|
118 CleanupStack::Pop(luidElem); |
|
119 } |
|
120 |
|
121 CleanupStack::PopAndDestroy(keyList); |
|
122 } |
|
123 |