|
1 /* |
|
2 * Copyright (c) 2006-2009 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 the License "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: |
|
15 * legacy plugin selector implementation |
|
16 * Legacy plugin selector implementation |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 #include "cryptospiutil.h" |
|
25 #include "cryptospiproperty.h" |
|
26 #include "e32uid.h" |
|
27 #include <cryptospi/cryptospidef.h> |
|
28 #include <e32property.h> |
|
29 #include "rulecharacteristics.h" |
|
30 |
|
31 using namespace CryptoSpi; |
|
32 |
|
33 /** |
|
34 The name of the executable which set up all the crypto spi |
|
35 */ |
|
36 _LIT(KCryptoSpiPropertySetupExe, "z:\\sys\\bin\\cryptospisetup.exe"); |
|
37 |
|
38 void CryptoSpiUtil::RetrieveCharacteristicsL(TInt32 aInterface, RPointerArray<CCharacteristicsAndPluginName>& aList) |
|
39 { |
|
40 RDesReadStream stream; |
|
41 RBuf8 rBuf; |
|
42 TInt count=0; |
|
43 CleanupClosePushL(rBuf); |
|
44 TInt length=RetrieveCharacteristicsL(aInterface, stream, rBuf, count); |
|
45 if (length<=4) |
|
46 { |
|
47 CleanupStack::PopAndDestroy(&rBuf); |
|
48 return; |
|
49 } |
|
50 |
|
51 //internalize the characteristics and dll index |
|
52 for (TInt i=0;i<count;i++) |
|
53 { |
|
54 CCharacteristicsAndPluginName* temp=CCharacteristicsAndPluginName::NewLC(aInterface); |
|
55 temp->InternalizeL(stream); |
|
56 aList.AppendL(temp); |
|
57 CleanupStack::Pop(temp); //temp |
|
58 } |
|
59 CleanupStack::PopAndDestroy(&rBuf); |
|
60 } |
|
61 |
|
62 void CryptoSpiUtil::RetrieveCharacteristicsL(TInt32 aInterface, RPointerArray<CRulesCharacteristicsAndPluginName>& aList) |
|
63 { |
|
64 RDesReadStream stream; |
|
65 RBuf8 rBuf; |
|
66 TInt count=0; |
|
67 CleanupClosePushL(rBuf); |
|
68 TInt length=RetrieveCharacteristicsL(aInterface, stream, rBuf, count); |
|
69 if (length<=4) |
|
70 { |
|
71 CleanupStack::PopAndDestroy(&rBuf); |
|
72 return; |
|
73 } |
|
74 |
|
75 //internalize the characteristics and dll index |
|
76 for (TInt i=0;i<count;i++) |
|
77 { |
|
78 CRulesCharacteristicsAndPluginName* temp=CRulesCharacteristicsAndPluginName::NewLC(aInterface); |
|
79 temp->InternalizeL(stream); |
|
80 aList.AppendL(temp); |
|
81 CleanupStack::Pop(temp); //temp |
|
82 } |
|
83 CleanupStack::PopAndDestroy(&rBuf); |
|
84 } |
|
85 |
|
86 TInt CryptoSpiUtil::RetrieveCharacteristicsL(TInt32 aInterface, RDesReadStream& aStream, RBuf8& aBuf, TInt& aCount) |
|
87 { |
|
88 TBuf8<KMaxFileName> buf; |
|
89 TInt testResult = RProperty::Get(KCryptoSpiPropertyCat, aInterface, buf); |
|
90 if (testResult==KErrNotFound) |
|
91 { |
|
92 //run the exe to Publish the properties |
|
93 RunCryptoSpiPropertySetupExe(); |
|
94 testResult = RProperty::Get(KCryptoSpiPropertyCat, aInterface, buf); |
|
95 if (testResult==KErrNotFound) |
|
96 { |
|
97 //Error |
|
98 User::Leave(testResult); |
|
99 } |
|
100 } |
|
101 |
|
102 //Try to read the length first |
|
103 RDesReadStream rStream(buf); |
|
104 TInt32 len=rStream.ReadInt32L(); |
|
105 |
|
106 //If the property is empty |
|
107 if (len<=4) |
|
108 { |
|
109 return len; |
|
110 } |
|
111 |
|
112 //Allocate memory |
|
113 aBuf.CreateMaxL(len); |
|
114 User::LeaveIfError(RProperty::Get(KCryptoSpiPropertyCat, aInterface, aBuf)); |
|
115 |
|
116 //Read the length |
|
117 aStream.Open(aBuf); |
|
118 len=aStream.ReadInt32L(); |
|
119 |
|
120 //Read the count of the characteristics |
|
121 aCount=aStream.ReadInt16L(); |
|
122 return len; |
|
123 } |
|
124 |
|
125 TInt CryptoSpiUtil::DllIndexToName(TInt aDllIndex, TFileName& aName) |
|
126 { |
|
127 TInt dllCount=0; |
|
128 TInt result = RProperty::Get(KCryptoSpiPropertyCat, KPluginsConfigurationKeyCount, dllCount); |
|
129 if (result==KErrNotFound) |
|
130 { |
|
131 //run the exe to publish the properties |
|
132 RunCryptoSpiPropertySetupExe(); |
|
133 result = RProperty::Get(KCryptoSpiPropertyCat, KPluginsConfigurationKeyCount, dllCount); |
|
134 if (result==KErrNotFound) |
|
135 { |
|
136 return KErrNotFound; |
|
137 } |
|
138 } |
|
139 if (aDllIndex>=dllCount) |
|
140 { |
|
141 return KErrNotFound; |
|
142 } |
|
143 |
|
144 TBuf8<KMaxFileName> buf; |
|
145 result = RProperty::Get(KCryptoSpiPropertyCat, KPluginsConfigurationKey+aDllIndex, buf); |
|
146 if (result==KErrNotFound) |
|
147 { |
|
148 return KErrNotFound; |
|
149 } |
|
150 |
|
151 RDesReadStream rStream(buf); |
|
152 rStream>>aName; |
|
153 return KErrNone; |
|
154 } |
|
155 |
|
156 void CryptoSpiUtil::LoadPluginDllLC(RLibrary& aLib, TFileName& aFileName) |
|
157 { |
|
158 User::LeaveIfError(aLib.Load(aFileName)); |
|
159 CleanupClosePushL(aLib); |
|
160 RLibrary plugin=aLib; |
|
161 CleanupClosePushL(plugin); |
|
162 User::LeaveIfError(aLib.Duplicate(RThread(), EOwnerProcess)); |
|
163 CleanupStack::PopAndDestroy(&plugin); |
|
164 } |
|
165 |
|
166 TInt CryptoSpiUtil::RunCryptoSpiPropertySetupExe() |
|
167 { |
|
168 const TUidType setupExeUidType(KExecutableImageUid, TUid::Null(), KCryptoSpiPropertyCat); |
|
169 RProcess setupProc; |
|
170 TInt result = setupProc.Create(KCryptoSpiPropertySetupExe, KNullDesC, setupExeUidType); |
|
171 if (result != KErrNone) |
|
172 { |
|
173 return result; |
|
174 } |
|
175 TRequestStatus setupStatus; |
|
176 // request Rendezvous before Resume() to avoid race condition. |
|
177 // Also note if request to rendezvous fails (OOM etc.) then setup exe may |
|
178 // complete after query code, with feature property possibly undefined |
|
179 setupProc.Rendezvous(setupStatus); |
|
180 setupProc.Resume(); |
|
181 setupProc.Close(); |
|
182 User::WaitForRequest(setupStatus); |
|
183 return setupStatus.Int(); |
|
184 } |
|
185 |
|
186 CCharacteristics* CryptoSpiUtil::CreateCharacteristicsL(TInt32 aInterface) |
|
187 { |
|
188 CCharacteristics* character=NULL; |
|
189 switch (aInterface) |
|
190 { |
|
191 case KHashInterface: |
|
192 case KAsyncHashInterface: |
|
193 character=CHashCharacteristics::NewL(); |
|
194 break; |
|
195 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT |
|
196 case KMacInterface: |
|
197 case KAsyncMacInterface: |
|
198 character=CMacCharacteristics::NewL(); |
|
199 break; |
|
200 #endif |
|
201 case KRandomInterface: |
|
202 case KAsyncRandomInterface: |
|
203 character=CRandomCharacteristics::NewL(); |
|
204 break; |
|
205 |
|
206 case KSymmetricCipherInterface: |
|
207 case KAsyncSymmetricCipherInterface: |
|
208 character=CSymmetricCipherCharacteristics::NewL(); |
|
209 break; |
|
210 |
|
211 case KAsymmetricCipherInterface: |
|
212 case KAsyncAsymmetricCipherInterface: |
|
213 character=CAsymmetricCipherCharacteristics::NewL(); |
|
214 break; |
|
215 |
|
216 case KSignerInterface: |
|
217 case KAsyncSignerInterface: |
|
218 case KVerifierInterface: |
|
219 case KAsyncVerifierInterface: |
|
220 character=CAsymmetricSignatureCharacteristics::NewL(); |
|
221 break; |
|
222 |
|
223 case KKeyAgreementInterface: |
|
224 case KAsyncKeyAgreementInterface: |
|
225 character=CKeyAgreementCharacteristics::NewL(); |
|
226 break; |
|
227 |
|
228 case KKeypairGeneratorInterface: |
|
229 case KAsyncKeypairGeneratorInterface: |
|
230 character=CKeypairGeneratorCharacteristics::NewL(); |
|
231 break; |
|
232 |
|
233 default: |
|
234 User::Leave(KErrNotSupported); |
|
235 } |
|
236 return character; |
|
237 } |
|
238 |