void WalletSerializer::loadWalletV1(Common::IInputStream& source, const std::string& password) { CryptoNote::CryptoContext cryptoContext; CryptoNote::BinaryInputStreamSerializer encrypted(source); encrypted(cryptoContext.iv, "iv"); generateKey(password, cryptoContext.key); std::string cipher; encrypted(cipher, "data"); std::string plain = decrypt(cipher, cryptoContext); MemoryInputStream decryptedStream(plain.data(), plain.size()); CryptoNote::BinaryInputStreamSerializer serializer(decryptedStream); loadWalletV1Keys(serializer); checkKeys(); subscribeWallets(); bool detailsSaved; serializer(detailsSaved, "has_details"); if (detailsSaved) { loadWalletV1Details(serializer); } }
void LanLinkProvider::sslErrors(const QList<QSslError>& errors) { QSslSocket* socket = qobject_cast<QSslSocket*>(sender()); if (!socket) return; disconnect(socket, SIGNAL(encrypted()), this, SLOT(encrypted())); disconnect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>))); foreach(const QSslError &error, errors) { qCDebug(KDECONNECT_CORE) << "SSL Error :" << error.errorString(); switch (error.error()) { case QSslError::CertificateSignatureFailed: case QSslError::CertificateNotYetValid: case QSslError::CertificateExpired: case QSslError::CertificateUntrusted: case QSslError::SelfSignedCertificate: { qCDebug(KDECONNECT_CORE) << "Unpairing device due to " << error.errorString(); // Due to simultaneous multiple connections, it may be possible that device instance does not exist anymore Device *device = Daemon::instance()->getDevice(socket->peerVerifyName()); if (device != Q_NULLPTR) { device->unpair(); } break; } default: continue; // Lots of warnings without this } }
void ClientSyncer::clientInitAck(const QVariantMap &msg) { // Core has accepted our version info and sent its own. Let's see if we accept it as well... uint ver = msg["ProtocolVersion"].toUInt(); if(ver < Quassel::buildInfo().clientNeedsProtocol) { emit connectionError(tr("<b>The Quassel Core you are trying to connect to is too old!</b><br>" "Need at least core/client protocol v%1 to connect.").arg(Quassel::buildInfo().clientNeedsProtocol)); disconnectFromCore(); return; } emit connectionMsg(msg["CoreInfo"].toString()); #ifndef QT_NO_COMPRESS if(msg["SupportsCompression"].toBool()) { _socket->setProperty("UseCompression", true); } #endif _coreMsgBuffer = msg; #ifdef HAVE_SSL if(coreConnectionInfo["useSsl"].toBool()) { if(msg["SupportSsl"].toBool()) { QSslSocket *sslSocket = qobject_cast<QSslSocket *>(_socket); Q_ASSERT(sslSocket); connect(sslSocket, SIGNAL(encrypted()), this, SLOT(sslSocketEncrypted())); connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &))); sslSocket->startClientEncryption(); } else {
bool StartTLSFeature::xmppStanzaIn(IXmppStream *AXmppStream, Stanza &AStanza, int AOrder) { if (AXmppStream==FXmppStream && AOrder==XSHO_XMPP_FEATURE) { FXmppStream->removeXmppStanzaHandler(XSHO_XMPP_FEATURE,this); if (AStanza.tagName() == "proceed") { if (FXmppStream->connection()->startEncryption()) { LOG_STRM_INFO(FXmppStream->streamJid(),"Starting StartTLS encryption"); connect(FXmppStream->connection()->instance(),SIGNAL(encrypted()),SLOT(onConnectionEncrypted())); } else { LOG_STRM_ERROR(FXmppStream->streamJid(),"Failed to negotiate StartTLS encryption: Handshake not started"); emit error(XmppError(IERR_STARTTLS_NOT_STARTED)); } } else if (AStanza.tagName() == "failure") { LOG_STRM_WARNING(FXmppStream->streamJid(),"Failed to negotiate StartTLS encryption: Negotiation failed"); emit error(XmppError(IERR_STARTTLS_NEGOTIATION_FAILED)); } else { LOG_STRM_WARNING(FXmppStream->streamJid(),"Failed to negotiate StartTLS encryption: Invalid responce"); emit error(XmppError(IERR_STARTTLS_INVALID_RESPONCE)); } return true; } return false; }
SimondConnector::SimondConnector(QObject *parent) : QObject(parent), state(Unconnected), socket(new QSslSocket(this)), timeoutTimer(new QTimer(this)), response(new QDataStream(socket)), mic(new SoundInput(SOUND_CHANNELS, SOUND_SAMPLERATE, this)), passThroughSound(false) { connect(this, SIGNAL(connectionState(ConnectionState)), this, SLOT(setCurrentState(ConnectionState))); connect(socket, SIGNAL(readyRead()), this, SLOT(messageReceived())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError())); connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(socketError())); connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); connect(socket, SIGNAL(encrypted()), this, SLOT(connectionEstablished())); connect(socket, SIGNAL(disconnected()), this, SLOT(connectionLost())); connect(mic, SIGNAL(error(QString)), this, SIGNAL(error(QString))); connect(mic, SIGNAL(microphoneLevel(int,int,int)), this, SIGNAL(microphoneLevel(int,int,int))); connect(mic, SIGNAL(listening()), this, SLOT(startRecording())); connect(mic, SIGNAL(complete()), this, SLOT(commitRecording())); connect(mic, SIGNAL(readyRead()), this, SLOT(soundDataAvailable())); connect(timeoutTimer, SIGNAL(timeout()), this, SLOT(timeoutReached())); timeoutTimer->setSingleShot(true); timeoutTimer->setInterval(SOCKET_TIMEOUT); }
void QXmppStream::setSocket(QSslSocket *socket) { bool check; Q_UNUSED(check); d->socket = socket; if (!d->socket) return; // socket events check = connect(socket, SIGNAL(connected()), this, SLOT(_q_socketConnected())); Q_ASSERT(check); check = connect(socket, SIGNAL(encrypted()), this, SLOT(_q_socketEncrypted())); Q_ASSERT(check); check = connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(_q_socketError(QAbstractSocket::SocketError))); Q_ASSERT(check); check = connect(socket, SIGNAL(readyRead()), this, SLOT(_q_socketReadyRead())); Q_ASSERT(check); }
void QMyServer::_connectSocketSignals () { connect(socket, SIGNAL(encrypted()), this, SLOT(slot_encrypted())); connect(socket, SIGNAL(encryptedBytesWritten(qint64)), this, SLOT(slot_encryptedBytesWritten(qint64))); connect(socket, SIGNAL(modeChanged(QSslSocket::SslMode)), this, SLOT(slot_modeChanged(QSslSocket::SslMode))); connect(socket, SIGNAL(peerVerifyError(const QSslError &)), this, SLOT(slot_peerVerifyError (const QSslError &))); connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(slot_sslErrors(const QList<QSslError> &))); connect(socket, SIGNAL(readyRead()), this, SLOT(slot_readyRead())); connect(socket, SIGNAL(connected()), this, SLOT(slot_connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(slot_disconnected())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_error(QAbstractSocket::SocketError))); connect(socket, SIGNAL(hostFound()), this, SLOT(slot_hostFound())); connect(socket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), this, SLOT(slot_proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *))); connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(slot_stateChanged(QAbstractSocket::SocketState))); }
void SslClient::establish(const QString& host, quint16 port) { threadLock_ = new QMutex(); threadEvent_ = new QWaitCondition(); QMutexLocker blocked(threadLock_); host_ = host; port_ = port; start(); threadEvent_->wait(threadLock_); if(ssl_.isNull() || running_ == false) Q_ASSERT_X(ssl_.isNull() || running_ == false, "SslClient::establish", "Cannot start SslClient's thread"); connect(ssl_.data(), SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)), Qt::DirectConnection); connect(ssl_.data(), SIGNAL(encrypted()), this, SLOT(socketEncrypted()), Qt::DirectConnection); connect(ssl_.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)), Qt::DirectConnection); connect(ssl_.data(), SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)), Qt::DirectConnection); connect(ssl_.data(), SIGNAL(readyRead()), this, SLOT(socketReadyRead()), Qt::DirectConnection); ConfigureForLMAX(); }
void QSslServer::incomingConnection(qintptr socket) { QSslSocket *pSslSocket = new QSslSocket(); if (Q_LIKELY(pSslSocket)) { pSslSocket->setSslConfiguration(m_sslConfiguration); if (Q_LIKELY(pSslSocket->setSocketDescriptor(socket))) { typedef void (QSslSocket::* sslErrorsSignal)(const QList<QSslError> &); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 2) connect(pSslSocket, &QSslSocket::peerVerifyError, this, &QSslServer::peerVerifyError); connect(pSslSocket, &QSslSocket::encrypted, this, &QSslServer::newEncryptedConnection); #else connect(pSslSocket,SIGNAL(peerVerifyError(QSslError)), this, SIGNAL(peerVerifyError(QSslError))); connect(pSslSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SIGNAL(sslErrors(QList<QSslError>))); connect(pSslSocket, SIGNAL(encrypted()), this, SIGNAL(newEncryptedConnection())); #endif addPendingConnection(pSslSocket); pSslSocket->startServerEncryption(); } else { delete pSslSocket; } } }
void ServerThread::run() { QFile keyFile("./server.key"); s = new QSslSocket(); if(!s->setSocketDescriptor(socketDescriptor)) { emit error(s->error()); } if(!keyFile.open(QIODevice::ReadOnly)) { qDebug() << "File was not opened"; } QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem ,QSsl::PrivateKey); s->setPrivateKey(key); s->setLocalCertificate("./server.crt",QSsl::Pem); s->addCaCertificates("./ca.crt", QSsl::Pem); //s->addCaCertificates("./server.crt",QSsl::Pem); connect(s, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::QueuedConnection); connect(s, SIGNAL(disconnected()), this, SLOT(disconnected()), Qt::DirectConnection); connect(s, SIGNAL(encrypted()), this, SLOT(ready()),Qt::QueuedConnection); connect(s, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(errorm(QList<QSslError>)),Qt::DirectConnection); s->startServerEncryption(); qDebug() << "started listening"; exec(); }
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(); } }
Mail::Mail() : CodeClass() { connect(&mSmtp, SIGNAL(connected()), this, SLOT(connected())); connect(&mSmtp, SIGNAL(connectionFailed(QByteArray)), this, SLOT(connectionFailed(QByteArray))); connect(&mSmtp, SIGNAL(encrypted()), this, SLOT(encrypted())); connect(&mSmtp, SIGNAL(encryptionFailed(QByteArray)), this, SLOT(encryptionFailed(QByteArray))); connect(&mSmtp, SIGNAL(authenticated()), this, SLOT(authenticated())); connect(&mSmtp, SIGNAL(authenticationFailed(QByteArray)), this, SLOT(authenticationFailed(QByteArray))); connect(&mSmtp, SIGNAL(senderRejected(int,QString,QByteArray)), this, SLOT(senderRejected(int,QString,QByteArray))); connect(&mSmtp, SIGNAL(recipientRejected(int,QString,QByteArray)), this, SLOT(recipientRejected(int,QString,QByteArray))); connect(&mSmtp, SIGNAL(mailFailed(int,int,QByteArray)), this, SLOT(mailFailed(int,int,QByteArray))); connect(&mSmtp, SIGNAL(mailSent(int)), this, SLOT(mailSent(int))); connect(&mSmtp, SIGNAL(finished()), this, SLOT(finished())); connect(&mSmtp, SIGNAL(disconnected()), this, SLOT(disconnected())); }
void sshsocket::AcceptHost(QString title, QString hostname, QString username, QString password, qint32 port ) { host = new Host(title, hostname, username, port) ; #ifdef Q_WS_SIMULATOR host->setPassword(password); #else QByteArray clearData ; clearData.append(password) ; RAWDATA_PTR cipherData = NULL; size_t cipherLength = 0; aegis_crypto_result rc = aegis_crypto_encrypt(clearData.data(), clearData.length(), NULL, &cipherData, &cipherLength) ; if (aegis_crypto_ok != rc) { AEGIS_ERROR("%s: aegis_crypto_encrypt failed (%s)", __func__, aegis_crypto_last_error_str()); } QByteArray encrypted((char *)cipherData, cipherLength); host->setSecret(encrypted); // aegis_crypto_free(cipherData); #endif socket = new QTcpSocket(this) ; qint16 port_value = host->port() ; socket->connectToHost(host->hostname(), port_value); connect(socket, SIGNAL(connected()), this, SLOT(socket_connected_slot())) ; connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(display_error(QAbstractSocket::SocketError))) ; }
Connection::Connection(QObject *parent) : QObject(parent) { this->_blockSize = 0; this->sslsocket = new QSslSocket(this); this->sslsocket->setProtocol(QSsl::TlsV1_2); connect( this->sslsocket, SIGNAL(readyRead()), this, SLOT(readyRead()) ); connect( this->sslsocket, SIGNAL(encrypted()), this, SLOT(encrypted()) ); connect( this->sslsocket, SIGNAL (disconnected()), this, SLOT(disconnected()) ); connect( this->sslsocket, SIGNAL(connected()), this, SLOT(connected()) ); connect( this->sslsocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(socketSslErrors(const QList<QSslError> &)) ); connect( this->sslsocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)) ); }
void Connection::init() { connect(this, SIGNAL(connected()), SLOT(handshake())); connect(this, SIGNAL(readyRead()), SLOT(onDataReady())); connect(this, SIGNAL(encrypted()), SLOT(onEncrypted())); connect(this, SIGNAL(sslErrors(const QList<QSslError>&)), SLOT(onSslErrors(const QList<QSslError>&))); connect(this, SIGNAL(bytesWritten(qint64)), SLOT(sendNext(qint64))); }
void LoginHandler::startTls() { connect(m_server->_socket, SIGNAL(encrypted()), this, SLOT(tlsStarted())); connect(m_server->_socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(tlsError(QList<QSslError>))); m_tls = false; m_server->_socket->startClientEncryption(); }
QScriptValue Mail::waitForEncrypted(int waitTime) { QxtSignalWaiter waiter(&mSmtp, SIGNAL(encrypted())); if(!waiter.wait(waitTime)) throwError("EncryptionError", tr("Cannot encrypt the connection")); return thisObject(); }
/*! Constructs a new QxtPop3 whith parent \a parent. */ QxtPop3::QxtPop3(QObject* parent) : QObject(parent), d_ptr(new QxtPop3Private) { d_ptr->q_ptr = this; d_ptr->state = QxtPop3Private::Disconnected; #ifndef QT_NO_OPENSSL d_ptr->socket = new QSslSocket(this); QObject::connect(socket(), SIGNAL(encrypted()), this, SIGNAL(encrypted())); QObject::connect(socket(), SIGNAL(encrypted()), d_func(),SLOT(encrypted())); #else d_func()->socket = new QTcpSocket(this); #endif QObject::connect(socket(), SIGNAL(connected()), this, SIGNAL(connected())); QObject::connect(socket(), SIGNAL(disconnected()), this, SIGNAL(disconnected())); QObject::connect(socket(), SIGNAL(disconnected()), d_func(), SLOT(disconnected())); QObject::connect(socket(), SIGNAL(error(QAbstractSocket::SocketError)), d_func(), SLOT(socketError(QAbstractSocket::SocketError))); QObject::connect(socket(), SIGNAL(readyRead()), d_func(), SLOT(socketRead())); }
QxtSmtp::QxtSmtp(QObject* parent) : QObject(parent) { QXT_INIT_PRIVATE(QxtSmtp); qxt_d().state = QxtSmtpPrivate::Disconnected; qxt_d().nextID = 0; #ifndef QT_NO_OPENSSL qxt_d().socket = new QSslSocket(this); QObject::connect(socket(), SIGNAL(encrypted()), this, SIGNAL(encrypted())); //QObject::connect(socket(), SIGNAL(encrypted()), &qxt_d(), SLOT(ehlo())); #else qxt_d().socket = new QTcpSocket(this); #endif QObject::connect(socket(), SIGNAL(connected()), this, SIGNAL(connected())); QObject::connect(socket(), SIGNAL(disconnected()), this, SIGNAL(disconnected())); QObject::connect(socket(), SIGNAL(error(QAbstractSocket::SocketError)), &qxt_d(), SLOT(socketError(QAbstractSocket::SocketError))); QObject::connect(this, SIGNAL(authenticated()), &qxt_d(), SLOT(sendNext())); QObject::connect(socket(), SIGNAL(readyRead()), &qxt_d(), SLOT(socketRead())); }
QT_BEGIN_NAMESPACE // TODO: Put channel specific stuff here so it does not polute qhttpnetworkconnection.cpp void QHttpNetworkConnectionChannel::init() { #ifndef QT_NO_OPENSSL if (connection->d_func()->encrypt) socket = new QSslSocket; else socket = new QTcpSocket; #else socket = new QTcpSocket; #endif // limit the socket read buffer size. we will read everything into // the QHttpNetworkReply anyway, so let's grow only that and not // here and there. socket->setReadBufferSize(64*1024); QObject::connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(_q_bytesWritten(qint64)), Qt::DirectConnection); QObject::connect(socket, SIGNAL(connected()), this, SLOT(_q_connected()), Qt::DirectConnection); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(_q_readyRead()), Qt::DirectConnection); QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(_q_disconnected()), Qt::DirectConnection); QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(_q_error(QAbstractSocket::SocketError)), Qt::DirectConnection); #ifndef QT_NO_NETWORKPROXY QObject::connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(_q_proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), Qt::DirectConnection); #endif #ifndef QT_NO_OPENSSL QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); if (sslSocket) { // won't be a sslSocket if encrypt is false QObject::connect(sslSocket, SIGNAL(encrypted()), this, SLOT(_q_encrypted()), Qt::DirectConnection); QObject::connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(_q_sslErrors(QList<QSslError>)), Qt::DirectConnection); QObject::connect(sslSocket, SIGNAL(encryptedBytesWritten(qint64)), this, SLOT(_q_encryptedBytesWritten(qint64)), Qt::DirectConnection); } #endif }
KVNetworkReply::KVNetworkReply(QObject *parent, QNetworkReply *toCopy, QNetworkAccessManager *mgr, bool translate) : QNetworkReply(parent) { d = new KVNetworkReplyPrivate; d->finished = false; d->copied = toCopy; d->manager = mgr; d->translate = translate; setOperation(d->copied->operation()); setRequest(d->copied->request()); setUrl(d->copied->url()); // Translate reply when it's complete connect(d->copied, SIGNAL(finished()), SLOT(handleResponse())); connect(d->copied, SIGNAL(encrypted()), SIGNAL(encrypted())); connect(d->copied, SIGNAL(metaDataChanged()), SIGNAL(metaDataChanged())); }
//! [1] void SslServer::incomingConnection(qintptr socketDescriptor) { QSslSocket *serverSocket = new QSslSocket; if (serverSocket->setSocketDescriptor(socketDescriptor)) { connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready())); serverSocket->startServerEncryption(); } else { delete serverSocket; } }
void DefaultConnection::onSocketEncrypted() { LogDetail(QString("[DefaultConnection] Socket connection encrypted")); emit encrypted(); if (FSSLConnection) { FRecords.clear(); emit connected(); } }
void LanLinkProvider::encrypted() { qCDebug(KDECONNECT_CORE) << "Socket succesfully stablished an SSL connection"; QSslSocket* socket = qobject_cast<QSslSocket*>(sender()); if (!socket) return; disconnect(socket, SIGNAL(encrypted()), this, SLOT(encrypted())); disconnect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>))); NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np; const QString& deviceId = receivedPackage->get<QString>("deviceId"); //qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable(); addLink(deviceId, socket, receivedPackage, LanDeviceLink::Remotely); // Copied from connected slot, now delete received package delete receivedIdentityPackages.take(socket).np; }
ThreadedSSLSocket::ThreadedSSLSocket(QObject* parent): QIODevice(parent), socketThread(new SocketThread(this)), socket(new SimonSSLSocket(this)) { open(QIODevice::ReadWrite); //krazy:exclude=syscalls qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError"); writeBuffer.open(QIODevice::ReadWrite); socketThread->start(); socket->moveToThread(socketThread); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(error(QAbstractSocket::SocketError))); connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SIGNAL(sslErrors(QList<QSslError>))); connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); connect(socket, SIGNAL(connected()), this, SIGNAL(connected())); connect(socket, SIGNAL(encrypted()), this, SIGNAL(encrypted())); }
DeviceAgent::DeviceAgent(QObject *parent): QSslSocket(parent) { connect(this,SIGNAL(readyRead()),this,SLOT(onDataComing())); connect(this, SIGNAL(disconnected()), this, SLOT(onDeviceDisconnected())); connect(this, SIGNAL(encrypted()), this, SLOT(onEncrypted())); connect(this, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(onSslErrors(QList<QSslError>))); m_dataPos = 0; }
void Connector::connectToHost() { qDebug() << "Connecting..."; d->sock = new QSslSocket(this); connect( d->sock, SIGNAL(encrypted()), this, SLOT(ready()) ); connect( d->sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)) ); connect( d->sock, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslError(const QList<QSslError> &)) ); d->sock->connectToHostEncrypted( d->host, d->port ); }
QByteArray Core::encryptData(const QByteArray& data, const Tox_Pass_Key& encryptionKey) { QByteArray encrypted(data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, 0x00); if (!tox_pass_key_encrypt(&encryptionKey, reinterpret_cast<const uint8_t*>(data.data()), data.size(), (uint8_t*) encrypted.data(), nullptr)) { qWarning() << "Encryption failed"; return QByteArray(); } return encrypted; }
void Server :: acceptConnection() { clientConnection = sslServer -> getClientConnection(); qDebug() << "New connection received from "<< clientConnection->peerAddress().toString(); connect(clientConnection, SIGNAL(encrypted()), SLOT(connectionAccepted())); connect(clientConnection, SIGNAL(readyRead()), this, SLOT(readDataFromClient())); connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater())); connect(clientConnection, SIGNAL(disconnected()), this, SLOT(notifyDisconnect())); connect(clientConnection, SIGNAL(sslErrors(QList<QSslError>)),SLOT(sslErrors(QList<QSslError>)) ); }
// 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 }