本文整理汇总了C++中QSslSocket::setProtocol方法的典型用法代码示例。如果您正苦于以下问题:C++ QSslSocket::setProtocol方法的具体用法?C++ QSslSocket::setProtocol怎么用?C++ QSslSocket::setProtocol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSslSocket
的用法示例。
在下文中一共展示了QSslSocket::setProtocol方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slot_newIncommingConnection
void SshServer::slot_newIncommingConnection( int socketDescriptor )
{
QSslSocket* sslSocket = new QSslSocket();
// before the handshake, we need to adjust some security parameters for SSL
QSsl::SslProtocol sslProtocol;
if( "SSL-v3" == _sshServerSettings._version )
sslProtocol = QSsl::SslV3;
else if( "TLS-v1" == _sshServerSettings._version )
sslProtocol = QSsl::TlsV1;
else
{
logError( this, "no valid SSL version to use" );
delete sslSocket;
return;
}
QSsl::EncodingFormat ecodingFormat = ("PER"==_sshServerSettings._format) ? QSsl::Pem : QSsl::Der;
QSsl::KeyAlgorithm algorithm = ("RSA"==_sshServerSettings._cipher) ? QSsl::Rsa : QSsl::Dsa;
QByteArray password;
// setting the SSL version to use
sslSocket->setProtocol( sslProtocol );
// ensure that the peer's certificate will be verified
sslSocket->setPeerVerifyMode( QSslSocket::VerifyPeer );
// ensure that the peer's cerficiate and its issuer's certificate will be verified
sslSocket->setPeerVerifyDepth( 2 );
// setting server's certificate
sslSocket->setLocalCertificate( _sshServerSettings._certificate, ecodingFormat );
// setting server's private key
sslSocket->setPrivateKey( _sshServerSettings._privateKey, algorithm, ecodingFormat, password );
// setting the CA ceritificate
QList<QSslCertificate> caCertificates = QSslCertificate::fromPath( _sshServerSettings._certificate, ecodingFormat );
sslSocket->setDefaultCaCertificates( caCertificates );
// setup some traps for the socket events
connect( sslSocket, SIGNAL(disconnected()), sslSocket, SLOT(deleteLater()) );
connect( sslSocket, SIGNAL(encrypted()), SLOT(slot_SuccessfulConnected()) );
connect( sslSocket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(slot_UnSuccessfulConnected(const QList<QSslError>&)) );
connect( sslSocket, SIGNAL(readyRead()), this, SLOT(slot_IncommingData()) );
// start the handshake
bool result = sslSocket->setSocketDescriptor( socketDescriptor );
if( false == result )
{
logError( this, QString("failed to set socket descriptor: %1").arg(sslSocket->errorString()) );
delete sslSocket;
return;
}
sslSocket->startServerEncryption();
}
示例2: incomingConnection
/**
* Called when a new connection is available. The newConnection()
* signal is emitted when the connection is added to the pending
* connections queue
*
* @brief SslServer::incomingConnection
* @param socketDescriptor
*
* Ref: http://doc.qt.io/qt-5/qtcpserver.html#incomingConnection
*/
void SslServer::incomingConnection(qintptr socketDescriptor)
{
QSslSocket *mSslSocket = new QSslSocket(this);
if(mSslSocket->setSocketDescriptor(socketDescriptor))
{
mSslSocket->setProtocol(mProtocol);
mSslSocket->setLocalCertificate(mLocalCertificate);
mSslSocket->setPrivateKey(mPrivateKey);
this->addPendingConnection(mSslSocket);
}
else
{
delete mSslSocket;
qDebug() << "QSslSocket pointer deleted";
}
}
示例3: handleEndElement
void TLSFeature::handleEndElement(const QStringRef &name, const QStringRef &uri)
{
Q_UNUSED(uri);
if (name == QLatin1String("proceed")) {
DirectConnection *connection = qobject_cast<DirectConnection*>(m_client->connection());
Q_ASSERT(connection);
QSslSocket *socket = qobject_cast<QSslSocket*>(connection->socket());
Q_ASSERT(socket);
m_socket = socket;
socket->setProtocol(QSsl::TlsV1);
socket->setPeerVerifyMode(QSslSocket::VerifyNone);
connect(socket, SIGNAL(encrypted()), this, SLOT(onHandshaken()));
connect(socket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
connect(socket, SIGNAL(peerVerifyError(QSslError)), SLOT(onPeerVerifyError(QSslError)));
socket->startClientEncryption();
}
}
示例4: newConnectionPrivate
void SslServer::newConnectionPrivate(qintptr descriptor)
{
QSslSocket *socket = new QSslSocket(this);
socket->setSocketDescriptor(descriptor);
if (m_max_connections == 0)
{
socket->abort();
return;
}
socket->setProtocol(QSsl::TlsV1_2OrLater);
socket->addCaCertificate(m_cert);
socket->setLocalCertificate(m_cert);
socket->setPrivateKey(m_key);
//New connection done, set one less available connection
m_max_connections--;
QByteArray m_buffer;
qint32 size = 0;
m_socket_list.append(socket);
m_descriptor_hash.insert(socket, descriptor);
m_socket_hash.insert(descriptor, socket);
m_buffer_hash.insert(socket, m_buffer);
m_size_hash.insert(socket, size);
connect(socket, &QSslSocket::encrypted, this, &SslServer::encrypted);
connect(socket, &QSslSocket::disconnected, this, &SslServer::disconnectedPrivate);
connect(socket, static_cast<void(QSslSocket::*)(const QList<QSslError>&)>(&QSslSocket::sslErrors), this, &SslServer::sslErrors);
m_alive_hash[socket].start();
socket->startServerEncryption();
}
示例5: dossh
bool ssh::dossh()
{
#ifdef USE_QSSH
{
if(m_connection && m_connection->state() != QSsh::SshConnection::Unconnected)
{
helpers::log("ssh: already connecting...", LOG_INF, qApp, 0);
return true;
}
m_connection = new QSsh::SshConnection(params, this);
connect(m_connection, SIGNAL(connected()), SLOT(onQsshConnected()));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(onQsshConnectionError(QSsh::SshError)));
helpers::log("ssh: connecting START...", LOG_INF, qApp, 0);
m_connection->connectToHost();
return false;
}
#else
helpers::log("ssh: START: " + QString::number(QSslSocket::supportsSsl()), QSslSocket::supportsSsl() ? LOG_INF : LOG_ERR, qApp, 0);
//http://stackoverflow.com/questions/15213139/simple-qssl-client-server-cannot-start-handshake-on-non-plain-connection
QSslSocket *socket = new QSslSocket(this);
socket->ignoreSslErrors();
socket->setPeerVerifyMode(QSslSocket::VerifyNone);
socket->setProtocol(QSsl::SslV3);
connect(socket, SIGNAL(encrypted()), this, SLOT(ready()));
connect(socket, SIGNAL(encryptedBytesWritten(qint64)), this, SLOT(encryptedBytesWritten(qint64)));
connect(socket, SIGNAL(modeChanged(QSslSocket::SslMode)), this, SLOT(modeChanged(QSslSocket::SslMode)));
connect(socket, SIGNAL(peerVerifyError(const QSslError &)), this, SLOT(peerVerifyError(const QSslError &)));
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
connect(socket, SIGNAL(hostFound()), this, SLOT(hostFound()));
connect(socket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), this, SLOT(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)));
connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(stateChanged(QAbstractSocket::SocketState)));
connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
{
{
QFile file( "c:/Users/gherczeg/.ssh/id_boot2docker" );
if( ! file.open( QIODevice::ReadOnly ) )
{
QMessageBox::question(0, "Erreur", "Impossible de charger id_boot2docker");
return;
}
QSslKey key(&file);
file.close();
helpers::log("ssh:keyok: "+QString::number(!key.isNull()), !key.isNull() ? LOG_INF : LOG_ERR, qApp, 0);
socket->setPrivateKey( key );
}
foreach (const QSslCertificate &cert, QSslCertificate::fromPath("c:/Users/gherczeg/.boot2docker/certs/boot2docker-vm/*.pem", QSsl::Pem, QRegExp::Wildcard))
{
helpers::log("ssh:certok1: "+QString::number(!cert.isNull()), !cert.isNull() ? LOG_INF : LOG_ERR, qApp, 0);
socket->setLocalCertificate( cert );
socket->sslConfiguration().caCertificates().append(cert);
socket->addCaCertificate( cert );
socket->addDefaultCaCertificate(cert);
}
}
socket->connectToHostEncrypted("127.0.0.1", 2022);
//socket->connectToHost("127.0.0.1", 2022);
bool bok = socket->waitForEncrypted(100000);
//bool bok = socket->waitForConnected(100000);
if(!bok)
{
helpers::log("ssh:!waited:"+QString::number(bok),LOG_ERR, qApp, 0);
return;
}
helpers::log("ssh:waited4ecnrypt/connect:"+QString::number(bok),LOG_INF, qApp, 0);
socket->startClientEncryption();
bool wait4Read1 = socket->waitForReadyRead(100000);
helpers::log("ssh:wait4Read1:"+QString::number(wait4Read1),wait4Read1 ? LOG_INF : LOG_ERR, qApp, 0);
QString s = "docker: do!";
qint64 written = socket->write(s.toStdString().c_str());
helpers::log("ssh:written:"+QString::number(written),written > 0 ? LOG_INF : LOG_ERR, qApp, 0);
bool flushed = socket->flush();
helpers::log("ssh:flush:"+QString::number(flushed),flushed ? LOG_INF : LOG_ERR, qApp, 0);
bool wait4Write = socket->waitForBytesWritten(100000);
helpers::log("ssh:wait4Write:"+QString::number(wait4Write),wait4Write ? LOG_INF : LOG_ERR, qApp, 0);
bool wait4Read2 = socket->waitForReadyRead(100000);
helpers::log("ssh:wait4Read2:"+QString::number(wait4Read2),wait4Read2 ? LOG_INF : LOG_ERR, qApp, 0);
socket->disconnectFromHost();
#endif
}