|
1 /* |
|
2 * Copyright (c) 2005 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 the CPKIDialog class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPKIDlg.h" |
|
21 #include "CTSecurityDialogRequestor.h" |
|
22 #include "CTSecurityDialogDefs.h" |
|
23 #include <s32mem.h> |
|
24 |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // MACROS |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 |
|
36 // MODULE DATA STRUCTURES |
|
37 |
|
38 // LOCAL FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 EXPORT_C MPKIDialog* PKIDialogFactory::CreateNoteL() |
|
46 { |
|
47 return CPKIDialog::NewL(); |
|
48 } |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CPKIDialog::CPKIDialog |
|
54 // C++ default constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CPKIDialog::CPKIDialog() |
|
59 { |
|
60 } |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CPKIDialog::ConstructL |
|
63 // Symbian 2nd phase constructor can leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CPKIDialog::ConstructL() |
|
67 { |
|
68 iRequester = CCTSecurityDialogRequestor::NewL( *this ); |
|
69 iSenderBuffer = CBufFlat::NewL( KCTSecDialSendBufLen ); |
|
70 } |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CPKIDialog::NewL |
|
73 // Two-phased constructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CPKIDialog* CPKIDialog::NewL() |
|
77 { |
|
78 CPKIDialog* self = new( ELeave ) CPKIDialog; |
|
79 |
|
80 CleanupStack::PushL( self ); |
|
81 self->ConstructL(); |
|
82 CleanupStack::Pop( self ); |
|
83 |
|
84 return self; |
|
85 } |
|
86 |
|
87 |
|
88 // Destructor |
|
89 CPKIDialog::~CPKIDialog() |
|
90 { |
|
91 if ( iRequester ) |
|
92 { |
|
93 iRequester->Cancel(); |
|
94 } |
|
95 delete iRequester; |
|
96 delete iSenderBuffer; |
|
97 delete iBufferData; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CPKIDialog::?member_function |
|
102 // ?implementation_description |
|
103 // (other items were commented in a header). |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CPKIDialog::UserAuthentication( |
|
107 const RArray<TCTTokenObjectHandle>& aCertHandleList, |
|
108 TCTTokenObjectHandle& aCertHandle, |
|
109 TRequestStatus& aStatus ) |
|
110 { |
|
111 iCurrentOperation = EUserAuthentication; |
|
112 InitClientStatus( aStatus ); |
|
113 |
|
114 TSignInput signInput; |
|
115 signInput.iOperation = EUserAuthentication; |
|
116 signInput.iCertHandleArrayTotal = aCertHandleList.Count(); |
|
117 TPckgC<TSignInput> signInputBufPtr( signInput ); |
|
118 // iSignInputBuf is persistent because further input processing occurs in the AO before |
|
119 // calling the notifier. |
|
120 iSignInputBuf.Copy( signInputBufPtr ); |
|
121 iVariableDataPtr.Set( NULL, 0 ); |
|
122 iClientCertInfoHandlePtr = &aCertHandle; |
|
123 |
|
124 iRequester->RequestVariableBufferDialog( iSignInputBuf, iVariableDataPtr, |
|
125 aCertHandleList, iCertInfoHandleBuf ); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CPKIDialog::?member_function |
|
130 // ?implementation_description |
|
131 // (other items were commented in a header). |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CPKIDialog::UserAuthenticationText( |
|
135 const TDesC& aTextToSign, |
|
136 const RArray<TCTTokenObjectHandle>& aCertHandleList, |
|
137 TCTTokenObjectHandle& aCertHandle, |
|
138 TRequestStatus& aStatus ) |
|
139 { |
|
140 iCurrentOperation = EUserAuthenticationText; |
|
141 InitClientStatus( aStatus ); |
|
142 |
|
143 TInt textSize = aTextToSign.Size(); |
|
144 TSignInput signInput; |
|
145 signInput.iOperation = EUserAuthenticationText; |
|
146 signInput.iVariableDataSize = textSize; |
|
147 signInput.iCertHandleArrayTotal = aCertHandleList.Count(); |
|
148 TPckgC<TSignInput> signInputBufPtr( signInput ); |
|
149 // iSignInputBuf is persistent because further input processing occurs in the AO before |
|
150 // calling the notifier. |
|
151 iSignInputBuf.Copy( signInputBufPtr ); |
|
152 const TUint8* textToSignPtr = reinterpret_cast<const TUint8*>( aTextToSign.Ptr() ); |
|
153 iVariableDataPtr.Set( textToSignPtr, textSize ); |
|
154 |
|
155 iClientCertInfoHandlePtr = &aCertHandle; |
|
156 |
|
157 iRequester->RequestVariableBufferDialog( iSignInputBuf, iVariableDataPtr, |
|
158 aCertHandleList, iCertInfoHandleBuf ); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CPKIDialog::?member_function |
|
163 // ?implementation_description |
|
164 // (other items were commented in a header). |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CPKIDialog::RequestWithTokenHandleL( |
|
168 const TDesC& aText, |
|
169 const TCTTokenObjectHandle& aTokenHandle, |
|
170 TRequestStatus& aStatus ) |
|
171 { |
|
172 InitClientStatus(aStatus); |
|
173 |
|
174 iSenderBuffer->Reset(); |
|
175 RBufWriteStream stream; |
|
176 CleanupClosePushL( stream ); |
|
177 stream.Open( *iSenderBuffer ); |
|
178 |
|
179 stream.WriteInt32L( iCurrentOperation ); |
|
180 if (0 < aText.Length()) |
|
181 { |
|
182 stream.WriteInt32L( aText.Length() ); |
|
183 stream << aText; |
|
184 } |
|
185 // new stuff begin |
|
186 delete iBufferData; |
|
187 TInt inputBufferSize = |
|
188 iSenderBuffer->Ptr(0).Size() + sizeof(TCTTokenObjectHandle); |
|
189 |
|
190 iBufferData = HBufC8::NewL( inputBufferSize ); |
|
191 TPtr8 inputBufferPtr( iBufferData->Des() ); |
|
192 inputBufferPtr = iSenderBuffer->Ptr(0); |
|
193 |
|
194 TPckgC<TCTTokenObjectHandle> handleBuf( aTokenHandle ); |
|
195 inputBufferPtr.Append( handleBuf ); |
|
196 |
|
197 // new stuff end |
|
198 CleanupStack::PopAndDestroy(); // stream.close; |
|
199 iRequester->RequestDialog(*iBufferData, iDlgResponseBuf); |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CPKIDialog::?member_function |
|
204 // ?implementation_description |
|
205 // (other items were commented in a header). |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void CPKIDialog::CreateCSR( |
|
209 const TDesC& aSubject, |
|
210 const TCTTokenObjectHandle& aKeyHandle, |
|
211 TRequestStatus& aStatus ) |
|
212 { |
|
213 iCurrentOperation = ECreateCSR; |
|
214 TRAPD(ret, RequestWithTokenHandleL(aSubject, aKeyHandle, aStatus)); |
|
215 if (ret!=KErrNone) |
|
216 { |
|
217 User::RequestComplete(iClientStatus, ret); |
|
218 } |
|
219 |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CPKIDialog::?member_function |
|
224 // ?implementation_description |
|
225 // (other items were commented in a header). |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 void CPKIDialog::CertificateDetails( |
|
229 const TCTTokenObjectHandle& aCertHandle, |
|
230 TRequestStatus& aStatus ) |
|
231 { |
|
232 iCurrentOperation = ECertDetails; |
|
233 TRAPD(ret, RequestWithTokenHandleL(KNullDesC, aCertHandle, aStatus)); |
|
234 if (ret!=KErrNone) |
|
235 { |
|
236 User::RequestComplete(iClientStatus, ret); |
|
237 } |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CPKIDialog::?member_function |
|
242 // ?implementation_description |
|
243 // (other items were commented in a header). |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CPKIDialog::SaveCertificate( |
|
247 TCertificateFormat aFormat, |
|
248 TCertificateOwnerType aCertificateOwnerType, |
|
249 const TDesC8& aCert, TRequestStatus& aStatus) |
|
250 { |
|
251 TRAPD(ret, DoSaveCertificateL(aFormat, aCertificateOwnerType, aCert, aStatus)); |
|
252 if (ret!=KErrNone) |
|
253 { |
|
254 User::RequestComplete(iClientStatus, ret); |
|
255 } |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CPKIDialog::?member_function |
|
260 // ?implementation_description |
|
261 // (other items were commented in a header). |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CPKIDialog::DoSaveCertificateL( |
|
265 TCertificateFormat aFormat, |
|
266 TCertificateOwnerType aCertificateOwnerType, |
|
267 const TDesC8& aCert, TRequestStatus& aStatus) |
|
268 { |
|
269 iCurrentOperation = ESaveCert; |
|
270 InitClientStatus( aStatus ); |
|
271 |
|
272 TSaveCertInput saveCertInput; |
|
273 saveCertInput.iOperation = ESaveCert; |
|
274 saveCertInput.iCertFormat = aFormat; |
|
275 saveCertInput.iCertOwnerType = aCertificateOwnerType; |
|
276 saveCertInput.iDataSize = aCert.Size(); |
|
277 |
|
278 TPckgC<TSaveCertInput> saveCertInputBuf( saveCertInput ); |
|
279 |
|
280 //const TUint8* textToSignPtr = reinterpret_cast<const TUint8*>( aCert.Ptr() ); |
|
281 |
|
282 // new stuff begin |
|
283 delete iBufferData; |
|
284 TInt inputBufferSize = aCert.Size() + sizeof(TSaveCertInput); |
|
285 |
|
286 iBufferData = HBufC8::NewL( inputBufferSize ); |
|
287 TPtr8 inputBufferPtr( iBufferData->Des() ); |
|
288 inputBufferPtr.Append( saveCertInputBuf ); |
|
289 inputBufferPtr.Append(aCert); |
|
290 iRequester->RequestDialog(*iBufferData, iDlgResponseBuf); |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CPKIDialog::?member_function |
|
295 // ?implementation_description |
|
296 // (other items were commented in a header). |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CPKIDialog::DeleteCertificate( |
|
300 const TCTTokenObjectHandle& aCertHandle, |
|
301 TRequestStatus& aStatus ) |
|
302 { |
|
303 iCurrentOperation = EDeleteCert; |
|
304 TRAPD(ret, RequestWithTokenHandleL(KNullDesC, aCertHandle, aStatus)); |
|
305 if (ret!=KErrNone) |
|
306 { |
|
307 User::RequestComplete(iClientStatus, ret); |
|
308 } |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CPKIDialog::?member_function |
|
313 // ?implementation_description |
|
314 // (other items were commented in a header). |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CPKIDialog::SaveSignedText( |
|
318 const TDesC& aSignedText, |
|
319 TRequestStatus& aStatus ) |
|
320 { |
|
321 TCTTokenObjectHandle tokenHandle; |
|
322 iCurrentOperation = ESaveReceipt; |
|
323 TRAPD(ret, RequestWithTokenHandleL(aSignedText, tokenHandle, aStatus)); |
|
324 if (ret!=KErrNone) |
|
325 { |
|
326 User::RequestComplete(iClientStatus, ret); |
|
327 } |
|
328 } |
|
329 // ----------------------------------------------------------------------------- |
|
330 // CPKIDialog::?member_function |
|
331 // ?implementation_description |
|
332 // (other items were commented in a header). |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CPKIDialog::PINBlockedInfo( |
|
336 const TPINLabel& aLabel, |
|
337 TRequestStatus& aStatus ) |
|
338 { |
|
339 iCurrentOperation = EPinCodeBlockedInfo; |
|
340 InitClientStatus(aStatus); |
|
341 |
|
342 iSenderBuffer->Reset(); |
|
343 RBufWriteStream stream; |
|
344 CleanupClosePushL( stream ); |
|
345 stream.Open( *iSenderBuffer ); |
|
346 |
|
347 stream.WriteInt32L( EPinCodeBlockedInfo ); |
|
348 stream << aLabel; |
|
349 // new stuff begin |
|
350 delete iBufferData; |
|
351 iBufferData = NULL; |
|
352 iBufferData = HBufC8::NewL( iSenderBuffer->Ptr(0).Size() ); |
|
353 iBufferData->Des() = iSenderBuffer->Ptr(0); |
|
354 // new stuff end |
|
355 CleanupStack::PopAndDestroy(); // stream.close; |
|
356 iRequester->RequestDialog(*iBufferData, iDlgResponseBuf); |
|
357 } |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // CPKIDialog::Note |
|
361 // ?implementation_description |
|
362 // (other items were commented in a header). |
|
363 // ----------------------------------------------------------------------------- |
|
364 // |
|
365 void CPKIDialog::Note( |
|
366 MPKIDialog::TNoteType aNoteType, |
|
367 TRequestStatus& aStatus ) |
|
368 { |
|
369 ShowNoteL( aStatus, aNoteType ); |
|
370 } |
|
371 |
|
372 // ----------------------------------------------------------------------------- |
|
373 // CPKIDialog::ShowNoteL |
|
374 // ----------------------------------------------------------------------------- |
|
375 // |
|
376 void CPKIDialog::ShowNoteL( |
|
377 TRequestStatus& aStatus, |
|
378 TInt aDlgType, |
|
379 const TDesC& aDynamic) |
|
380 { |
|
381 |
|
382 InitClientStatus( aStatus ); |
|
383 |
|
384 iSenderBuffer->Reset(); |
|
385 RBufWriteStream stream; |
|
386 CleanupClosePushL( stream ); |
|
387 stream.Open( *iSenderBuffer ); |
|
388 |
|
389 stream.WriteInt32L( aDlgType ); |
|
390 stream.WriteInt32L( aDynamic.Length() ); |
|
391 stream << aDynamic; |
|
392 |
|
393 stream.WriteInt32L(0); |
|
394 stream << KNullDesC; |
|
395 |
|
396 delete iBufferData; |
|
397 iBufferData = NULL; |
|
398 iBufferData = HBufC8::NewL(iSenderBuffer->Ptr(0).Size()); |
|
399 iBufferData->Des() = iSenderBuffer->Ptr(0); |
|
400 CleanupStack::PopAndDestroy(); // stream.close; |
|
401 |
|
402 iRequester->RequestDialog(*iBufferData, iDlgResponseBuf); |
|
403 } |
|
404 |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CPKIDialog::Release |
|
408 // |
|
409 // ----------------------------------------------------------------------------- |
|
410 // |
|
411 void CPKIDialog::Release() |
|
412 { |
|
413 delete this; |
|
414 } |
|
415 |
|
416 // ----------------------------------------------------------------------------- |
|
417 // CPKIDialog::InitClientStatus |
|
418 // InitClientStatus initialises the client's RequestStatus object. |
|
419 // ----------------------------------------------------------------------------- |
|
420 // |
|
421 void CPKIDialog::InitClientStatus( TRequestStatus& aStatus ) |
|
422 { |
|
423 iClientStatus = &aStatus; |
|
424 *iClientStatus = KRequestPending; |
|
425 } |
|
426 |
|
427 // ----------------------------------------------------------------------------- |
|
428 // CPKIDialog::HandleResponse |
|
429 // |
|
430 // ----------------------------------------------------------------------------- |
|
431 // |
|
432 void CPKIDialog::HandleResponse(TInt aResult) |
|
433 { |
|
434 switch ( iCurrentOperation ) |
|
435 { |
|
436 case EUserAuthenticationText: |
|
437 case EUserAuthentication: |
|
438 { |
|
439 *iClientCertInfoHandlePtr = iCertInfoHandleBuf(); |
|
440 break; |
|
441 } |
|
442 default: |
|
443 // Do nothing, just client status complete. |
|
444 break; |
|
445 |
|
446 } |
|
447 User::RequestComplete(iClientStatus, aResult); |
|
448 } |
|
449 |
|
450 // End of File |