|
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: Device dialog plugin that shows untrusted certificate |
|
15 * dialog for TLS server authentication failure errors. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "untrustedcertificatewidget.h" |
|
20 #include "untrustedcertificatedefinitions.h" |
|
21 #include "untrustedcertificateinfobase.h" |
|
22 #include <hblabel.h> |
|
23 #include <hbcheckbox.h> |
|
24 #include <hbgroupbox.h> |
|
25 #include <hbtextedit.h> |
|
26 #include <QGraphicsLinearLayout> |
|
27 #include <QDebug> |
|
28 |
|
29 const int KUnknownError = -5; // KErrNotSupported |
|
30 |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // UntrustedCertificateWidget::UntrustedCertificateWidget() |
|
36 // ---------------------------------------------------------------------------- |
|
37 // |
|
38 UntrustedCertificateWidget::UntrustedCertificateWidget(QGraphicsItem *parent, |
|
39 Qt::WindowFlags flags) : HbWidget(parent, flags), |
|
40 mMainLayout(0), mProblemDescription(0), mAcceptPermanently(0), |
|
41 mCertificateDetailsGroupBox(0), mCertificateDetailsText(0), |
|
42 mCertificateInfo(0), mServerName(), mValidationError(0), |
|
43 mIsSavingServerNamePossible(true) |
|
44 { |
|
45 } |
|
46 |
|
47 // ---------------------------------------------------------------------------- |
|
48 // UntrustedCertificateWidget::~UntrustedCertificateWidget() |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 UntrustedCertificateWidget::~UntrustedCertificateWidget() |
|
52 { |
|
53 delete mCertificateInfo; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // UntrustedCertificateWidget::constructFromParameters() |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 void UntrustedCertificateWidget::constructFromParameters( |
|
61 const QVariantMap ¶meters) |
|
62 { |
|
63 processParameters(parameters); |
|
64 |
|
65 Q_ASSERT(mMainLayout == 0); |
|
66 mMainLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
67 |
|
68 Q_ASSERT(mProblemDescription == 0); |
|
69 QString text = descriptionText().arg(mServerName); |
|
70 mProblemDescription = new HbLabel(text); |
|
71 mProblemDescription->setTextWrapping(Hb::TextWordWrap); |
|
72 mMainLayout->addItem(mProblemDescription); |
|
73 |
|
74 if (isPermanentAcceptAllowed()) { |
|
75 Q_ASSERT(mAcceptPermanently == 0); |
|
76 // TODO: localised UI string needed |
|
77 mAcceptPermanently = new HbCheckBox(tr("Accept permanently")); |
|
78 mMainLayout->addItem(mAcceptPermanently); |
|
79 } |
|
80 |
|
81 Q_ASSERT(mCertificateDetailsGroupBox == 0); |
|
82 mCertificateDetailsGroupBox = new HbGroupBox; |
|
83 // TODO: localized UI string needed |
|
84 mCertificateDetailsGroupBox->setHeading(tr("Details")); |
|
85 |
|
86 Q_ASSERT(mCertificateDetailsText == 0); |
|
87 mCertificateDetailsText = new HbTextEdit; |
|
88 qDebug() << "fixing Certificatedialog.length() to 63"; |
|
89 QString certificateDetails = mCertificateInfo->certificateDetails(mServerName).left(63); |
|
90 mCertificateDetailsText->setPlainText(certificateDetails); |
|
91 mCertificateDetailsText->setReadOnly(true); |
|
92 |
|
93 mCertificateDetailsGroupBox->setContentWidget(mCertificateDetailsText); |
|
94 mCertificateDetailsGroupBox->setCollapsed(true); |
|
95 mMainLayout->addItem(mCertificateDetailsGroupBox); |
|
96 |
|
97 setLayout(mMainLayout); |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // UntrustedCertificateWidget::updateFromParameters() |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 void UntrustedCertificateWidget::updateFromParameters( |
|
105 const QVariantMap ¶meters) |
|
106 { |
|
107 processParameters(parameters); |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // UntrustedCertificateWidget::isPermanentAcceptAllowed() |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 bool UntrustedCertificateWidget::isPermanentAcceptAllowed() const |
|
115 { |
|
116 return (mCertificateInfo->isDateValid() && (mServerName.length() > 0) && |
|
117 mIsSavingServerNamePossible); |
|
118 } |
|
119 |
|
120 // ---------------------------------------------------------------------------- |
|
121 // UntrustedCertificateWidget::isPermanentAcceptChecked() |
|
122 // ---------------------------------------------------------------------------- |
|
123 // |
|
124 bool UntrustedCertificateWidget::isPermanentAcceptChecked() const |
|
125 { |
|
126 if (mAcceptPermanently) { |
|
127 return (mAcceptPermanently->checkState() == Qt::Checked); |
|
128 } |
|
129 return false; |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // UntrustedCertificateWidget::serverName() |
|
134 // ---------------------------------------------------------------------------- |
|
135 // |
|
136 QString UntrustedCertificateWidget::serverName() const |
|
137 { |
|
138 return mServerName; |
|
139 } |
|
140 |
|
141 // ---------------------------------------------------------------------------- |
|
142 // UntrustedCertificateWidget::processParameters() |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 void UntrustedCertificateWidget::processParameters(const QVariantMap ¶meters) |
|
146 { |
|
147 mServerName = parameters.value(KUntrustedCertServerName).toString(); |
|
148 |
|
149 bool ok = false; |
|
150 mValidationError = KUnknownError; |
|
151 int value = parameters.value(KUntrustedCertValidationError).toInt(&ok); |
|
152 if (ok) { |
|
153 mValidationError = value; |
|
154 } |
|
155 |
|
156 QByteArray encodedCert = parameters.value(KUntrustedCertEncodedCertificate).toByteArray(); |
|
157 processEncodedCertificate(encodedCert); |
|
158 |
|
159 if (parameters.contains(KUntrustedCertTrustedSiteStoreFail)) { |
|
160 mIsSavingServerNamePossible = false; |
|
161 } |
|
162 } |
|
163 |