When making an HTTPS request using Qt, I try to obtain a peer certificate after establishing an SSL connection to track future certificate changes.
QNetworkAccessManager nam;
nam.get(QNetworkRequest(QUrl("https://google.com/")));
QObject::connect(&nam, &QNetworkAccessManager::encrypted, [](QNetworkReply *reply){
qDebug() << reply->sslConfiguration().peerCertificate();
});
According to the documentationQNetworkAccessManager::encrypted , the above code should gain access to the server certificate:
This signal is emitted when the SSL / TLS session has successfully completed the initial handshake. No user data has been transferred at this time. The signal can be used to perform additional checks on the certificate chain, for example, to notify users that a certificate for a website has changed. If the response does not meet the expected criteria, it should be interrupted by calling QNetworkReply :: abort () by the slot connected to this signal. The SSL configuration used can be verified using the QNetworkReply :: sslConfiguration () method.
In addition, from the documentationQSslConfiguration::peerCertificate() :
Since the peer certificate is installed at the confirmation stage, it is safe to access the peer certificate from the slot connected to the QSslSocket :: sslErrors (), QNetworkReply :: sslErrors (), or QSslSocket :: encrypted () signals.
. ( ):
QSslCertificate( "" , "" , "1B2M2Y8AsgTpgAmY7PhCfg==" , () , () , QMap() , QDateTime(" Qt::LocalTime") , QDateTime(" Qt::LocalTime") )
, SSL, sslErrors, . , Ubuntu/Apache, Qt - , "https://localhost" :
QSslCertificate( "3" , "95:b0:93:f2:16:bb:22:cb" , "cXB6WctE7oZsrvZLU2BWUw==" , () , () , QMap() , QDateTime("2014-07-10 23:04:06.000 UTC Qt::UTC") , QDateTime("2024-07-07 23:04:06.000 UTC Qt::UTC") )
, SSL ?
QNetworkAccessManager, QNetworkReply; .
MCVE https://bitbucket.org/leemes/ssltest, :
git clone https://bitbucket.org/leemes/ssltest.git
Qt 5.4.0 Qt 5.3.1; .