Exemplo n.º 1
0
bool KSSLD::caAdd(TQString certificate, bool ssl, bool email, bool code) {
KSSLCertificate *x = KSSLCertificate::fromString(certificate.local8Bit());

	if (!x) return false;

TDEConfig cfg("ksslcalist", false, false);

	cfg.setGroup(x->getSubject());
	cfg.writeEntry("x509", certificate);
	cfg.writeEntry("site", ssl);
	cfg.writeEntry("email", email);
	cfg.writeEntry("code", code);

	cfg.sync();
	delete x;

return true;
}
Exemplo n.º 2
0
bool KSSLD::caRemoveFromFile(TQString filename) {

	TQStringList certificates;
	certificates = caReadCerticatesFromFile(filename);
	if (certificates.isEmpty())
		return false;

	bool ok = true;

	for (TQStringList::Iterator it = certificates.begin();
					it != certificates.end(); ++it ) {
		TQString certificate = *it;
		KSSLCertificate *x = KSSLCertificate::fromString(certificate.local8Bit());
		ok &= x && caRemove(x->getSubject());
		delete x;
	}

	return ok;
}
Exemplo n.º 3
0
void KSSLInfoDlg::setup(KSSLCertificate *cert, const QString &ip, const QString &url, const QString &cipher, const QString &cipherdesc,
                        const QString &sslversion, int usedbits, int bits, KSSLCertificate::KSSLValidation /*certState*/)
{
    // Needed to put the GUI stuff here to get the layouting right

    d->_cert = cert;

    QGridLayout *layout = new QGridLayout(4, 2, KDialog::spacingHint());

    layout->addWidget(new QLabel(i18n("Chain:"), this), 0, 0);
    d->_chain = new KComboBox(this);
    layout->addMultiCellWidget(d->_chain, 1, 1, 0, 1);
    connect(d->_chain, SIGNAL(activated(int)), this, SLOT(slotChain(int)));

    d->_chain->clear();

    if(cert->chain().isValid() && cert->chain().depth() > 1)
    {
        d->_chain->setEnabled(true);
        d->_chain->insertItem(i18n("0 - Site Certificate"));
        int cnt = 0;
        QPtrList< KSSLCertificate > cl = cert->chain().getChain();
        cl.setAutoDelete(true);
        for(KSSLCertificate *c = cl.first(); c != 0; c = cl.next())
        {
            KSSLX509Map map(c->getSubject());
            QString id;
            id = map.getValue("CN");
            if(id.length() == 0)
                id = map.getValue("O");
            if(id.length() == 0)
                id = map.getValue("OU");
            d->_chain->insertItem(QString::number(++cnt) + " - " + id);
        }
        d->_chain->setCurrentItem(0);
    }
    else
        d->_chain->setEnabled(false);

    layout->addWidget(new QLabel(i18n("Peer certificate:"), this), 2, 0);
    layout->addWidget(d->_subject = static_cast< KSSLCertBox * >(buildCertInfo(cert->getSubject())), 3, 0);
    layout->addWidget(new QLabel(i18n("Issuer:"), this), 2, 1);
    layout->addWidget(d->_issuer = static_cast< KSSLCertBox * >(buildCertInfo(cert->getIssuer())), 3, 1);
    d->m_layout->addMultiCell(layout, 1, 1, 0, 2);

    layout = new QGridLayout(11, 2, KDialog::spacingHint());
    layout->setColStretch(1, 1);
    QLabel *ipl = new QLabel(i18n("IP address:"), this);
    layout->addWidget(ipl, 0, 0);
    if(ip.isEmpty())
    {
        ipl->hide();
    }
    layout->addWidget(ipl = new QLabel(ip, this), 0, 1);
    if(ip.isEmpty())
    {
        ipl->hide();
    }
    layout->addWidget(new QLabel(i18n("URL:"), this), 1, 0);
    KSqueezedTextLabel *urlLabel = new KSqueezedTextLabel(url, this);
    layout->addWidget(urlLabel, 1, 1);
    layout->addWidget(new QLabel(i18n("Certificate state:"), this), 2, 0);

    layout->addWidget(d->_csl = new QLabel("", this), 2, 1);

    update();

    layout->addWidget(new QLabel(i18n("Valid from:"), this), 3, 0);
    layout->addWidget(d->_validFrom = new QLabel("", this), 3, 1);
    layout->addWidget(new QLabel(i18n("Valid until:"), this), 4, 0);
    layout->addWidget(d->_validUntil = new QLabel("", this), 4, 1);

    layout->addWidget(new QLabel(i18n("Serial number:"), this), 5, 0);
    layout->addWidget(d->_serialNum = new QLabel("", this), 5, 1);
    layout->addWidget(new QLabel(i18n("MD5 digest:"), this), 6, 0);
    layout->addWidget(d->_digest = new QLabel("", this), 6, 1);

    layout->addWidget(new QLabel(i18n("Cipher in use:"), this), 7, 0);
    layout->addWidget(new QLabel(cipher, this), 7, 1);
    layout->addWidget(new QLabel(i18n("Details:"), this), 8, 0);
    layout->addWidget(new QLabel(cipherdesc.simplifyWhiteSpace(), this), 8, 1);
    layout->addWidget(new QLabel(i18n("SSL version:"), this), 9, 0);
    layout->addWidget(new QLabel(sslversion, this), 9, 1);
    layout->addWidget(new QLabel(i18n("Cipher strength:"), this), 10, 0);
    layout->addWidget(new QLabel(i18n("%1 bits used of a %2 bit cipher").arg(usedbits).arg(bits), this), 10, 1);
    d->m_layout->addMultiCell(layout, 2, 2, 0, 2);

    displayCert(cert);
}
Exemplo n.º 4
0
bool KSSLSigners::remove(KSSLCertificate& cert) {
	return remove(cert.getSubject());
}
Exemplo n.º 5
0
bool KSSLSigners::useForCode(KSSLCertificate& cert) const{
	return useForCode(cert.getSubject());
}
Exemplo n.º 6
0
void KJavaAppletServer::slotJavaRequest( const QByteArray& qb )
{
    // qb should be one command only without the length string,
    // we parse out the command and it's meaning here...
    QString cmd;
    QStringList args;
    int index = 0;
    const int qb_size = qb.size();

    //get the command code
    const char cmd_code = qb[ index++ ];
    ++index; //skip the next sep

    //get contextID
    QString contextID;
    while( qb[index] != 0 && index < qb_size )
    {
        contextID += qb[ index++ ];
    }
    bool ok;
    const int ID_num = contextID.toInt( &ok ); // context id or kio job id
    /*if (d->locked_context > -1 &&
        ID_num != d->locked_context &&
        (cmd_code == KJAS_JAVASCRIPT_EVENT ||
         cmd_code == KJAS_APPLET_STATE ||
         cmd_code == KJAS_APPLET_FAILED))
    {
        / * Don't allow requests from other contexts if we're waiting
         * on a return value that can trigger JavaScript events
         * /
        d->java_requests.push_back(qb);
        return;
    }*/
    ++index; //skip the sep

    if (cmd_code == KJAS_PUT_DATA) {
        // rest of the data is for kio put
        if (ok) {
            KIOJobMap::iterator it = d->kiojobs.find( ID_num );
            if (ok && it != d->kiojobs.end()) {
                QByteArray qba;
                qba = QByteArray::fromRawData(qb.data() + index, qb.size() - index - 1);
                it.value()->data(qba);
                qba = QByteArray::fromRawData(qb.data() + index, qb.size() - index - 1);
            }
            kDebug(6100) << "PutData(" << ID_num << ") size=" << qb.size() - index;
        } else
            kError(6100) << "PutData error " << ok << endl;
        return;
    }
    //now parse out the arguments
    while( index < qb_size )
    {
        int sep_pos = qb.indexOf( (char) 0, index );
        if (sep_pos < 0) {
            kError(6100) << "Missing separation byte" << endl;
            sep_pos = qb_size;
        }
        //kDebug(6100) << "KJavaAppletServer::slotJavaRequest: "<< QString::fromLocal8Bit( qb.data() + index, sep_pos - index );
        args.append( QString::fromLocal8Bit( qb.data() + index, sep_pos - index ) );
        index = sep_pos + 1; //skip the sep
    }
    //here I should find the context and call the method directly
    //instead of emitting signals
    switch( cmd_code )
    {
        case KJAS_SHOW_DOCUMENT:
            cmd = QLatin1String( "showdocument" );
            break;

        case KJAS_SHOW_URLINFRAME:
            cmd = QLatin1String( "showurlinframe" );
            break;

        case KJAS_SHOW_STATUS:
            cmd = QLatin1String( "showstatus" );
            break;

        case KJAS_RESIZE_APPLET:
            cmd = QLatin1String( "resizeapplet" );
            break;

        case KJAS_GET_URLDATA:
            if (ok && !args.empty() ) {
                d->kiojobs.insert(ID_num, new KJavaDownloader(ID_num, args.first()));
                kDebug(6100) << "GetURLData(" << ID_num << ") url=" << args.first();
            } else
                kError(6100) << "GetURLData error " << ok << " args:" << args.size() << endl;
            return;
        case KJAS_PUT_URLDATA:
            if (ok && !args.empty()) {
                KJavaUploader* const job = new KJavaUploader(ID_num, args.first());
                d->kiojobs.insert(ID_num, job);
                job->start();
                kDebug(6100) << "PutURLData(" << ID_num << ") url=" << args.first();
            } else
                kError(6100) << "PutURLData error " << ok << " args:" << args.size() << endl;
            return;
        case KJAS_DATA_COMMAND:
            if (ok && !args.empty()) {
                const int cmd = args.first().toInt( &ok );
                KIOJobMap::iterator it = d->kiojobs.find( ID_num );
                if (ok && it != d->kiojobs.end())
                    it.value()->jobCommand( cmd );
                kDebug(6100) << "KIO Data command: " << ID_num << " " << args.first();
            } else
                kError(6100) << "KIO Data command error " << ok << " args:" << args.size() << endl;
            return;
        case KJAS_JAVASCRIPT_EVENT:
            cmd = QLatin1String( "JS_Event" );

            if(!args.empty()) {
                 kDebug(6100) << "Javascript request: "<< contextID
                              << " code: " << args[0] << endl;
            } else {
                kError(6100) << "Expected args not to be empty!" << endl;
            }

            break;
        case KJAS_GET_MEMBER:
        case KJAS_PUT_MEMBER:
        case KJAS_CALL_MEMBER: {
            if(!args.empty()) {
                const int ticket = args[0].toInt();
                JSStack::iterator it = d->jsstack.find(ticket);
                if (it != d->jsstack.end()) {
                    kDebug(6100) << "slotJavaRequest: " << ticket;
                    args.pop_front();
                    it.value()->args.operator=(args); // just in case ..
                    it.value()->ready = true;
                    it.value()->exit = true;
                } else
                    kDebug(6100) << "Error: Missed return member data";
            } else {
                kError(6100) << "Expected args not to be empty!" << endl;
            }
            return;
        }
        case KJAS_AUDIOCLIP_PLAY:
            cmd = QLatin1String( "audioclip_play" );
            if(!args.empty())
                kDebug(6100) << "Audio Play: url=" << args[0];
            else
                kError(6100) << "Expected args not to be empty!" << endl;

            break;
        case KJAS_AUDIOCLIP_LOOP:
            cmd = QLatin1String( "audioclip_loop" );
            if(!args.empty())
                kDebug(6100) << "Audio Loop: url=" << args[0];
            else
                kError(6100) << "Expected args not to be empty!" << endl;

            break;
        case KJAS_AUDIOCLIP_STOP:
            cmd = QLatin1String( "audioclip_stop" );
            if(!args.empty())
                kDebug(6100) << "Audio Stop: url=" << args[0];
            else
                kError(6100) << "Expected args not to be empty!" << endl;

            break;
        case KJAS_APPLET_STATE:
            if(args.size() > 1)
                kDebug(6100) << "Applet State Notification for Applet " << args[0] << ". New state=" << args[1];
            else
                kError(6100) << "Expected args not to be empty!" << endl;

            cmd = QLatin1String( "AppletStateNotification" );
            break;
        case KJAS_APPLET_FAILED:
            if(args.size() > 1)
                kDebug(6100) << "Applet " << args[0] << " Failed: " << args[1];
            else
                kError(6100) << "Expected args not to be empty!" << endl;

            cmd = QLatin1String( "AppletFailed" );
            break;
        case KJAS_SECURITY_CONFIRM: {
            if (KSSL::doesSSLWork() && !d->kssl)
                d->kssl = new KSSL;
            QStringList sl;
            QString answer( "invalid" );

            if (!d->kssl) {
                answer = "nossl";
            } else if (args.size() > 2) {
                const int certsnr = args[1].toInt();
                Q_ASSERT(args.size() > certsnr + 1);
                QString text;
                QList<KSSLCertificate *> certs;
                for (int i = certsnr - 1; i >= 0; --i) {
                    const QByteArray &arg = args[i + 2].toAscii();
                    KSSLCertificate * cert = KSSLCertificate::fromString(arg.constData());
                    if (cert) {
                        certs.prepend(cert);
                        if (cert->isSigner())
                            text += i18n("Signed by (validation: %1)", KSSLCertificate::verifyText(cert->validate()));
                        else
                            text += i18n("Certificate (validation: %1)", KSSLCertificate::verifyText(cert->validate()));
                        text += "\n";
                        QString subject = cert->getSubject() + QChar('\n');
                        QRegExp reg(QString("/[A-Z]+="));
                        int pos = 0;
                        while ((pos = subject.indexOf(reg, pos)) > -1)
                            subject.replace(pos, 1, QString("\n    "));
                        text += subject.mid(1);
                    }
                }
                kDebug(6100) << "Security confirm " << args.first() << certs.count();
                if ( !certs.isEmpty() ) {
                    KSSLCertChain chain;
                    chain.setChain( certs );
                    if ( chain.isValid() )
                        answer = PermissionDialog( qApp->activeWindow() ).exec( text, args[0] );
                }
                qDeleteAll(certs);
            }
            sl.push_front( answer );
            sl.push_front( QString::number(ID_num) );
            process->send( KJAS_SECURITY_CONFIRM, sl );
            return;
        }
        default:
            return;
            break;
    }


    if( !ok )
    {
        kError(6100) << "could not parse out contextID to call command on" << endl;
        return;
    }

    KJavaAppletContext* const context = d->contexts[ ID_num ];
    if( context )
        context->processCmd( cmd, args );
    else if (cmd != "AppletStateNotification")
        kError(6100) << "no context object for this id" << endl;
}