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


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

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


在下文中一共展示了QSslSocket::setPrivateKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: incomingConnection

void HTTPSManager::incomingConnection(qintptr socketDescriptor) {
    QSslSocket* sslSocket = new QSslSocket(this);

    sslSocket->setLocalCertificate(_certificate);
    sslSocket->setPrivateKey(_privateKey);

    if (sslSocket->setSocketDescriptor(socketDescriptor)) {
        new HTTPSConnection(sslSocket, this);
    } else {
        delete sslSocket;
    }
}
开发者ID:jsundman,项目名称:hifi,代码行数:12,代码来源:HTTPSManager.cpp

示例2: incomingConnection

void QTlsServer::incomingConnection(int socketDescriptor)
{
	QSslSocket* serverSocket = new QSslSocket;
	QObject::connect(serverSocket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(displayTlsErrors(const QList<QSslError>&)));

	if (serverSocket->setSocketDescriptor(socketDescriptor))
	{
		QFile file("server-key.pem");
		if (!file.open(QIODevice::ReadOnly))
		{
			std::cout << "can't open key" << "server-key.pem";
			return;
		}
		QSslKey key(&file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, QByteArray("qtwebsocket-server-key"));
		file.close();
		serverSocket->setPrivateKey(key);

		if (!serverSocket->addCaCertificates("ca.pem"))
		{
			std::cout << "open certificate ca error" << "ca.pem";
			return;
		}
		
		serverSocket->setLocalCertificate("server-crt.pem");
		serverSocket->setPeerVerifyMode(QSslSocket::VerifyNone);
		//serverSocket->ignoreSslErrors();

		QObject::connect(serverSocket, SIGNAL(encrypted()), this, SLOT(tlsSocketEncrypted()));
		serverSocket->startServerEncryption();
	}
	else
	{
		serverSocket->deleteLater();
	}
}
开发者ID:gvsurenderreddy,项目名称:Canyon,代码行数:35,代码来源:QTlsServer.cpp

示例3: acceptConnection

// Accept connection from server and initiate the SSL handshake
void Server::acceptConnection()
{
	if (sockets.empty() == false)
		std::cout << "Server is mad efor 1 connection also. Need to update to handle multiple connections" << std::endl;

  QSslSocket *socket = dynamic_cast<QSslSocket *>(server.nextPendingConnection());
  assert(socket);


  // Report any SSL errors that occur
  connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));

  connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionFailure()));

  
  // QSslSocket emits the encrypted() signal after the encrypted connection is established
#define _USE_ENCRYPTION
#ifdef _USE_ENCRYPTION
  connect(socket, SIGNAL(encrypted()), this, SLOT(handshakeComplete()));
  socket->setPrivateKey(key);
  socket->setLocalCertificate(certificate);

  socket->setPeerVerifyMode(QSslSocket::VerifyNone);
  socket->startServerEncryption();
#else
  connect(socket, SIGNAL(disconnected()), this, SLOT(connectionClosed()));
  connect(socket, SIGNAL(readyRead()), this, SLOT(receiveMessage()));
  sockets.push_back(socket);
  std::cout << "Accepted connection from " << socket->peerAddress().toString().toStdString() << ":" << socket->peerPort() << " .Encrypted : " << socket->isEncrypted() << std::endl;
#endif
}
开发者ID:Tudi,项目名称:TempStorage,代码行数:32,代码来源:server.cpp

示例4: QSslSocket

QTcpSocket *Nuria::Internal::TcpServer::handleToSocket (qintptr handle) {
	if (!this->m_ssl) {
		QTcpSocket *socket = new QTcpSocket;
		socket->setSocketDescriptor (handle);
		return socket;
	}
	
	// SSL
#ifndef NURIA_NO_SSL_HTTP
	QSslSocket *socket = new QSslSocket (this);
	
	// Certificate and private key
	socket->setPrivateKey (this->m_key);
	socket->setLocalCertificate (this->m_cert);
	
	// Set handle
	if (!socket->setSocketDescriptor (handle)) {
		delete socket;
		return nullptr;
	}
	
	// 
	socket->startServerEncryption ();
	return socket;
#else	
	return nullptr;
#endif
	
}
开发者ID:NuriaProject,项目名称:Network,代码行数:29,代码来源:tcpserver.cpp

示例5: 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,代码来源:

示例6: incomingConnection

void SslServer::incomingConnection(qintptr handle)
{
	QSslSocket *socket = new QSslSocket(this);
	socket->setSocketDescriptor(handle);
	socket->setLocalCertificate(_cert);
	socket->setPrivateKey(_key);

	addPendingConnection(socket);
}
开发者ID:GreenReaper,项目名称:Drawpile,代码行数:9,代码来源:sslserver.cpp

示例7: operator

QAbstractSocket* SslSocketCreation::operator()() const {
	QSslSocket* socket = new QSslSocket();
	socket->setSocketDescriptor(socketDescriptor);

	socket->setLocalCertificate(certificate);
	socket->setPrivateKey(privateKey);

	socket->startServerEncryption();

	return socket;
}
开发者ID:todbot,项目名称:tasteful-server,代码行数:11,代码来源:SocketCreation.cpp

示例8: QSslSocket

QAbstractSocket * HttpsSocket::createSocket(qintptr socketDescriptor)
{
    QSslSocket * socket = new QSslSocket();

    socket->setSocketDescriptor(socketDescriptor);

    socket->setLocalCertificate(m_certificate);
    socket->setPrivateKey(m_privateKey);

    socket->startServerEncryption();

    return socket;
}
开发者ID:scheibel,项目名称:tastefulserver,代码行数:13,代码来源:HttpsSocket.cpp

示例9: incomingConnection

QIODevice* QxtSslConnectionManager::incomingConnection(int socketDescriptor)
#endif
{
    QSslSocket* socket = new QSslSocket(this);
    if(socket->setSocketDescriptor(socketDescriptor)) {
        socket->setLocalCertificate(qxt_d().localCertificate());
        socket->setPrivateKey(qxt_d().privateKey());
        if(qxt_d().autoEncrypt()) socket->startServerEncryption();
        return socket;
    } else {
        delete socket;
        return 0;
    }
}
开发者ID:develnk,项目名称:qxtweb-qt5,代码行数:14,代码来源:qxtsslconnectionmanager.cpp

示例10: 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";
    }
}
开发者ID:ecobos,项目名称:volunteer-relay,代码行数:26,代码来源:SslServer.cpp

示例11: incomingConnection

void SslServer::incomingConnection(int socketDescriptor)
{
    QSslSocket *serverSocket = new QSslSocket(this);
    if (serverSocket->setSocketDescriptor(socketDescriptor)) {
        if (isCertValid()) {
            serverSocket->setLocalCertificate(_cert);
            serverSocket->setPrivateKey(_key);
            serverSocket->addCaCertificates(_ca);
        }
        _pendingConnections << serverSocket;
        emit newConnection();
    }
    else {
        delete serverSocket;
    }
}
开发者ID:2kah,项目名称:quassel,代码行数:16,代码来源:sslserver.cpp

示例12: acceptConnection

// Accept connection from server and initiate the SSL handshake
void Server::acceptConnection()
{
  QSslSocket *socket = server.nextPendingConnection();
  assert(socket);

  // QSslSocket emits the encrypted() signal after the encrypted connection is established
  connect(socket, SIGNAL(encrypted()), this, SLOT(handshakeComplete()));

  // Report any SSL errors that occur
  connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));

  connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionFailure()));

  socket->setPrivateKey(key);
  socket->setLocalCertificate(certificate);

  socket->setPeerVerifyMode(QSslSocket::VerifyNone);
  socket->startServerEncryption();
}
开发者ID:andrewly,项目名称:3574_HW7,代码行数:20,代码来源:server.cpp

示例13: incomingConnection

void QxtSslServer::incomingConnection(int socketDescriptor)
#endif
{
    QSslSocket* socket = new QSslSocket(this);
    if(socket->setSocketDescriptor(socketDescriptor)) {
        socket->setLocalCertificate(qxt_d().localCertificate);
        socket->setPrivateKey(qxt_d().privateKey);
        if(parent()){
            connect(socket, SIGNAL(sslErrors(const QList<QSslError>&)),
                    parent(), SLOT(sslErrors(const QList<QSslError>&)));
            connect(socket, SIGNAL(peerVerifyError(const QSslError&)),
                    parent(), SLOT(peerVerifyError(const QSslError&)));
        }
        qxt_d().pendingConnections.enqueue(socket);
        // emit newConnection(); // removed: QTcpServerPrivate emits this for us
        if(qxt_d().autoEncrypt) socket->startServerEncryption();
    } else {
        delete socket;
    }
}
开发者ID:mmitkevich,项目名称:libqxt,代码行数:20,代码来源:qxtsslserver.cpp

示例14: incomingConnection

void HttpsServer::incomingConnection(qintptr socketDescriptor)
#endif
{
    QSslSocket* sslSocket = new QSslSocket(this);
    if (sslSocket->setSocketDescriptor(socketDescriptor))
    {
        sslSocket->setPrivateKey(privateKey());
        sslSocket->setLocalCertificate(certificate());
        sslSocket->startServerEncryption();
        connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslSocket_sslErrors(QList<QSslError>)));
        connect(sslSocket, SIGNAL(encrypted()), this, SLOT(sslSocket_encrypted()));
        addPendingConnection(sslSocket);
        nextPendingConnection();
        createHttpConnection()->initialize(sslSocket, sslSocket);
    }
    else
    {
        qWarning() << "HttpsServer::incomingConnection: failed to set socket descriptor '" << socketDescriptor << "' on ssl socket.";
        delete sslSocket;
    }
}
开发者ID:acossette,项目名称:pillow,代码行数:21,代码来源:HttpsServer.cpp

示例15: 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();
}
开发者ID:antonypro,项目名称:AudioStreaming,代码行数:37,代码来源:sslserver.cpp


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