QNetworkRequest 和默认 SSL 配置
我使用以下代码向服务器发出 HTTPS 请求。
QNetworkRequest request;
//request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
request.setUrl(QUrl("https://www.someurl.com/"));
QNetworkReply *reply = manager->get(request);
一切似乎都适用于我的测试服务器,但我想知道是否建议设置defaultConfiguration(取消注释第二行),或者网络API在使用SSL时是否自动检查所有defaultConfiguration?如果它检查了,如果我添加一个自定义配置它也可以吗?我的意思是,是否需要将自定义配置附加到默认配置列表中?例如:
QSslConfiguration SslConfiguration(QSslConfiguration::defaultConfiguration());
QList<QSslCertificate> certificates = SslConfiguration.caCertificates();
certificates.append(QSslCertificate::fromData(certificate.toAscii(), QSsl::Pem));
SslConfiguration.setCaCertificates(certificates);
request.setSslConfiguration(SslConfiguration);
编辑:我想补充一点,我正在 Symbian 平台上工作。
I'm using the following piece of code to make HTTPS requests with a server.
QNetworkRequest request;
//request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
request.setUrl(QUrl("https://www.someurl.com/"));
QNetworkReply *reply = manager->get(request);
Everything seems to be working with my test server, but I would like to know if it is recommended to set the defaultConfiguration (uncomment second line) or does the network API automatically check all defaultConfigurations when using SSL? And if it checks, does it also do if I add one custom configuration? I mean, is it required to append the custom configuration to the list of default configuration? For example:
QSslConfiguration SslConfiguration(QSslConfiguration::defaultConfiguration());
QList<QSslCertificate> certificates = SslConfiguration.caCertificates();
certificates.append(QSslCertificate::fromData(certificate.toAscii(), QSsl::Pem));
SslConfiguration.setCaCertificates(certificates);
request.setSslConfiguration(SslConfiguration);
Edit: I would like to add that I'm working on Symbian platform.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自
的文档
void QNetworkRequest::setSslConfiguration ( const QSslConfiguration & config )
:您可以使用以下代码验证此声明:
但是,您似乎将根 CA 证书存储与 SSL 配置混淆了。前者只是后者的一部分(参见
QListQSslConfiguration ::caCertificates () const
)。如果您想确保 QNAM 使用您的根 CA 证书,您可以利用 QNAM 使用 QSslSocket 建立 SSL 连接,并使用以下任一静态方法设置根 CA 证书,供使用 QSslSocket 建立的所有 SSL 连接使用。请记住,这是全局设置,会影响使用 QSslSocket 建立的所有 SSL 连接而不仅仅是使用 QNAM 建立的连接。没有 API 可以仅针对特定 QNAM 或所有 QNAM 设置此项。
From documentation of
void QNetworkRequest::setSslConfiguration ( const QSslConfiguration & config )
:You can verify this statement using the following code:
However, you seem to confuse root CA certificates store with SSL configuration. The former is only one part of the latter (see
QList<QSslCertificate> QSslConfiguration::caCertificates () const
). If you want to make sure your root CA certificates will be used by QNAM you can take advantage of the fact that QNAM uses QSslSocket to make SSL connections and use any of the following static methodsto set root CA certificates to be used by all SSL connections made using QSslSocket. Remember, this is global setting and affects all SSL connections made using QSslSocket not only these made using QNAM. There's no API to set this only for specific QNAM or for all QNAMs.