tcpslavebase.cpp
来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C++ 代码 · 共 1,342 行 · 第 1/3 页
CPP
1,342 行
QStringList() ); } } QByteArray data, ignore; QCString ignoretype; QDataStream arg(data, IO_WriteOnly); arg << theurl << mOutgoingMetaData; arg << metaData("window-id").toInt(); d->dcc->call("kio_uiserver", "UIServer", "showSSLInfoDialog(QString,KIO::MetaData,int)", data, ignoretype, ignore); } } while (result == KMessageBox::Yes); if (result == KMessageBox::No) { setMetaData("ssl_action", "accept"); rc = 1; cp = KSSLCertificateCache::Accept; doAddHost = true; result = messageBox( WarningYesNo, i18n("Would you like to accept this " "certificate forever without " "being prompted?"), i18n("Server Authentication"), i18n("&Forever"), i18n("&Current Sessions Only")); if (result == KMessageBox::Yes) permacache = true; else permacache = false; } else { setMetaData("ssl_action", "reject"); rc = -1; cp = KSSLCertificateCache::Prompt; } break; } default: kdDebug(7029) << "TCPSlaveBase/SSL error in cert code." << "Please report this to kfm-devel@kde.org." << endl; break; } } // - cache the results d->cc->addCertificate(pc, cp, permacache); if (doAddHost) d->cc->addHost(pc, ourHost); } else { // Child frame // - Read from cache and see if there is a policy for this KSSLCertificateCache::KSSLCertificatePolicy cp = d->cc->getPolicyByCertificate(pc); isChild = true; // Check the cert and IP to make sure they're the same // as the parent frame bool certAndIPTheSame = (d->ip == metaData("ssl_parent_ip") && pc.toString() == metaData("ssl_parent_cert")); if (ksv == KSSLCertificate::Ok) { if (certAndIPTheSame) { // success rc = 1; setMetaData("ssl_action", "accept"); } else { /* if (d->militantSSL) { return -1; } result = messageBox(WarningYesNo, i18n("The certificate is valid but does not appear to have been assigned to this server. Do you wish to continue loading?"), i18n("Server Authentication")); if (result == KMessageBox::Yes) { // success rc = 1; setMetaData("ssl_action", "accept"); } else { // fail rc = -1; setMetaData("ssl_action", "reject"); } */ setMetaData("ssl_action", "accept"); rc = 1; // Let's accept this now. It's bad, but at least the user // will see potential attacks in KDE3 with the pseudo-lock // icon on the toolbar, and can investigate with the RMB } } else { if (d->militantSSL) { return -1; } if (cp == KSSLCertificateCache::Accept) { if (certAndIPTheSame) { // success rc = 1; setMetaData("ssl_action", "accept"); } else { // fail result = messageBox(WarningYesNo, i18n("You have indicated that you wish to accept this certificate, but it is not issued to the server who is presenting it. Do you wish to continue loading?"), i18n("Server Authentication")); if (result == KMessageBox::Yes) { rc = 1; setMetaData("ssl_action", "accept"); d->cc->addHost(pc, ourHost); } else { rc = -1; setMetaData("ssl_action", "reject"); } } } else if (cp == KSSLCertificateCache::Reject) { // fail messageBox(Information, i18n("SSL certificate is being rejected as requested. You can disable this in the KDE Control Center."), i18n("Server Authentication")); rc = -1; setMetaData("ssl_action", "reject"); } else { do { QString msg = i18n("The server certificate failed the " "authenticity test (%1)."); result = messageBox(WarningYesNoCancel, msg.arg(ourHost), i18n("Server Authentication"), i18n("&Details"), i18n("Co&nnect")); if (result == KMessageBox::Yes) { if (!d->dcc) { d->dcc = new DCOPClient; d->dcc->attach(); if (!d->dcc->isApplicationRegistered("kio_uiserver")) { KApplication::startServiceByDesktopPath("kio_uiserver.desktop", QStringList() ); } } QByteArray data, ignore; QCString ignoretype; QDataStream arg(data, IO_WriteOnly); arg << theurl << mOutgoingMetaData; arg << metaData("window-id").toInt(); d->dcc->call("kio_uiserver", "UIServer", "showSSLInfoDialog(QString,KIO::MetaData,int)", data, ignoretype, ignore); } } while (result == KMessageBox::Yes); if (result == KMessageBox::No) { setMetaData("ssl_action", "accept"); rc = 1; cp = KSSLCertificateCache::Accept; result = messageBox(WarningYesNo, i18n("Would you like to accept this " "certificate forever without " "being prompted?"), i18n("Server Authentication"), i18n("&Forever"), i18n("&Current Sessions Only")); permacache = (result == KMessageBox::Yes); d->cc->addCertificate(pc, cp, permacache); d->cc->addHost(pc, ourHost); } else { setMetaData("ssl_action", "reject"); rc = -1; cp = KSSLCertificateCache::Prompt; d->cc->addCertificate(pc, cp, permacache); } } } } if (rc == -1) { return rc; } if (metaData("ssl_activate_warnings") == "TRUE") { // - entering SSL if (!isChild && metaData("ssl_was_in_use") == "FALSE" && d->kssl->settings()->warnOnEnter()) { int result; do { result = messageBox( i18n("You are about to " "enter secure mode. " "All transmissions " "will be encrypted " "unless otherwise " "noted.\nThis means " "that no third party " "will be able to " "easily observe your " "data in transit."), WarningYesNo, i18n("Security Information"), i18n("Display SSL " "&Information"), i18n("C&onnect"), "WarnOnEnterSSLMode" ); // Move this setting into KSSL instead KConfig *config = new KConfig("kioslaverc"); config->setGroup("Notification Messages"); if (!config->readBoolEntry("WarnOnEnterSSLMode", true)) { config->deleteEntry("WarnOnEnterSSLMode"); config->sync(); d->kssl->settings()->setWarnOnEnter(false); d->kssl->settings()->save(); } delete config; if ( result == KMessageBox::Yes ) { if (!d->dcc) { d->dcc = new DCOPClient; d->dcc->attach(); if (!d->dcc->isApplicationRegistered("kio_uiserver")) { KApplication::startServiceByDesktopPath("kio_uiserver.desktop", QStringList() ); } } QByteArray data, ignore; QCString ignoretype; QDataStream arg(data, IO_WriteOnly); arg << theurl << mOutgoingMetaData; arg << metaData("window-id").toInt(); d->dcc->call("kio_uiserver", "UIServer", "showSSLInfoDialog(QString,KIO::MetaData,int)", data, ignoretype, ignore); } } while (result != KMessageBox::No); } } // if ssl_activate_warnings kdDebug(7029) << "SSL connection information follows:" << endl << "+-----------------------------------------------" << endl << "| Cipher: " << d->kssl->connectionInfo().getCipher() << endl << "| Description: " << d->kssl->connectionInfo().getCipherDescription() << endl << "| Version: " << d->kssl->connectionInfo().getCipherVersion() << endl << "| Strength: " << d->kssl->connectionInfo().getCipherUsedBits() << " of " << d->kssl->connectionInfo().getCipherBits() << " bits used." << endl << "| PEER:" << endl << "| Subject: " << d->kssl->peerInfo().getPeerCertificate().getSubject() << endl << "| Issuer: " << d->kssl->peerInfo().getPeerCertificate().getIssuer() << endl << "| Validation: " << (int)ksv << endl << "| Certificate matches IP: " << _IPmatchesCN << endl << "+-----------------------------------------------" << endl; // sendMetaData(); Do not call this function!! return rc;}bool TCPSlaveBase::isConnectionValid(){ if ( m_iSock == -1 ) return false; fd_set rdfs; FD_ZERO(&rdfs); FD_SET(m_iSock , &rdfs); struct timeval tv; tv.tv_usec = 0; tv.tv_sec = 0; int retval;#ifdef Q_OS_UNIX do { retval = KSocks::self()->select(m_iSock+1, &rdfs, NULL, NULL, &tv); if (wasKilled()) return false; // Beam us out of here } while ((retval == -1) && (errno == EAGAIN));#else retval = -1;#endif // retval == -1 ==> Error // retval == 0 ==> Connection Idle // retval >= 1 ==> Connection Active //kdDebug(7029) << "TCPSlaveBase::isConnectionValid: select returned: " // << retval << endl; if (retval == -1) return false; if (retval == 0) return true; // Connection is active, check if it has closed. char buffer[100];#ifdef Q_OS_UNIX do { retval = KSocks::self()->recv(m_iSock, buffer, 80, MSG_PEEK); } while ((retval == -1) && (errno == EAGAIN));#else retval = -1;#endif //kdDebug(7029) << "TCPSlaveBase::isConnectionValid: recv returned: " // << retval << endl; if (retval <= 0) return false; // Error or connection closed. return true; // Connection still valid.}bool TCPSlaveBase::waitForResponse( int t ){ fd_set rd; struct timeval timeout; if ( (m_bIsSSL || d->usingTLS) && !d->useSSLTunneling && d->kssl ) if (d->kssl->pending() > 0) return true; FD_ZERO(&rd); FD_SET(m_iSock, &rd); timeout.tv_usec = 0; timeout.tv_sec = t; time_t startTime; int rc; int n = t;reSelect: startTime = time(NULL);#ifdef Q_OS_UNIX rc = KSocks::self()->select(m_iSock+1, &rd, NULL, NULL, &timeout);#else rc = -1;#endif if (wasKilled()) return false; // We're dead. if (rc == -1) return false; if (FD_ISSET(m_iSock, &rd)) return true; // Well it returned but it wasn't set. Let's see if it // returned too early (perhaps from an errant signal) and // start over with the remaining time int timeDone = time(NULL) - startTime; if (timeDone < n) { n -= timeDone; timeout.tv_sec = n; goto reSelect; } return false; // Timed out!}int TCPSlaveBase::connectResult(){ return d->status;}void TCPSlaveBase::setBlockConnection( bool b ){ d->block = b;}void TCPSlaveBase::setConnectTimeout( int t ){ d->timeout = t;}bool TCPSlaveBase::isSSLTunnelEnabled(){ return d->useSSLTunneling;}void TCPSlaveBase::setEnableSSLTunnel( bool enable ){ d->useSSLTunneling = enable;}void TCPSlaveBase::setRealHost( const QString& realHost ){ d->realHost = realHost;}bool TCPSlaveBase::doSSLHandShake( bool sendError ){ kdDebug(7029) << "TCPSlaveBase::doSSLHandShake: " << endl; QString msgHost = d->host; d->kssl->reInitialize(); if (hasMetaData("ssl_session_id")) { KSSLSession *s = KSSLSession::fromString(metaData("ssl_session_id")); if (s) { d->kssl->setSession(s); delete s; } } certificatePrompt(); if ( !d->realHost.isEmpty() ) { msgHost = d->realHost; } kdDebug(7029) << "Setting real hostname: " << msgHost << endl; d->kssl->setPeerHost(msgHost); d->status = d->kssl->connect(m_iSock); if (d->status < 0) { closeDescriptor(); if ( sendError ) error( ERR_COULD_NOT_CONNECT, msgHost); return false; } setMetaData("ssl_session_id", d->kssl->session()->toString()); setMetaData("ssl_in_use", "TRUE"); if (!d->kssl->reusingSession()) { int rc = verifyCertificate(); if ( rc != 1 ) { d->status = -1; closeDescriptor(); if ( sendError ) error( ERR_COULD_NOT_CONNECT, msgHost); return false; } } d->needSSLHandShake = false; d->savedMetaData = mOutgoingMetaData; return true;}bool TCPSlaveBase::userAborted() const{ return d->userAborted;}void TCPSlaveBase::virtual_hook( int id, void* data ){ SlaveBase::virtual_hook( id, data ); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?