|
1 /* |
|
2 * Copyright (c) 2010 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: Displays untrusted certificate dialog |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "untrustedcertquery.h" // CUntrustedCertQuery |
|
19 #include <hb/hbcore/hbsymbianvariant.h> // CHbSymbianVariantMap |
|
20 #include "securitydialogstrace.h" // TRACE macro |
|
21 |
|
22 // Note that the dialog type string, the parameters name strings, and the return code |
|
23 // name string and values must match to those defined in Qt-side untrusted certificate |
|
24 // dialog (in untrustedcertificatedefinitions.h file). |
|
25 |
|
26 // Device dialog type for untrusted certificate dialog |
|
27 _LIT( KUntrustedCertificateDialog, "com.nokia.untrustedcert/1.0" ); |
|
28 |
|
29 // Variant map parameter names for untrusted certificate dialog |
|
30 _LIT( KUntrustedCertEncodedCertificate, "cert" ); // bytearray, mandatory |
|
31 _LIT( KUntrustedCertServerName, "host" ); // string, mandatory |
|
32 _LIT( KUntrustedCertValidationError, "err" ); // int (TValidationError), mandatory |
|
33 _LIT( KUntrustedCertTrustedSiteStoreFail, "tss" ); // any, prevents permanent acceptance |
|
34 |
|
35 // Dialog return code name and values |
|
36 _LIT( KUntrustedCertDialogResult, "result" ); // int |
|
37 const TInt KUntrustedCertDialogRejected = 0; |
|
38 const TInt KUntrustedCertDialogAccepted = 1; |
|
39 const TInt KUntrustedCertDialogAcceptedPermanently = 2; |
|
40 |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CUntrustedCertQuery::NewL() |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CUntrustedCertQuery* CUntrustedCertQuery::NewL( |
|
49 TValidationError aValidationError, const TDesC8& aCertificate, |
|
50 const TDesC& aServerName, TBool aCanHandlePermanentAccept ) |
|
51 { |
|
52 TRACE( "CUntrustedCertQuery::NewL" ); |
|
53 CUntrustedCertQuery* self = new ( ELeave ) CUntrustedCertQuery( |
|
54 aValidationError, aCertificate, aServerName, |
|
55 aCanHandlePermanentAccept ); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CUntrustedCertQuery::~CUntrustedCertQuery() |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CUntrustedCertQuery::~CUntrustedCertQuery() |
|
67 { |
|
68 TRACE( "CUntrustedCertQuery::~CUntrustedCertQuery, begin" ); |
|
69 Cancel(); |
|
70 delete iWait; |
|
71 iWait = NULL; |
|
72 delete iDeviceDialog; |
|
73 iDeviceDialog = NULL; |
|
74 delete iVariantMap; |
|
75 iVariantMap = NULL; |
|
76 TRACE( "CUntrustedCertQuery::~CUntrustedCertQuery, end" ); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CUntrustedCertQuery::ShowQueryAndWaitForResponseL() |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CUntrustedCertQuery::ShowQueryAndWaitForResponseL( TResponse& aResponse ) |
|
84 { |
|
85 TRACE( "CUntrustedCertQuery::ShowQueryAndWaitForResponseL, begin" ); |
|
86 if( !iDeviceDialog ) |
|
87 { |
|
88 iDeviceDialog = CHbDeviceDialogSymbian::NewL(); |
|
89 } |
|
90 if( !iVariantMap ) |
|
91 { |
|
92 iVariantMap = CHbSymbianVariantMap::NewL(); |
|
93 } |
|
94 |
|
95 CHbSymbianVariant *variant = NULL; |
|
96 variant = CHbSymbianVariant::NewL( &iCertificate, CHbSymbianVariant::EBinary ); |
|
97 User::LeaveIfError( iVariantMap->Add( KUntrustedCertEncodedCertificate, variant ) ); |
|
98 variant = CHbSymbianVariant::NewL( &iValidationError, CHbSymbianVariant::EInt ); |
|
99 User::LeaveIfError( iVariantMap->Add( KUntrustedCertValidationError, variant ) ); |
|
100 variant = CHbSymbianVariant::NewL( &iServerName, CHbSymbianVariant::EDes ); |
|
101 User::LeaveIfError( iVariantMap->Add( KUntrustedCertServerName, variant ) ); |
|
102 if( !iCanHandlePermanentAccept ) |
|
103 { |
|
104 variant = CHbSymbianVariant::NewL( &iCanHandlePermanentAccept, CHbSymbianVariant::EBool ); |
|
105 User::LeaveIfError( iVariantMap->Add( KUntrustedCertTrustedSiteStoreFail, variant ) ); |
|
106 } |
|
107 |
|
108 User::LeaveIfError( iDeviceDialog->Show( KUntrustedCertificateDialog, *iVariantMap, this ) ); |
|
109 iStatus = KRequestPending; |
|
110 SetActive(); |
|
111 |
|
112 TRACE( "CUntrustedCertQuery::ShowQueryAndWaitForResponseL, iWait start" ); |
|
113 iWait->Start(); |
|
114 TRACE( "CUntrustedCertQuery::ShowQueryAndWaitForResponseL, iWaitCompletionCode=%d", |
|
115 iWaitCompletionCode ); |
|
116 User::LeaveIfError( iWaitCompletionCode ); |
|
117 TRACE( "CUntrustedCertQuery::ShowQueryAndWaitForResponseL, iResponse=%d", iResponse ); |
|
118 aResponse = iResponse; |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CUntrustedCertQuery::DoCancel() |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CUntrustedCertQuery::DoCancel() |
|
126 { |
|
127 TRACE( "CUntrustedCertQuery::DoCancel, begin" ); |
|
128 if( iDeviceDialog ) |
|
129 { |
|
130 TRACE( "CUntrustedCertQuery::DoCancel, cancelling device dialog" ); |
|
131 iDeviceDialog->Cancel(); |
|
132 } |
|
133 |
|
134 // Have to complete the request here, because cancelled device dialog does not |
|
135 // call DeviceDialogClosed() that normally completes it. The request needs to |
|
136 // be completed since CActive::Cancel() waits until the request is completed. |
|
137 TRACE( "CUntrustedCertQuery::DoCancel, completing self with KErrCancel" ); |
|
138 TRequestStatus* status( &iStatus ); |
|
139 User::RequestComplete( status, KErrCancel ); |
|
140 |
|
141 // Normally the above request complete would trigger running RunL(). Now RunL() |
|
142 // is not run since the active object is already cancelled. Hence, have to stop |
|
143 // the waiting here so that iWait->Start() returns. |
|
144 iWaitCompletionCode = KErrCancel; |
|
145 if( iWait && iWait->IsStarted() ) |
|
146 { |
|
147 TRACE( "CUntrustedCertQuery::DoCancel, stopping iWait" ); |
|
148 iWait->AsyncStop(); |
|
149 } |
|
150 TRACE( "CUntrustedCertQuery::DoCancel, end" ); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CUntrustedCertQuery::RunL() |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CUntrustedCertQuery::RunL() |
|
158 { |
|
159 TRACE( "CUntrustedCertQuery::RunL, iStatus.Int()=%d", iStatus.Int() ); |
|
160 iWaitCompletionCode = iStatus.Int(); |
|
161 if( iWait && iWait->IsStarted() ) |
|
162 { |
|
163 TRACE( "CUntrustedCertQuery::RunL, stopping iWait" ); |
|
164 iWait->AsyncStop(); |
|
165 } |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CUntrustedCertQuery::DataReceived() |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CUntrustedCertQuery::DataReceived( CHbSymbianVariantMap& aData ) |
|
173 { |
|
174 TRACE( "CUntrustedCertQuery::DataReceived" ); |
|
175 const CHbSymbianVariant* variant = aData.Get( KUntrustedCertDialogResult ); |
|
176 if( variant ) |
|
177 { |
|
178 TInt* value = variant->Value<TInt>(); |
|
179 if( value ) |
|
180 { |
|
181 switch( *value ) |
|
182 { |
|
183 case KUntrustedCertDialogRejected: |
|
184 TRACE( "CUntrustedCertQuery::DataReceived, rejected" ); |
|
185 iResponse = EQueryRejected; |
|
186 break; |
|
187 case KUntrustedCertDialogAccepted: |
|
188 TRACE( "CUntrustedCertQuery::DataReceived, accepted" ); |
|
189 iResponse = EQueryAccepted; |
|
190 break; |
|
191 case KUntrustedCertDialogAcceptedPermanently: |
|
192 TRACE( "CUntrustedCertQuery::DataReceived, accepted permanently" ); |
|
193 iResponse = EQueryAcceptedPermanently; |
|
194 break; |
|
195 default: |
|
196 __ASSERT_DEBUG( EFalse, User::Invariant() ); |
|
197 break; |
|
198 } |
|
199 } |
|
200 else |
|
201 { |
|
202 __ASSERT_DEBUG( EFalse, User::Invariant() ); |
|
203 } |
|
204 } |
|
205 else |
|
206 { |
|
207 __ASSERT_DEBUG( EFalse, User::Invariant() ); |
|
208 } |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // CUntrustedCertQuery::DeviceDialogClosed() |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void CUntrustedCertQuery::DeviceDialogClosed( TInt aCompletionCode ) |
|
216 { |
|
217 TRACE( "CUntrustedCertQuery::DeviceDialogClosed, aCompletionCode=%d", aCompletionCode ); |
|
218 if( IsActive() ) |
|
219 { |
|
220 TRACE( "CUntrustedCertQuery::DeviceDialogClosed, request complete" ); |
|
221 TRequestStatus* status( &iStatus ); |
|
222 User::RequestComplete( status, aCompletionCode ); |
|
223 } |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CUntrustedCertQuery::CUntrustedCertQuery() |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 CUntrustedCertQuery::CUntrustedCertQuery( |
|
231 TValidationError aValidationError, const TDesC8& aCertificate, |
|
232 const TDesC& aServerName, TBool aCanHandlePermanentAccept ) : |
|
233 CActive( CActive::EPriorityStandard ), iValidationError( aValidationError ), |
|
234 iCertificate( aCertificate ), iServerName( aServerName ), |
|
235 iCanHandlePermanentAccept( aCanHandlePermanentAccept ), |
|
236 iResponse( EQueryRejected ) |
|
237 { |
|
238 CActiveScheduler::Add( this ); |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // CUntrustedCertQuery::ConstructL() |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 void CUntrustedCertQuery::ConstructL() |
|
246 { |
|
247 TRACE( "CUntrustedCertQuery::ConstructL" ); |
|
248 iWait = new( ELeave ) CActiveSchedulerWait; |
|
249 } |
|
250 |