How to implement a ftp over tls client by qsslsocket?

283 Views Asked by At

In FTPS, the client connect to the server, the server sending a welcome message; thus, then client send command "AUTH TLS",the server set Certificate态PrivateKey and startServerEncryption; what should the client do to finish this ssl handshake?

Server:

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;
    }
}

client

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

I wish the client finish the ssl shakehand by using startClientEncryption, and then I can use the client socket to send command or file; but it does not work; I know the client socket and the server socket already connect, but how to add ssl on this?

0

There are 0 best solutions below