为什么我不能获得用户正在使用的证书的正确信息?
Why can not I get the right information about the certificate, which is used by the user?
这是两个完全不同的网站。他们有两个不同的ssl证书。下面描述的程序充当服务器。客户端是浏览器。当我访问为我的https服务器服务的不同站点时,我总是得到一个哈希值。
#include <QCoreApplication>
#include "server.h"
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
Server h;
return a.exec();
}
///////////////////////////////////////
#ifndef SERVER_H
#define SERVER_H
#include <QTcpServer>
class Server : public QTcpServer {
public:
Server();
void incomingConnection(int);
};
#endif // SERVER_H
///////////////////////////////////////////
#include "server.h"
#include <QSslSocket>
#include <QSslCertificate>
Server::Server() {
if (!listen(QHostAddress::Any, 80)) {
//error
}
}
void Server::incomingConnection(int d) {
QSslSocket * socket = new QSslSocket();
if(socket->setSocketDescriptor(d)) {
socket->setProtocol(QSsl::AnyProtocol);
//always one hash. why?
qDebug() << socket->peerCertificate().digest(QCryptographicHash::Sha1).toHex();
QString c, k;
c = "site.crt";
k = "site.key";
socket->setLocalCertificate(c);
socket->setPrivateKey(k);
socket->startServerEncryption();
if(socket->waitForEncrypted()) {
if(socket->waitForReadyRead()) {
socket->write(socket->readAll());
socket->waitForBytesWritten();
socket->disconnectFromHost();
if(socket->state() == QTcpSocket::UnconnectedState) {
socket->waitForDisconnected();
}
socket->close();
socket->deleteLater();
}
else {
delete socket;
}
}
else {
delete socket;
}
}
}
来自Qt文档:
因为对端证书是在握手阶段设置的,所以是从连接的插槽安全访问对端证书sslErrors()信号或encrypted()信号
如果返回一个空证书,它可能意味着SSL握手失败,也可能意味着您所连接的主机没有证书,或者表示没有连接。
因此,您应该在本地插槽接收到QSslSocket::加密信号后尝试获取客户端证书。
你还应该注意,如果你的客户端没有证书,那么peerCertificate()将返回一个空值
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- "unknown ca"自生成的 CA、证书和客户端/服务器
- 如何设置一个范围来提取我想要获得的信息
- 如何在C++中使用X509证书模在令牌中查找私钥
- OpenSSL TLS服务器-使用客户端证书白名单
- 系统参数信息A 与 SPI_GETMOUSE 返回 0
- 为什么 gcovr 会生成空覆盖率统计信息?
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 使用 OpenSSL 从内存中读取原始 SSL/TLS 证书
- CertGetCertificateChain 具有支持的内存存储和证书信任列表
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- 调试符号中缺少 QObject 类信息(编辑但存在其他 Qt 类)
- 为什么数组大小信息可用于"sizeof"运算符和 delete[] 运算符,但在将数组作为参数传递到
- Pisarze - 来自波兰奥林匹克信息学的数据分析任务
- C MACOS-编程检索代码符号证书信息
- 如何在CryptoAPI中通过证书公钥获取密钥容器的信息
- 为什么我不能获得用户正在使用的证书的正确信息?
- 如何获取有关客户端证书的信息