如何通过q​​sslsocket在tls客户端上实现ftp?

时间:2019-03-27 16:37:53

标签: qt ssl ftps qsslsocket

在FTPS中,客户端连接到服务器,服务器发送欢迎消息;这样,客户端发送命令“ AUTH TLS”,服务器设置证书,私钥和startServerEncryption。客户应该怎么做才能完成此ssl握手?

服务器:

if ("AUTH" == command && "TLS" == commandParameters.toUpper())
{
        auth();
}

void FtpControlConnection::auth()
{
    reply("234 Initializing SSL connection.");
    SslServer::setLocalCertificateAndPrivateKey(socket);
    socket->startServerEncryption();
}

void SslServer::setLocalCertificateAndPrivateKey(QSslSocket *socket)
{
    socket->setPrivateKey(":/ssl/server.key", QSsl::Rsa, QSsl::Pem, "1234");
    Q_ASSERT(!socket->privateKey().isNull());
    socket->setLocalCertificate(":/ssl/server.crt");
    Q_ASSERT(!socket->localCertificate().isNull());
}

void SslServer::incomingConnection(PortableSocketDescriptorType socketDescriptor)
{
    QSslSocket *socket = new QSslSocket(this);
    if (socket->setSocketDescriptor(socketDescriptor)) {
        addPendingConnection(socket);
    } else {
        delete socket;
    }
}

客户端

socket->connectToHost(hostNameEdit->text(), portBox->value());
socket->write("AUTH TLS\r\n");
socket->waitForConnected();
socket->startClientEncryption();
socket->waitForEncrypted();

我希望客户端使用startClientEncryption完成ssl握手,然后我可以使用客户端套接字发送命令或文件;但它不起作用;我知道客户端套接字和服务器套接字已经连接,但是如何在此添加ssl?

0 个答案:

没有答案