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