23 #include "ui_sslinfo.h"
28 #include <QtGui/QFrame>
29 #include <QtCore/QDate>
30 #include <QtCore/QFile>
31 #include <QtGui/QLabel>
32 #include <QtGui/QLayout>
33 #include <QtCore/Q_PID>
34 #include <QtNetwork/QSslCertificate>
45 class KSslInfoDialog::KSslInfoDialogPrivate
51 bool isMainPartEncrypted;
52 bool auxPartsEncrypted;
63 d(new KSslInfoDialogPrivate)
65 setCaption(
i18n(
"KDE SSL Information"));
66 setAttribute(Qt::WA_DeleteOnClose);
68 d->ui.setupUi(mainWidget());
69 setButtons(KDialog::Close);
73 d->ui.certParties->addTab(d->subject,
i18nc(
"The receiver of the SSL certificate",
"Subject"));
74 d->ui.certParties->addTab(d->issuer,
i18nc(
"The authority that issued the SSL certificate",
"Issuer"));
76 d->isMainPartEncrypted =
true;
77 d->auxPartsEncrypted =
true;
78 updateWhichPartsEncrypted();
83 d->pixmap->setPixmap(
BarIcon(
"security-high"));
84 d->info->setText(
i18n(
"Current connection is secured with SSL."));
86 d->pixmap->setPixmap(
BarIcon(
"security-low"));
87 d->info->setText(
i18n(
"Current connection is not secured with SSL."));
90 d->pixmap->setPixmap(
BarIcon(
"security-low"));
91 d->info->setText(
i18n(
"SSL support is not available in this build of KDE."));
104 void KSslInfoDialog::launchConfig()
106 QProcess::startDetached(
"kcmshell4",
QStringList() <<
"crypto");
112 d->isMainPartEncrypted = mainEncrypted;
113 updateWhichPartsEncrypted();
119 d->auxPartsEncrypted = auxEncrypted;
120 updateWhichPartsEncrypted();
124 void KSslInfoDialog::updateWhichPartsEncrypted()
126 if (d->isMainPartEncrypted) {
127 if (d->auxPartsEncrypted) {
128 d->ui.encryptionIndicator->setPixmap(
BarIcon(
"security-high"));
129 d->ui.explanation->setText(
i18n(
"Current connection is secured with SSL."));
131 d->ui.encryptionIndicator->setPixmap(
BarIcon(
"security-medium"));
132 d->ui.explanation->setText(
i18n(
"The main part of this document is secured "
133 "with SSL, but some parts are not."));
136 if (d->auxPartsEncrypted) {
137 d->ui.encryptionIndicator->setPixmap(
BarIcon(
"security-medium"));
138 d->ui.explanation->setText(
i18n(
"Some of this document is secured with SSL, "
139 "but the main part is not."));
141 d->ui.encryptionIndicator->setPixmap(
BarIcon(
"security-low"));
142 d->ui.explanation->setText(
i18n(
"Current connection is not secured with SSL."));
151 int usedBits,
int bits,
154 d->certificateChain = certificateChain;
155 d->certificateErrors = validationErrors;
157 d->ui.certSelector->clear();
158 for (
int i = 0; i < certificateChain.size(); i++) {
159 const QSslCertificate &cert = certificateChain[i];
161 static const QSslCertificate::SubjectInfo
si[] = {
162 QSslCertificate::CommonName,
163 QSslCertificate::Organization,
164 QSslCertificate::OrganizationalUnitName
166 for (
int j = 0; j < 3 && name.isEmpty(); j++)
167 name = cert.subjectInfo(si[j]);
168 d->ui.certSelector->addItem(name);
170 if (certificateChain.size() < 2) {
171 d->ui.certSelector->setEnabled(
false);
173 connect(d->ui.certSelector, SIGNAL(currentIndexChanged(
int)),
174 this, SLOT(displayFromChain(
int)));
175 if (d->certificateChain.isEmpty())
176 d->certificateChain.append(QSslCertificate());
179 d->ui.ip->setText(ip);
180 d->ui.address->setText(host);
181 d->ui.sslVersion->setText(sslProtocol);
183 const QStringList cipherInfo = cipher.split(
'\n', QString::SkipEmptyParts);
184 if (cipherInfo.size() >= 4) {
185 d->ui.encryption->setText(
i18nc(
"%1, using %2 bits of a %3 bit key",
"%1, %2 %3", cipherInfo[0],
186 i18ncp(
"Part of: %1, using %2 bits of a %3 bit key",
187 "using %1 bit",
"using %1 bits", usedBits),
188 i18ncp(
"Part of: %1, using %2 bits of a %3 bit key",
189 "of a %1 bit key",
"of a %1 bit key", bits)));
190 d->ui.details->setText(
QString(
"Auth = %1, Kx = %2, MAC = %3")
191 .arg(cipherInfo[1], cipherInfo[2],
194 d->ui.encryption->setText(
"");
195 d->ui.details->setText(
"");
200 void KSslInfoDialog::displayFromChain(
int i)
202 const QSslCertificate &cert = d->certificateChain[i];
205 if (!d->certificateErrors[i].isEmpty()) {
206 trusted =
i18nc(
"The certificate is not trusted",
"NO, there were errors:");
209 trusted.append(
'\n');
210 trusted.append(classError.errorString());
213 trusted =
i18nc(
"The certificate is trusted",
"Yes");
215 d->ui.trusted->setText(trusted);
217 QString vp =
i18nc(
"%1 is the effective date of the certificate, %2 is the expiry date",
"%1 to %2",
220 d->ui.validityPeriod->setText(vp);
222 d->ui.serial->setText(cert.serialNumber());
223 d->ui.digest->setText(cert.digest().toHex());
224 d->ui.sha1Digest->setText(cert.digest(QCryptographicHash::Sha1).toHex());
234 QStringList sl = es.split(
'\n', QString::KeepEmptyParts);
236 foreach (
const QString &s, sl) {
238 QStringList sl2 = s.split(
'\t', QString::SkipEmptyParts);
239 foreach (
const QString &s2, sl2) {
243 certErrors.append(error);
246 ret.append(certErrors);
251 #include "ksslinfodialog.moc"
QString i18n(const char *text)
static QList< QList< KSslError::Error > > errorsFromString(const QString &s)
const char * name(StandardAction id)
QString i18nc(const char *ctxt, const char *text)
void setAuxiliaryPartsEncrypted(bool)
QString i18ncp(const char *ctxt, const char *sing, const char *plur, const A1 &a1)
KSslInfoDialog(QWidget *parent=0)
Construct a KSSL Information Dialog.
static const char si[8][64]
QString formatDateTime(const QDateTime &dateTime, DateFormat format=ShortDate, bool includeSecs=false) const
virtual ~KSslInfoDialog()
Destroy this dialog.
static bool doesSSLWork()
Determine if SSL is available and works.
QPixmap BarIcon(const QString &name, int force_size, int state, const QStringList &overlays)
void setMainPartEncrypted(bool)
void setSslInfo(const QList< QSslCertificate > &certificateChain, const QString &ip, const QString &host, const QString &sslProtocol, const QString &cipher, int usedBits, int bits, const QList< QList< KSslError::Error > > &validationErrors)
Set information to display about the SSL connection.