|
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 #include "cstsuserauth.h" |
|
21 |
|
22 namespace java |
|
23 { |
|
24 namespace satsa |
|
25 { |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KSTSMinNumberOfSubModules = 2; |
|
29 |
|
30 const TInt KSTSDefaultGranularity = 1; |
|
31 const TTagType KSTSAPDUPinEntryTag = 0; |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 |
|
36 CSTSUserAuth::CSTSUserAuth() |
|
37 { |
|
38 iType = ENotInitialized; |
|
39 } |
|
40 |
|
41 void CSTSUserAuth::ConstructL() |
|
42 { |
|
43 // creating with empty values |
|
44 iAuthId = KNullDesC8().AllocL(); |
|
45 |
|
46 iApduPinHeaders = new(ELeave) CDesC8ArrayFlat(KSTSDefaultGranularity); |
|
47 } |
|
48 |
|
49 CSTSUserAuth* CSTSUserAuth::NewLC() |
|
50 { |
|
51 CSTSUserAuth* self = new(ELeave) CSTSUserAuth(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 CSTSUserAuth::~CSTSUserAuth() |
|
58 { |
|
59 delete iAuthId; |
|
60 delete iApduPinHeaders; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CSTSUserAuth::DecodeL |
|
65 // Decrypts raw data to this instance |
|
66 // (other items were commented in a header). |
|
67 // ----------------------------------------------------------------------------- |
|
68 void CSTSUserAuth::DecodeL(const TDesC8& aRawData) |
|
69 { |
|
70 CArrayPtr<TASN1DecGeneric>* itemsData = DecodeSequenceLC(ETrue, // must be sequence |
|
71 aRawData, KSTSMinNumberOfSubModules); |
|
72 |
|
73 // we would not get this far if there was atleast two element |
|
74 TInt pos = 0; |
|
75 // decoding authentication id (octet string) |
|
76 TASN1DecOctetString authId; |
|
77 HBufC8* tmp = authId.DecodeDERL(*itemsData->At(pos++)); |
|
78 delete iAuthId; |
|
79 iAuthId = tmp; |
|
80 |
|
81 // decoding user authentication method (choice) |
|
82 // we need: apduPinEntry [0]APDUPinEntry |
|
83 TASN1DecGeneric taggedEntryDec(*itemsData->At(pos++)); |
|
84 taggedEntryDec.InitL(); |
|
85 if (taggedEntryDec.Tag() == KSTSAPDUPinEntryTag) |
|
86 { |
|
87 // set information that apduHeaders used |
|
88 iType = EAPDUPinEntry; |
|
89 // decoding apduPinEntry |
|
90 TASN1DecGeneric decGen(taggedEntryDec.GetContentDER()); |
|
91 TRAPD(err, decGen.InitL()); |
|
92 // it there is some optional headers inside APDUPINEntry |
|
93 if (!err) |
|
94 { |
|
95 CleanupStack::PopAndDestroy(itemsData); |
|
96 itemsData = DecodeSequenceLC(EFalse, taggedEntryDec.Encoding()); |
|
97 TInt numOfHeaders = itemsData->Count(); |
|
98 |
|
99 if (numOfHeaders) |
|
100 { |
|
101 CDesC8ArrayFlat* tmpArray = |
|
102 new(ELeave) CDesC8ArrayFlat(numOfHeaders); |
|
103 CleanupStack::PushL(tmpArray); |
|
104 |
|
105 TUint currentTag = 0; |
|
106 TInt itemsLeft = numOfHeaders; |
|
107 // decode all pinheaders(octet string) in loop |
|
108 for (TInt i = 0; i < numOfHeaders; i++) |
|
109 { |
|
110 TBool ready = EFalse; |
|
111 TASN1DecGeneric decGenApduHeader(*itemsData->At(i)); |
|
112 // we must check tags in order 0 to ... |
|
113 while (!ready && (currentTag <= (TUint)(itemsLeft |
|
114 + currentTag))) |
|
115 { |
|
116 // add found header to correct place in buffer |
|
117 if (decGenApduHeader.Tag() == currentTag) |
|
118 { |
|
119 TASN1DecGeneric decGenApduHeaderDER( |
|
120 itemsData->At(i)->Encoding()); |
|
121 decGenApduHeaderDER.InitL(); |
|
122 TASN1DecOctetString apduHeader; |
|
123 HBufC8* headerBuf = apduHeader.DecodeDERL( |
|
124 decGenApduHeaderDER); |
|
125 CleanupStack::PushL(headerBuf); |
|
126 |
|
127 tmpArray->AppendL(headerBuf->Des()); |
|
128 CleanupStack::PopAndDestroy(headerBuf); |
|
129 ready = ETrue; |
|
130 itemsLeft--; |
|
131 } |
|
132 // there was no header for this tag, so add empty |
|
133 else |
|
134 { |
|
135 tmpArray->AppendL(KNullDesC8()); |
|
136 } |
|
137 currentTag++; |
|
138 } |
|
139 } |
|
140 delete iApduPinHeaders; |
|
141 iApduPinHeaders = tmpArray; |
|
142 // compress to get rid of possible unneccessary slots |
|
143 iApduPinHeaders->Compress(); |
|
144 CleanupStack::Pop(tmpArray); |
|
145 } |
|
146 } |
|
147 } |
|
148 else |
|
149 { |
|
150 iType = EOther; |
|
151 // we won't need others at all |
|
152 } |
|
153 CleanupStack::PopAndDestroy(itemsData); |
|
154 } |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CSTSUserAuth::Type |
|
157 // Getter for type |
|
158 // (other items were commented in a header). |
|
159 // ----------------------------------------------------------------------------- |
|
160 CSTSUserAuth::TType CSTSUserAuth::Type() const |
|
161 { |
|
162 return iType; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CSTSUserAuth::AuthId |
|
167 // Getter for authentication id |
|
168 // (other items were commented in a header). |
|
169 // ----------------------------------------------------------------------------- |
|
170 const TDesC8& CSTSUserAuth::AuthId() const |
|
171 { |
|
172 return *iAuthId; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CSTSUserAuth::ApduPinHeaders |
|
177 // Getter for PIN headers |
|
178 // (other items were commented in a header). |
|
179 // ----------------------------------------------------------------------------- |
|
180 const CDesC8ArrayFlat& CSTSUserAuth::ApduPinHeaders() const |
|
181 { |
|
182 return *iApduPinHeaders; |
|
183 } |
|
184 |
|
185 } // namespace satsa |
|
186 } // namespace java |
|
187 // End of File |
|
188 |