|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "cstspkcs15reader.h" |
|
22 #include "cstspkcs15objects.h" |
|
23 #include "cstspath.h" |
|
24 #include "cstsacie.h" |
|
25 #include "cstsefacifile.h" |
|
26 #include "cstsefacfile.h" |
|
27 #include "cstsfiledatamanager.h" |
|
28 #include "cstsuserauth.h" |
|
29 #include "cstsace.h" |
|
30 |
|
31 namespace java |
|
32 { |
|
33 namespace satsa |
|
34 { |
|
35 |
|
36 // CONSTANTS |
|
37 const TInt KSTSDefaultGranularity = 2; |
|
38 |
|
39 CSTSPKCS15Reader::CSTSPKCS15Reader() |
|
40 { |
|
41 iState = ENotOpened; |
|
42 } |
|
43 |
|
44 void CSTSPKCS15Reader::ConstructL() |
|
45 { |
|
46 iAcies = new(ELeave) CArrayPtrFlat<CSTSAcie> (KSTSDefaultGranularity); |
|
47 iAID = KNullDesC8().AllocL(); |
|
48 iFileDataManager = CSTSFileDataManager::NewL(); |
|
49 } |
|
50 |
|
51 CSTSPKCS15Reader* CSTSPKCS15Reader::NewL() |
|
52 { |
|
53 CSTSPKCS15Reader* self = new(ELeave) CSTSPKCS15Reader(); |
|
54 |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(); |
|
57 |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // Destructor |
|
63 CSTSPKCS15Reader::~CSTSPKCS15Reader() |
|
64 { |
|
65 Close(); |
|
66 delete iFileDataManager; |
|
67 delete iAID; |
|
68 if (iAcies) |
|
69 { |
|
70 iAcies->ResetAndDestroy(); |
|
71 delete iAcies; |
|
72 } |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CSTSPKCS15Reader::OpenL |
|
77 // Opens channel to card and tries to select PKCS15 application with AID. If |
|
78 // directly selection was not allowed, reads EF(DIR) file for finding path to |
|
79 // PCKS15 application. Reads EF(ODF) and reads path to EF(DODF) and EF(AODF). |
|
80 // Finally reads EF(TokenInfo) for finding label for token. |
|
81 // (other items were commented in a header). |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CSTSPKCS15Reader::OpenL() |
|
85 { |
|
86 iFileDataManager->InitializeL(); |
|
87 // if no leaves, pkcs15 application is opened succesfully |
|
88 iState = EPCKS15Opened; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CSTSPKCS15Reader::Close |
|
93 // Close channnel to card |
|
94 // (other items were commented in a header). |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CSTSPKCS15Reader::Close() |
|
98 { |
|
99 iState = EClosed; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CSTSPKCS15Reader::ReadACFL |
|
104 // Reads first EF(DODF) for finding path to ACIF. Reads ACIF for finding path |
|
105 // to Access Control Files (ACF). Reads all Access Control files. |
|
106 // (other items were commented in a header). |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CSTSPKCS15Reader::ReadACFL(CArrayPtr<CSTSAce>* aAces) |
|
110 { |
|
111 |
|
112 ReadACIFL(); |
|
113 |
|
114 TInt foundCount = 0; |
|
115 TInt aciesCount = iAcies->Count(); |
|
116 |
|
117 CSTSEFACFile* acf = CSTSEFACFile::NewLC(iFileDataManager); |
|
118 acf->SetArray(aAces); |
|
119 |
|
120 // read all Access control files |
|
121 for (TInt i = 0; i < aciesCount; i++) |
|
122 { |
|
123 // select ACF |
|
124 acf->SetPath(iAcies->At(i)->ACFPath().Path()); |
|
125 acf->ReadL(0); // we read all data to previous set array |
|
126 foundCount += acf->FoundRecords(); |
|
127 } |
|
128 CleanupStack::PopAndDestroy(acf); |
|
129 |
|
130 // compress the size of array |
|
131 aAces->Compress(); |
|
132 |
|
133 // The ACF contains an Access Control List (ACL). The ACL consists of |
|
134 // zero or more Access Control Entries(ACE). If the ACL is empty, access |
|
135 // is denied for all domains. |
|
136 if (foundCount == 0) |
|
137 { |
|
138 User::Leave(KSTSErrSecurity + KSTSErrSECAccessNotAllowed); |
|
139 } |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CSTSPKCS15Reader::ReadAuthObjectsL |
|
144 // Read the Authentication files to get authId |
|
145 // (other items were commented in a header). |
|
146 // ----------------------------------------------------------------------------- |
|
147 |
|
148 void CSTSPKCS15Reader::ReadAuthObjectsL(CArrayPtr<CSTSAuthType>* aAuthTypes, |
|
149 const CArrayPtr<CSTSAce>& aAces) |
|
150 { |
|
151 // create a list of used authIds in loop |
|
152 RArray<TInt> authIdList; |
|
153 |
|
154 // go throuhg all aces |
|
155 TInt acesCount = aAces.Count(); |
|
156 for (TInt x = 0; x < acesCount; x++) |
|
157 { |
|
158 CSTSAce* currentAce = aAces.At(x); |
|
159 |
|
160 TInt userAuthsCount = currentAce->UserAuthentications().Count(); |
|
161 // take authIds which are needed |
|
162 for (TInt i = 0; i < userAuthsCount; i++) |
|
163 { |
|
164 CSTSUserAuth* currentUserAuth = |
|
165 currentAce->UserAuthentications().At(i); |
|
166 // first element of authId descriptor is the authId |
|
167 authIdList.AppendL(currentUserAuth->AuthId()[0]); |
|
168 } |
|
169 } |
|
170 |
|
171 iFileDataManager->GetAuthObjectsL(aAuthTypes, authIdList); |
|
172 |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CSTSPKCS15Reader::SetAIDL |
|
177 // |
|
178 // (other items were commented in a header). |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CSTSPKCS15Reader::SetAIDL(const TDesC8& aAID) |
|
182 { |
|
183 HBufC8* tmp = aAID.AllocL(); |
|
184 delete iAID; |
|
185 iAID = tmp; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CSTSPKCS15Reader::ReadACIFL |
|
190 // Selects Access Control Index File (ACIF). Reads every record of that file |
|
191 // and finds with AID correct record and saves it to memeber array. Saves that |
|
192 // kind of records too, where AID is missing, because it is meant for all |
|
193 // applications. |
|
194 // If correct records is not found, leaves with KSTSErrSecurity error |
|
195 // code. |
|
196 // (other items were commented in a header). |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CSTSPKCS15Reader::ReadACIFL() |
|
200 { |
|
201 // select EF(DODF) |
|
202 CSTSEFACIFile* acif = CSTSEFACIFile::NewLC(iFileDataManager); |
|
203 acif->SetAIDL(*iAID); |
|
204 acif->SetArray(iAcies); |
|
205 acif->ReadL(0); // we read all data |
|
206 |
|
207 CleanupStack::PopAndDestroy(acif); |
|
208 |
|
209 TInt foundCount = acif->FoundRecords(); |
|
210 |
|
211 // there can be only 2 of correct Acies, otherwise something is wrong |
|
212 if (foundCount > 2) |
|
213 { |
|
214 User::Leave(KSTSErrConnectionNotFound); |
|
215 } |
|
216 |
|
217 // compress the size of array |
|
218 iAcies->Compress(); |
|
219 |
|
220 if (foundCount == 0) |
|
221 { |
|
222 // In the absence of an ACF related to the entire SE access to |
|
223 // applications that do not have their respective ACFs, is not |
|
224 // allowed. |
|
225 User::Leave(KSTSErrSecurity + KSTSErrSECAccessNotAllowed); |
|
226 } |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CSTSPKCS15Reader::GetTokenLabel |
|
231 // Returns token label. |
|
232 // (other items were commented in a header). |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 const TDesC& CSTSPKCS15Reader::TokenLabelL() |
|
236 { |
|
237 return iFileDataManager->RetrieveWIMLabelL(); |
|
238 } |
|
239 |
|
240 } // namespace satsa |
|
241 } // namespace java |
|
242 // End of File |
|
243 |