Qt 5.8 Apple 通知服务器握手失败
Qt 5.8 Apple Notification Server Handshake failed
我现在尝试了一些我们的,但我无法让它工作。我想从 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 握手失败,无法建立加密通道。 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;
}
现在神奇的事情来了
使用 private_key (.pkey) 文件,该文件也将由 fastlane pem
创建
//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 应用程序推送一些通知。试图让它在安装了 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 握手失败,无法建立加密通道。 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;
}
现在神奇的事情来了
使用 private_key (.pkey) 文件,该文件也将由 fastlane pem
//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()
信号发出了!是的..