Set ssl configuration with certificates of QNetworkRequest does not work
-
Hello, I am using Qt 5.4.1 QtNetwork module. I want to trust a website with ssl certificate whose root CA is not in the list of system certificates of Mac OSX 10.10.3. But it seems to be not working at all, here is the code, does anyone has any idea or experience about it?
import sys
from PyQt4 import QtNetwork, QtCore, QtGui
from PyQt4.QtCore import QObject, QFile, QRegExp
from PyQt4.QtNetwork import QSslConfiguration, QSslCertificate, QSsl, QSslSocketappQt = QtGui.QApplication(sys.argv)
def sslErrorHandler(reply, errorList):
reply.ignoreSslErrors()
for errorItem in errorList:
print "ssl error ignored: %s" % errorItem.errorString()def slotReadyRead():
print 'slotReadyRead'
print reply.readAll()sslConfig = QSslConfiguration.defaultConfiguration()
sslConfig.setProtocol(QSsl.TlsV1SslV3)
sslConfig.setPeerVerifyDepth(1)
sslConfig.setPeerVerifyMode(QSslSocket.VerifyPeer)
qcerts = QSslCertificate.fromPath("/Users/rogerlai/Library/Application Support/FangCloudSync/cacert.pem", QSsl.Pem,
QRegExp.Wildcard)sslConfig.setCaCertificates(qcerts)
request = QtNetwork.QNetworkRequest(QtCore.QUrl("https://kyfw.12306.cn/otn/leftTicket/init"))
request.setSslConfiguration(sslConfig)manager = QtNetwork.QNetworkAccessManager()
QObject.connect(manager, QtCore.SIGNAL("sslErrors (QNetworkReply *, const QList<QSslError> &)"),
sslErrorHandler)reply = manager.get(request)
QObject.connect(reply, QtCore.SIGNAL("readyRead()"), slotReadyRead);
appQt.exec_()