KIO
sslui.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "sslui.h"
00022
00023 #include <kdebug.h>
00024 #include <klocalizedstring.h>
00025 #include <kmessagebox.h>
00026 #include <ksslcertificatemanager.h>
00027 #include <ksslinfodialog.h>
00028 #include <ktcpsocket_p.h>
00029
00030
00031 bool KIO::SslUi::askIgnoreSslErrors(const KTcpSocket *socket, RulesStorage storedRules)
00032 {
00033 KSslErrorUiData uiData(socket);
00034 return askIgnoreSslErrors(uiData, storedRules);
00035 }
00036
00037
00038 bool KIO::SslUi::askIgnoreSslErrors(const KSslErrorUiData &uiData, RulesStorage storedRules)
00039 {
00040 const KSslErrorUiData::Private *ud = KSslErrorUiData::Private::get(&uiData);
00041 if (ud->sslErrors.isEmpty()) {
00042 return true;
00043 }
00044
00045 QList<KSslError> fatalErrors = KSslCertificateManager::nonIgnorableErrors(ud->sslErrors);
00046 if (!fatalErrors.isEmpty()) {
00047
00048 return false;
00049 }
00050 if (ud->certificateChain.isEmpty()) {
00051
00052 KMessageBox::sorry(0, i18n("The remote host did not send any SSL certificates.\n"
00053 "Aborting because the identity of the host cannot be established."));
00054 return false;
00055 }
00056
00057 KSslCertificateManager *const cm = KSslCertificateManager::self();
00058 KSslCertificateRule rule(ud->certificateChain.first(), ud->host);
00059 if (storedRules & RecallRules) {
00060 rule = cm->rule(ud->certificateChain.first(), ud->host);
00061
00062 QList<KSslError> remainingErrors = rule.filterErrors(ud->sslErrors);
00063 if (remainingErrors.isEmpty()) {
00064 kDebug(7029) << "Error list empty after removing errors to be ignored. Continuing.";
00065 return true;
00066 }
00067 }
00068
00069
00070
00071 QString message = i18n("The server failed the authenticity check (%1).\n\n", ud->host);
00072 foreach (const KSslError &err, ud->sslErrors) {
00073 message.append(err.errorString());
00074 message.append('\n');
00075 }
00076 message = message.trimmed();
00077
00078 int msgResult;
00079 do {
00080 msgResult = KMessageBox::warningYesNoCancel(0, message, i18n("Server Authentication"),
00081 KGuiItem(i18n("&Details")),
00082 KGuiItem(i18n("Co&ntinue")));
00083 if (msgResult == KMessageBox::Yes) {
00084
00085
00086
00087 QList<QList<KSslError::Error> > meh;
00088
00089 foreach (const QSslCertificate &cert, ud->certificateChain) {
00090 QList<KSslError::Error> errors;
00091 foreach(const KSslError &error, ud->sslErrors) {
00092 if (error.certificate() == cert) {
00093
00094 errors.append(error.error());
00095 }
00096 }
00097 meh.append(errors);
00098 }
00099
00100
00101 KSslInfoDialog *dialog = new KSslInfoDialog();
00102 dialog->setSslInfo(ud->certificateChain, ud->ip, ud->host, ud->sslProtocol,
00103 ud->cipher, ud->usedBits, ud->bits, meh);
00104 dialog->exec();
00105 } else if (msgResult == KMessageBox::Cancel) {
00106 return false;
00107 }
00108
00109 } while (msgResult == KMessageBox::Yes);
00110
00111
00112 if (storedRules & StoreRules) {
00113
00114
00115 msgResult = KMessageBox::warningYesNo(0,
00116 i18n("Would you like to accept this "
00117 "certificate forever without "
00118 "being prompted?"),
00119 i18n("Server Authentication"),
00120 KGuiItem(i18n("&Forever")),
00121 KGuiItem(i18n("&Current Session only")));
00122 QDateTime ruleExpiry = QDateTime::currentDateTime();
00123 if (msgResult == KMessageBox::Yes) {
00124
00125 ruleExpiry = ruleExpiry.addYears(1000);
00126 } else {
00127
00128 ruleExpiry = ruleExpiry.addSecs(30*60);
00129 }
00130
00131
00132
00133
00134 rule.setExpiryDateTime(ruleExpiry);
00135 rule.setIgnoredErrors(ud->sslErrors);
00136 cm->setRule(rule);
00137 }
00138
00139 return true;
00140 }
00141