QWebview Ssl 双向认证
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
qtssl::qtssl(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); connect(ui.webView->page()->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(on_networkReply_sslErrors(QNetworkReply*, const QList<QSslError>&))); if (!QSslSocket::supportsSsl()) Q_ASSERT(!"no supportsSsl!!"); m_networkRequest.setUrl(QUrl("https://demo.ecaishen.com/")); ui.webView->load(m_networkRequest); } void qtssl::on_networkReply_sslErrors(QNetworkReply* reply, const QList<QSslError> &error) { foreach(QSslError e, error) { //Q_ASSERT(!"SslErrors"); QMessageLogger(__FILE__, __LINE__, 0).warning() << e.errorString(); } QSettings settings; QList<QSslCertificate> ca_merge = QSslCertificate::fromData(settings.value(QLatin1String("CaCertificates")).toByteArray()); QList<QSslCertificate> ca_new; QStringList errorStrings; for (int i = 0; i < error.count(); ++i) { if (ca_merge.contains(error.at(i).certificate())) continue; errorStrings += error.at(i).errorString(); if (!error.at(i).certificate().isNull()) { ca_new.append(error.at(i).certificate()); } } if (errorStrings.isEmpty()) { reply->ignoreSslErrors(); return; } QString errors = errorStrings.join(QLatin1String("</li><li>")); if (true) { if (ca_new.count() > 0) { QStringList certinfos; if (true) { ca_merge += ca_new; QSslConfiguration sslCfg = QSslConfiguration::defaultConfiguration(); QList<QSslCertificate> ca_list = sslCfg.caCertificates(); ca_list += ca_new; sslCfg.setCaCertificates(ca_list); sslCfg.setPeerVerifyMode(QSslSocket::VerifyNone); sslCfg.setProtocol(QSsl::TlsV1_1); //sslCfg.setProtocol(QSsl::AnyProtocol); QSslConfiguration::setDefaultConfiguration(sslCfg); reply->setSslConfiguration(sslCfg); QByteArray pems; for (int i = 0; i < ca_merge.count(); ++i) pems += ca_merge.at(i).toPem() + '\n'; settings.setValue(QLatin1String("CaCertificates"), pems); } } reply->ignoreSslErrors(); } } |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=1318