gpt4 book ai didi

Qt 5.8 Apple 通知服务器握手失败

转载 作者:太空宇宙 更新时间:2023-11-03 13:34:21 25 4
gpt4 key购买 nike

我现在尝试了一些我们的,但我无法让它工作。我想从 Qt 应用程序推送一些通知。试图让它在安装了 Qt 5.8 的 macOS Sierra 上工作,并在安装了 Qt 5.8 的 Pi3 上工作。

我使用“faSTLane pem”创建了我的推送证书,并使用“Pusher”对其进行了测试,它工作正常。但我无法让它在 Qt 中工作....

首先是我用来初始化和连接QSslSocket的代码:

QSslSocket * ssl = new QSslSocket;

connect(ssl, &QSslSocket::encrypted, this, &IOSPusher::encrypted );
connect(ssl, static_cast<void(QSslSocket::*)(const QList<QSslError> &)>(&QSslSocket::sslErrors),this,&IOSPusher::sslErrors);
connect(ssl, static_cast<void(QSslSocket::*)(QAbstractSocket::SocketError)>(&QSslSocket::error),this, &IOSPusher::error );
connect(ssl,&QSslSocket::stateChanged,this,&IOSPusher::stateChanged );

加载证书

QString path = QStandardPaths::writableLocation(certificateLocation) + "/apns.pem";

const auto certs = QSslCertificate::fromPath(path);

if(certs.count() > 0){
qDebug() << "IOSPusher: Certificate loaded successfully";
}else{
qDebug() << "Could not load certificate : " + path;
}

QSslConfiguration config = QSslConfiguration::defaultConfiguration();
config.setCaCertificates(certs);

ssl->setSslConfiguration(config);
ssl->connectToHostEncrypted( gateway.sandbox.push.apple.com,2195 );

这就是我得到的输出:

IOSPusher: Certificate loaded successfully
IOSPusher::stateChanged QAbstractSocket::HostLookupState
IOSPusher::stateChanged QAbstractSocket::ConnectingState
IOSPusher::stateChanged QAbstractSocket::ConnectedState
IOSPusher::error QAbstractSocket::SocketError(13)
IOSPusher::stateChanged QAbstractSocket::ClosingState
IOSPusher::stateChanged QAbstractSocket::UnconnectedState

所以根据 Qt 文档错误:

QAbstractSocket::SocketError(13)

含义如下:

SslHandshakeFailedError

> SSL/TLS 握手失败,无法建立加密 channel 。 sslErrors() 信号应该已经发出。

但是 sslErrors() 信号在我的例子中不会被发射....

The SSL/TLS handshake failed, so the connection was closed (only used in QSslSocket)

关于如何与 Apple 建立加密连接的任何想法或示例?

提前致谢!

最佳答案

好吧,当我试图从任何人那里得到帮助时,我经常这样 :D

现在对我有用的解决方案是:

使用带密码的faSTLane pem 创建*.pem 证书(也许它也可以在没有密码的情况下工作,但那是我现在尝试的最后一次......从来没有换个运行系统哈哈)

 fastlane pem --development -p <private_key_password> -a <your_app_identifier>

然后连接 QSslSocket 执行以下操作...就像我之前的问题一样...

QSslSocket * ssl = new QSslSocket;
QString path = QStandardPaths::writableLocation(certificateLocation) + "/apns.pem";

connect(ssl, &QSslSocket::encrypted, this, &IOSPusher::encrypted );
connect(ssl, static_cast<void(QSslSocket::*)(const QList<QSslError> &)>(&QSslSocket::sslErrors),this,&IOSPusher::sslErrors);
connect(ssl, static_cast<void(QSslSocket::*)(QAbstractSocket::SocketError)>(&QSslSocket::error),this, &IOSPusher::error );
connect(ssl,&QSslSocket::stateChanged,this,&IOSPusher::stateChanged );

QSslCertificate cert;
const auto certs = QSslCertificate::fromPath(path);

if(certs.count() > 0){
cert = certs.at(0);
qDebug() << "IOSPusher: Certificate loaded successfully";
}else{
qDebug() << "Could not load certificate : " + path;
return false;
}

现在它为我带来的魔力来了

使用也将使用 faSTLane pem 创建的 private_key (.pkey) 文件

//Use the path to the .pkey file from fastlane
QFile keyfile(path + "/apns.pkey");
keyfile.open(QFile::ReadOnly);

//Create the QSslKey as private key
QSslKey privateKey(&keyfile,QSsl::Rsa,QSsl::Pem,QSsl::PrivateKey,QByteArray("<private_key_password_from_fastlane>"));
//Close the file
keyfile.close();

并将私钥和证书添加到ssl配置

QSslConfiguration config = QSslConfiguration::defaultConfiguration();

config.setLocalCertificate(cert);
config.setPrivateKey(privateKey);

如您所见,这次我没有使用 config.setCaCertificates 方法,而是使用了 config.setLocalCertificate 方法。这是我的错误...

至少将配置添加到 ssl 套接字并启动!

ssl->setSslConfiguration(config);
ssl->connectToHostEncrypted( "gateway.sandbox.push.apple.com",2195 );

就这些

现在 encrypted() 信号被发射了!是的..

关于Qt 5.8 Apple 通知服务器握手失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44839572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com