当前位置: 首页>>代码示例>>C++>>正文


C++ QSslSocket::setPeerVerifyDepth方法代码示例

本文整理汇总了C++中QSslSocket::setPeerVerifyDepth方法的典型用法代码示例。如果您正苦于以下问题:C++ QSslSocket::setPeerVerifyDepth方法的具体用法?C++ QSslSocket::setPeerVerifyDepth怎么用?C++ QSslSocket::setPeerVerifyDepth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSslSocket的用法示例。


在下文中一共展示了QSslSocket::setPeerVerifyDepth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
开发者ID:,项目名称:,代码行数:58,代码来源:


注:本文中的QSslSocket::setPeerVerifyDepth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。