You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
877 lines
26 KiB
877 lines
26 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
*
|
||
|
* Copyright (C) 2001-2003 George Staikos <staikos@kde.org>
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
|
||
12 years ago
|
#include "tdecertpart.h"
|
||
|
#include <tdeparts/genericfactory.h>
|
||
15 years ago
|
#include <kinstance.h>
|
||
12 years ago
|
#include <tdeaboutdata.h>
|
||
14 years ago
|
#include <tqframe.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
14 years ago
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqbutton.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqcombobox.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <kpassdlg.h>
|
||
|
#include <ksslall.h>
|
||
|
#include <kopenssl.h>
|
||
|
#include <ksslpemcallback.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
15 years ago
|
#include <kprocess.h>
|
||
14 years ago
|
#include <tqtabwidget.h>
|
||
15 years ago
|
#include <kseparator.h>
|
||
12 years ago
|
#include <tdelistview.h>
|
||
12 years ago
|
#include <tdeio/kmimemagic.h>
|
||
14 years ago
|
#include <tqmultilineedit.h>
|
||
|
#include <tqregexp.h>
|
||
15 years ago
|
#include <kcombobox.h>
|
||
12 years ago
|
#include <tdeparts/browserextension.h>
|
||
|
#include <tdeparts/browserinterface.h>
|
||
12 years ago
|
#include <tdeio/kservicetypefactory.h>
|
||
15 years ago
|
|
||
12 years ago
|
K_EXPORT_COMPONENT_FACTORY( libtdecertpart, KParts::GenericFactory<KCertPart> )
|
||
15 years ago
|
|
||
|
|
||
12 years ago
|
KX509Item::KX509Item(TDEListViewItem *parent, KSSLCertificate *x) :
|
||
|
TDEListViewItem(parent, 0L)
|
||
15 years ago
|
{
|
||
|
setup(x);
|
||
|
}
|
||
|
|
||
12 years ago
|
KX509Item::KX509Item(TDEListView *parent, KSSLCertificate *x) :
|
||
|
TDEListViewItem(parent)
|
||
15 years ago
|
{
|
||
|
setup(x);
|
||
|
}
|
||
|
|
||
|
void KX509Item::setup(KSSLCertificate *x) {
|
||
|
cert = x;
|
||
|
if (x) {
|
||
|
KSSLX509Map xm(x->getSubject());
|
||
14 years ago
|
TQString OU = "OU";
|
||
|
TQString CN = "CN";
|
||
15 years ago
|
OU = xm.getValue(OU);
|
||
|
CN = xm.getValue(CN);
|
||
14 years ago
|
OU.replace(TQRegExp("\n.*"), "");
|
||
|
CN.replace(TQRegExp("\n.*"), "");
|
||
15 years ago
|
|
||
|
if (OU.length() > 0) {
|
||
|
_prettyName = OU;
|
||
|
}
|
||
|
|
||
|
if (CN.length() > 0) {
|
||
|
if (_prettyName.length() > 0) {
|
||
|
_prettyName += " - ";
|
||
|
}
|
||
|
_prettyName += CN;
|
||
|
}
|
||
|
setText(0, _prettyName);
|
||
|
} else {
|
||
|
setText(0, i18n("Invalid certificate!"));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
KX509Item::~KX509Item()
|
||
|
{
|
||
|
delete cert;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
KPKCS12Item::KPKCS12Item(TDEListViewItem *parent, KSSLPKCS12 *x) :
|
||
|
TDEListViewItem(parent, 0L)
|
||
15 years ago
|
{
|
||
|
cert = x;
|
||
|
if (x) {
|
||
|
KSSLX509Map xm(x->getCertificate()->getSubject());
|
||
14 years ago
|
TQString CN = "CN";
|
||
15 years ago
|
CN = xm.getValue(CN);
|
||
14 years ago
|
CN.replace(TQRegExp("\n.*"), "");
|
||
15 years ago
|
_prettyName = CN;
|
||
|
setText(0, _prettyName);
|
||
|
} else {
|
||
|
setText(0, i18n("Invalid certificate!"));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
KPKCS12Item::~KPKCS12Item()
|
||
|
{
|
||
|
delete cert;
|
||
|
}
|
||
|
|
||
|
|
||
|
class KCertPartPrivate {
|
||
|
public:
|
||
|
KParts::BrowserExtension *browserExtension;
|
||
|
};
|
||
|
|
||
|
|
||
14 years ago
|
KCertPart::KCertPart(TQWidget *parentWidget, const char *widgetName,
|
||
14 years ago
|
TQObject *parent, const char *name,
|
||
|
const TQStringList & /*args*/ )
|
||
15 years ago
|
: KParts::ReadWritePart(parent, name) {
|
||
12 years ago
|
TDEInstance *instance = new TDEInstance("KCertPart");
|
||
14 years ago
|
TQGridLayout *grid;
|
||
15 years ago
|
setInstance(instance);
|
||
|
|
||
|
|
||
|
_signers = new KSSLSigners;
|
||
|
// This is a bit confusing now. Here's how it works:
|
||
|
// We create a _frame and split it left/right
|
||
|
// Then we add the ListView to the left and create
|
||
|
// a new frame on the right. We set the main widget
|
||
|
// on the right.
|
||
|
|
||
|
_p12 = NULL;
|
||
|
_ca = NULL;
|
||
|
_silentImport = false;
|
||
|
d = new KCertPartPrivate;
|
||
|
d->browserExtension = new KParts::BrowserExtension(this);
|
||
|
|
||
14 years ago
|
_frame = new TQFrame(parentWidget, widgetName);
|
||
15 years ago
|
setWidget(_frame);
|
||
|
|
||
14 years ago
|
_baseGrid = new TQGridLayout(_frame, 15, 9, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint());
|
||
|
|
||
12 years ago
|
_sideList = new TDEListView(_frame);
|
||
15 years ago
|
_sideList->setRootIsDecorated(true);
|
||
|
_sideList->addColumn(i18n("Certificates"));
|
||
12 years ago
|
_parentCA = new TDEListViewItem(_sideList, i18n("Signers"));
|
||
15 years ago
|
_parentCA->setExpandable(true);
|
||
|
_sideList->setOpen(_parentCA, true);
|
||
12 years ago
|
_parentP12 = new TDEListViewItem(_sideList, i18n("Client"));
|
||
15 years ago
|
_parentP12->setExpandable(true);
|
||
|
_sideList->setOpen(_parentP12, true);
|
||
|
|
||
|
_baseGrid->addMultiCellWidget(_sideList, 0, 13, 0, 1);
|
||
|
|
||
14 years ago
|
_importAll = new TQPushButton(i18n("Import &All"), _frame);
|
||
15 years ago
|
_baseGrid->addMultiCellWidget(_importAll, 14, 14, 0, 1);
|
||
14 years ago
|
connect(_importAll, TQT_SIGNAL(clicked()), TQT_SLOT(slotImportAll()));
|
||
15 years ago
|
|
||
|
|
||
|
|
||
|
//------------------------------------------------------------------------
|
||
|
// The PKCS widget
|
||
|
//------------------------------------------------------------------------
|
||
14 years ago
|
_pkcsFrame = new TQFrame(_frame);
|
||
15 years ago
|
|
||
14 years ago
|
grid = new TQGridLayout(_pkcsFrame, 13, 6, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
13 years ago
|
grid->addMultiCellWidget(new TQLabel(i18n("TDE Secure Certificate Import"), _pkcsFrame), 0, 0, 0, 5);
|
||
14 years ago
|
grid->addWidget(new TQLabel(i18n("Chain:"), _pkcsFrame), 1, 0);
|
||
15 years ago
|
_p12_chain = new KComboBox(_pkcsFrame);
|
||
|
grid->addMultiCellWidget(_p12_chain, 1, 1, 1, 4);
|
||
14 years ago
|
connect(_p12_chain, TQT_SIGNAL(activated(int)), TQT_SLOT(slotChain(int)));
|
||
15 years ago
|
|
||
14 years ago
|
grid->addWidget(new TQLabel(i18n("Subject:"), _pkcsFrame), 2, 0);
|
||
|
grid->addWidget(new TQLabel(i18n("Issued by:"), _pkcsFrame), 2, 3);
|
||
|
_p12_subject = KSSLInfoDlg::certInfoWidget(_pkcsFrame, TQString(""));
|
||
|
_p12_issuer = KSSLInfoDlg::certInfoWidget(_pkcsFrame, TQString(""));
|
||
15 years ago
|
grid->addMultiCellWidget(_p12_subject, 3, 6, 0, 2);
|
||
|
grid->addMultiCellWidget(_p12_issuer, 3, 6, 3, 5);
|
||
|
|
||
14 years ago
|
grid->addWidget(new TQLabel(i18n("File:"), _pkcsFrame), 7, 0);
|
||
|
_p12_filenameLabel = new TQLabel("", _pkcsFrame);
|
||
15 years ago
|
grid->addWidget(_p12_filenameLabel, 7, 1);
|
||
14 years ago
|
grid->addWidget(new TQLabel(i18n("File format:"), _pkcsFrame), 7, 3);
|
||
|
grid->addWidget(new TQLabel("PKCS#12", _pkcsFrame), 7, 4);
|
||
15 years ago
|
|
||
|
|
||
|
//
|
||
|
// Make the first tab
|
||
|
//
|
||
14 years ago
|
_tabs = new TQTabWidget(_pkcsFrame);
|
||
15 years ago
|
grid->addMultiCellWidget(_tabs, 8, 12, 0, 5);
|
||
|
|
||
14 years ago
|
TQFrame *tab = new TQFrame(_pkcsFrame);
|
||
|
TQGridLayout *tabGrid = new TQGridLayout(tab, 4, 5, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("State:"), tab), 0, 0);
|
||
|
_p12_certState = new TQLabel("", tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_p12_certState, 0, 0, 1, 4);
|
||
|
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Valid from:"), tab), 1, 0);
|
||
|
_p12_validFrom = new TQLabel("", tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_p12_validFrom, 1, 1, 1, 4);
|
||
|
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Valid until:"), tab), 2, 0);
|
||
|
_p12_validUntil = new TQLabel("", tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_p12_validUntil, 2, 2, 1, 4);
|
||
|
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Serial number:"), tab), 3, 0);
|
||
|
_p12_serialNum = new TQLabel("", tab);
|
||
15 years ago
|
tabGrid->addWidget(_p12_serialNum, 3, 1);
|
||
|
_tabs->addTab(tab, i18n("State"));
|
||
|
|
||
|
|
||
|
//
|
||
|
// Make the second tab
|
||
|
//
|
||
14 years ago
|
tab = new TQFrame(_pkcsFrame);
|
||
|
tabGrid = new TQGridLayout(tab, 4, 5, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("MD5 digest:"), tab), 0, 0);
|
||
|
_p12_digest = new TQLabel(tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_p12_digest, 0, 0, 1, 4);
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Signature:"), tab), 1, 0);
|
||
|
_p12_sig = new TQMultiLineEdit(tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_p12_sig, 1, 3, 1, 4);
|
||
|
_p12_sig->setReadOnly(true);
|
||
|
|
||
|
_tabs->addTab(tab, i18n("Signature"));
|
||
|
|
||
|
|
||
|
//
|
||
|
// Make the third tab
|
||
|
//
|
||
14 years ago
|
tab = new TQFrame(_pkcsFrame);
|
||
|
tabGrid = new TQGridLayout(tab, 4, 5, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Public key:"), tab), 0, 0);
|
||
|
_p12_pubkey = new TQMultiLineEdit(tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_p12_pubkey, 0, 3, 1, 4);
|
||
|
_p12_pubkey->setReadOnly(true);
|
||
|
|
||
|
|
||
|
_tabs->addTab(tab, i18n("Public Key"));
|
||
|
|
||
|
_pkcsFrame->hide();
|
||
|
|
||
|
//------------------------------------------------------------------------
|
||
|
// The X509 widget
|
||
|
//------------------------------------------------------------------------
|
||
|
// Note: this is almost identical to the above, but I duplicate it for
|
||
|
// the simple reason that the above has potential to display much
|
||
|
// more information, and this one has potential to display different
|
||
|
// information.
|
||
14 years ago
|
_x509Frame = new TQFrame(_frame);
|
||
15 years ago
|
|
||
14 years ago
|
grid = new TQGridLayout(_x509Frame, 12, 6, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
13 years ago
|
grid->addMultiCellWidget(new TQLabel(i18n("TDE Secure Certificate Import"), _x509Frame), 0, 0, 0, 5);
|
||
15 years ago
|
|
||
14 years ago
|
grid->addWidget(new TQLabel(i18n("Subject:"), _x509Frame), 1, 0);
|
||
|
grid->addWidget(new TQLabel(i18n("Issued by:"), _x509Frame), 1, 3);
|
||
|
_ca_subject = KSSLInfoDlg::certInfoWidget(_x509Frame, TQString(""));
|
||
|
_ca_issuer = KSSLInfoDlg::certInfoWidget(_x509Frame, TQString(""));
|
||
15 years ago
|
grid->addMultiCellWidget(_ca_subject, 2, 5, 0, 2);
|
||
|
grid->addMultiCellWidget(_ca_issuer, 2, 5, 3, 5);
|
||
|
|
||
14 years ago
|
grid->addWidget(new TQLabel(i18n("File:"), _x509Frame), 6, 0);
|
||
|
_ca_filenameLabel = new TQLabel("", _x509Frame);
|
||
15 years ago
|
grid->addWidget(_ca_filenameLabel, 6, 1);
|
||
14 years ago
|
grid->addWidget(new TQLabel(i18n("File format:"), _x509Frame), 6, 3);
|
||
|
grid->addWidget(new TQLabel("PEM or DER Encoded X.509", _x509Frame), 6, 4);
|
||
15 years ago
|
|
||
|
|
||
|
//
|
||
|
// Make the first tab
|
||
|
//
|
||
14 years ago
|
_tabs = new TQTabWidget(_x509Frame);
|
||
15 years ago
|
grid->addMultiCellWidget(_tabs, 7, 11, 0, 5);
|
||
|
|
||
14 years ago
|
tab = new TQFrame(_x509Frame);
|
||
|
tabGrid = new TQGridLayout(tab, 4, 5, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("State:"), tab), 0, 0);
|
||
|
_ca_certState = new TQLabel("", tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_ca_certState, 0, 0, 1, 4);
|
||
|
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Valid from:"), tab), 1, 0);
|
||
|
_ca_validFrom = new TQLabel("", tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_ca_validFrom, 1, 1, 1, 4);
|
||
|
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Valid until:"), tab), 2, 0);
|
||
|
_ca_validUntil = new TQLabel("", tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_ca_validUntil, 2, 2, 1, 4);
|
||
|
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Serial number:"), tab), 3, 0);
|
||
|
_ca_serialNum = new TQLabel("", tab);
|
||
15 years ago
|
tabGrid->addWidget(_ca_serialNum, 3, 1);
|
||
|
_tabs->addTab(tab, i18n("State"));
|
||
|
|
||
|
|
||
|
//
|
||
|
// Make the second tab
|
||
|
//
|
||
14 years ago
|
tab = new TQFrame(_x509Frame);
|
||
|
tabGrid = new TQGridLayout(tab, 4, 5, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("MD5 digest:"), tab), 0, 0);
|
||
|
_ca_digest = new TQLabel(tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_ca_digest, 0, 0, 1, 4);
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Signature:"), tab), 1, 0);
|
||
|
_ca_sig = new TQMultiLineEdit(tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_ca_sig, 1, 3, 1, 4);
|
||
|
_ca_sig->setReadOnly(true);
|
||
|
|
||
|
_tabs->addTab(tab, i18n("Signature"));
|
||
|
|
||
|
|
||
|
//
|
||
|
// Make the third tab
|
||
|
//
|
||
14 years ago
|
tab = new TQFrame(_x509Frame);
|
||
|
tabGrid = new TQGridLayout(tab, 4, 5, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
14 years ago
|
tabGrid->addWidget(new TQLabel(i18n("Public key:"), tab), 0, 0);
|
||
|
_ca_pubkey = new TQMultiLineEdit(tab);
|
||
15 years ago
|
tabGrid->addMultiCellWidget(_ca_pubkey, 0, 3, 1, 4);
|
||
|
_ca_pubkey->setReadOnly(true);
|
||
|
|
||
|
|
||
|
_tabs->addTab(tab, i18n("Public Key"));
|
||
|
|
||
|
_x509Frame->hide();
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//------------------------------------------------------------------------
|
||
|
// The blank widget
|
||
|
//------------------------------------------------------------------------
|
||
14 years ago
|
_blankFrame = new TQFrame(_frame);
|
||
|
grid = new TQGridLayout(_blankFrame, 1, 1, KDialog::marginHint(),
|
||
15 years ago
|
KDialog::spacingHint() );
|
||
13 years ago
|
grid->addMultiCellWidget(new TQLabel(i18n("TDE Secure Certificate Import"), _blankFrame), 0, 0, 0, 0);
|
||
15 years ago
|
_blankFrame->show();
|
||
|
|
||
|
|
||
|
|
||
|
//
|
||
|
// Finish it off
|
||
|
//
|
||
|
_baseGrid->addMultiCellWidget(new KSeparator(KSeparator::HLine, _frame), 13, 13, 2, 8);
|
||
14 years ago
|
_launch = new TQPushButton(i18n("&Crypto Manager..."), _frame);
|
||
|
_import = new TQPushButton(i18n("&Import"), _frame);
|
||
|
_save = new TQPushButton(i18n("&Save..."), _frame);
|
||
|
_done = new TQPushButton(i18n("&Done"), _frame);
|
||
15 years ago
|
_baseGrid->addMultiCellWidget(_launch, 14, 14, 4, 5);
|
||
|
_baseGrid->addWidget(_import, 14, 6);
|
||
|
_baseGrid->addWidget(_save, 14, 7);
|
||
|
_baseGrid->addWidget(_done, 14, 8);
|
||
14 years ago
|
connect(_launch, TQT_SIGNAL(clicked()), TQT_SLOT(slotLaunch()));
|
||
|
connect(_import, TQT_SIGNAL(clicked()), TQT_SLOT(slotImport()));
|
||
|
connect(_save, TQT_SIGNAL(clicked()), TQT_SLOT(slotSave()));
|
||
|
connect(_done, TQT_SIGNAL(clicked()), TQT_SLOT(slotDone()));
|
||
15 years ago
|
_import->setEnabled(false);
|
||
|
_save->setEnabled(false);
|
||
|
|
||
|
|
||
|
|
||
|
_baseGrid->addMultiCellWidget(_pkcsFrame, 0, 12, 2, 8);
|
||
|
_baseGrid->addMultiCellWidget(_x509Frame, 0, 12, 2, 8);
|
||
|
_baseGrid->addMultiCellWidget(_blankFrame, 0, 12, 2, 8);
|
||
|
|
||
14 years ago
|
connect(_sideList, TQT_SIGNAL(selectionChanged(TQListViewItem*)),
|
||
|
this, TQT_SLOT(slotSelectionChanged(TQListViewItem*)));
|
||
15 years ago
|
setReadWrite(true);
|
||
|
}
|
||
|
|
||
|
|
||
|
KCertPart::~KCertPart() {
|
||
|
delete _signers;
|
||
|
delete d->browserExtension;
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCertPart::setReadWrite(bool rw) {
|
||
|
if (!rw) {
|
||
|
_import->setEnabled(false);
|
||
|
_save->setEnabled(false);
|
||
|
}
|
||
|
KParts::ReadWritePart::setReadWrite(rw);
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KCertPart::saveFile() {
|
||
|
if (_p12) {
|
||
14 years ago
|
TQString certFile = KFileDialog::getSaveFileName(TQString::null, "application/x-pkcs12");
|
||
15 years ago
|
if (certFile.isEmpty())
|
||
|
return false;
|
||
|
|
||
|
if (!_p12->toFile(certFile)) {
|
||
|
KMessageBox::sorry(_frame, i18n("Save failed."), i18n("Certificate Import"));
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
} else if (_ca) {
|
||
14 years ago
|
TQString certFile = KFileDialog::getSaveFileName(TQString::null, "application/x-x509-ca-cert");
|
||
15 years ago
|
if (certFile.isEmpty())
|
||
|
return false;
|
||
|
|
||
14 years ago
|
TQByteArray enc;
|
||
15 years ago
|
if (certFile.endsWith("der") || certFile.endsWith("crt")) {
|
||
|
enc = _ca->toDer();
|
||
|
} else if (certFile.endsWith("netscape")) {
|
||
|
enc = _ca->toNetscape();
|
||
|
} else {
|
||
|
enc = _ca->toPem();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQFile of(certFile);
|
||
15 years ago
|
|
||
|
if (!of.open(IO_WriteOnly) || (unsigned)of.writeBlock(enc) != enc.size()) {
|
||
|
KMessageBox::sorry(_frame, i18n("Save failed."), i18n("Certificate Import"));
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
of.flush();
|
||
|
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KCertPart::openFile() {
|
||
|
#ifndef HAVE_SSL
|
||
13 years ago
|
KMessageBox::sorry(_frame, i18n("You do not seem to have compiled TDE with SSL support."), i18n("Certificate Import"));
|
||
15 years ago
|
return false;
|
||
|
#else
|
||
|
|
||
14 years ago
|
if (TQFileInfo(m_file).size() == 0) {
|
||
15 years ago
|
KMessageBox::sorry(_frame, i18n("Certificate file is empty."), i18n("Certificate Import"));
|
||
|
return false;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString whatType = d->browserExtension->urlArgs().serviceType;
|
||
15 years ago
|
//whatType = KMimeType::findByURL(m_url,0,true)->name();
|
||
|
if (whatType.isEmpty())
|
||
14 years ago
|
whatType = KServiceTypeFactory::self()->findFromPattern(m_file)->name();
|
||
15 years ago
|
|
||
|
/*
|
||
14 years ago
|
TQString blah = "file: " + m_file
|
||
15 years ago
|
+ "\nurl: " + m_url.url()
|
||
|
+ "\nserviceType: " + d->browserExtension->urlArgs().serviceType
|
||
14 years ago
|
+ "\nfactory: " + KServiceTypeFactory::self()->findFromPattern(m_file)->name()
|
||
15 years ago
|
+ "\nmimeType: " + KMimeType::findByURL(m_url)->name();
|
||
|
KMessageBox::information(_frame, blah, "ssl");
|
||
|
*/
|
||
|
|
||
|
|
||
|
emit completed();
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////////
|
||
|
// x-pkcs12 loading
|
||
|
/////////////////////////////////////////////////////////////////////////////
|
||
|
if (whatType == "application/x-pkcs12") {
|
||
14 years ago
|
TQCString pass;
|
||
15 years ago
|
_p12 = KSSLPKCS12::loadCertFile(m_file);
|
||
|
|
||
|
while (!_p12) {
|
||
|
// try prompting for a password.
|
||
|
int rc = KPasswordDialog::getPassword(pass, i18n("Certificate Password"));
|
||
|
if (rc != KPasswordDialog::Accepted) break;
|
||
|
|
||
14 years ago
|
_p12 = KSSLPKCS12::loadCertFile(m_file, TQString(pass));
|
||
15 years ago
|
|
||
|
if (!_p12) {
|
||
|
rc = KMessageBox::warningContinueCancel(_frame, i18n("The certificate file could not be loaded. Try a different password?"), i18n("Certificate Import"),i18n("Try Different"));
|
||
|
if (rc == KMessageBox::Continue) continue;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!_p12) return false;
|
||
|
|
||
|
new KPKCS12Item(_parentP12, _p12);
|
||
|
_p12 = NULL;
|
||
|
return true;
|
||
|
/////////////////////////////////////////////////////////////////////////////
|
||
|
// x-509-ca-cert loading
|
||
|
/////////////////////////////////////////////////////////////////////////////
|
||
|
} else if (whatType == "application/x-x509-ca-cert" ||
|
||
|
whatType == "application/binary-certificate") {
|
||
|
FILE *fp;
|
||
|
bool isPEM = false;
|
||
|
|
||
|
_ca_filenameLabel->setText(m_file);
|
||
|
|
||
|
///////////// UGLY HACK TO GET AROUND OPENSSL PROBLEMS ///////////
|
||
|
if (whatType == "application/x-x509-ca-cert") {
|
||
|
// Check if it is PEM or not
|
||
14 years ago
|
TQFile qf(m_file);
|
||
15 years ago
|
qf.open(IO_ReadOnly);
|
||
14 years ago
|
TQByteArray theFile = qf.readAll();
|
||
15 years ago
|
qf.close();
|
||
|
|
||
|
const char *signature = "-----BEGIN CERTIFICATE-----";
|
||
|
theFile[(uint)(qf.size()-1)] = 0;
|
||
13 years ago
|
isPEM = (TQCString(theFile.data()).find(signature) >= 0);
|
||
15 years ago
|
}
|
||
|
|
||
|
fp = fopen(m_file.local8Bit(), "r");
|
||
|
if (!fp) {
|
||
|
KMessageBox::sorry(_frame, i18n("This file cannot be opened."), i18n("Certificate Import"));
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
kdDebug() << "Reading in a file in "
|
||
|
<< (isPEM ? "PEM" : "DER")
|
||
|
<< " format." << endl;
|
||
|
*/
|
||
|
|
||
|
if (!isPEM) {
|
||
|
X509 *dx = KOSSL::self()->X509_d2i_fp(fp, NULL);
|
||
|
|
||
|
if (dx) {
|
||
|
KSSLCertificate *xc = KSSLCertificate::fromX509(dx);
|
||
|
if (xc) {
|
||
|
if (xc->x509V3Extensions().certTypeCA())
|
||
|
new KX509Item(_parentCA, xc);
|
||
|
else
|
||
|
new KX509Item(_sideList, xc);
|
||
|
fclose(fp);
|
||
|
return true;
|
||
|
}
|
||
|
KOSSL::self()->X509_free(dx);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
STACK_OF(X509_INFO) *sx5i = KOSSL::self()->PEM_X509_INFO_read(fp, NULL, KSSLPemCallback, NULL);
|
||
|
|
||
|
if (!sx5i) {
|
||
|
KMessageBox::sorry(_frame, i18n("This file cannot be opened."), i18n("Certificate Import"));
|
||
|
fclose(fp);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
_ca_filenameLabel->setText(m_file);
|
||
8 years ago
|
for (int i = 0; i < KOSSL::self()->OPENSSL_sk_num(sx5i); i++) {
|
||
|
X509_INFO* x5i = reinterpret_cast<X509_INFO*>(KOSSL::self()->OPENSSL_sk_value(sx5i, i));
|
||
15 years ago
|
if (x5i->x_pkey && x5i->x509) { // a personal cert (like PKCS12)
|
||
|
KSSLCertificate *xc = KSSLCertificate::fromX509(x5i->x509);
|
||
|
new KX509Item(_sideList, xc);
|
||
|
} else if (x5i->x509) { // something else - maybe a CA file
|
||
|
KSSLCertificate *xc = KSSLCertificate::fromX509(x5i->x509);
|
||
|
if (xc->x509V3Extensions().certTypeCA())
|
||
|
new KX509Item(_parentCA, xc);
|
||
|
else new KX509Item(_sideList, xc);
|
||
|
} else if (x5i->crl) { // a crl
|
||
|
kdDebug() << "Found a CRL..." << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
KOSSL::self()->OPENSSL_sk_free(sx5i);
|
||
15 years ago
|
|
||
|
fclose(fp);
|
||
|
return true;
|
||
|
/////////////////////////////////////////////////////////////////////////////
|
||
|
// Dunno how to load this
|
||
|
/////////////////////////////////////////////////////////////////////////////
|
||
|
} else {
|
||
14 years ago
|
TQString emsg = i18n("I do not know how to handle this type of file.") + "\n" + whatType;
|
||
15 years ago
|
KMessageBox::sorry(_frame, emsg, i18n("Certificate Import"));
|
||
|
return false;
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCertPart::displayPKCS12() {
|
||
|
KSSLCertificate *xc = _p12->getCertificate();
|
||
|
_p12_filenameLabel->setText(m_file);
|
||
|
displayPKCS12Cert(xc);
|
||
|
_p12_certState->setText(KSSLCertificate::verifyText(_p12->validate()));
|
||
|
|
||
|
// Set the chain if it's there
|
||
|
if (xc->chain().depth() > 1) {
|
||
14 years ago
|
TQPtrList<KSSLCertificate> cl = xc->chain().getChain();
|
||
15 years ago
|
int cnt = 0;
|
||
|
_p12_chain->setEnabled(true);
|
||
|
_p12_chain->clear();
|
||
|
_p12_chain->insertItem(i18n("0 - Site Certificate"));
|
||
|
for (KSSLCertificate *c = cl.first(); c != 0; c = cl.next()) {
|
||
|
KSSLX509Map map(c->getSubject());
|
||
14 years ago
|
_p12_chain->insertItem(TQString::number(++cnt)+" - "+map.getValue("CN"));
|
||
15 years ago
|
}
|
||
|
_p12_chain->setCurrentItem(0);
|
||
|
} else {
|
||
|
_p12_chain->clear();
|
||
|
_p12_chain->setEnabled(false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCertPart::displayCACert(KSSLCertificate *c) {
|
||
|
// We have the file, lets work with it.
|
||
|
_ca_subject->setValues(c->getSubject());
|
||
|
_ca_issuer->setValues(c->getIssuer());
|
||
|
|
||
|
// Set the valid period
|
||
14 years ago
|
TQPalette cspl = _ca_validFrom->palette();
|
||
13 years ago
|
if (TQDateTime::currentDateTime() < c->getQDTNotBefore()) {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
|
||
15 years ago
|
} else {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
|
||
15 years ago
|
}
|
||
|
_ca_validFrom->setPalette(cspl);
|
||
|
_ca_validFrom->setText(c->getNotBefore());
|
||
|
|
||
|
cspl = _ca_validUntil->palette();
|
||
13 years ago
|
if (TQDateTime::currentDateTime() > c->getQDTNotAfter()) {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
|
||
15 years ago
|
} else {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
|
||
15 years ago
|
}
|
||
|
_ca_validUntil->setPalette(cspl);
|
||
|
_ca_validUntil->setText(c->getNotAfter());
|
||
|
|
||
|
_ca_serialNum->setText(c->getSerialNumber());
|
||
|
cspl = _ca_certState->palette();
|
||
|
if (!c->isValid()) {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
|
||
15 years ago
|
} else {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
|
||
15 years ago
|
}
|
||
|
_ca_certState->setPalette(cspl);
|
||
|
_ca_certState->setText(KSSLCertificate::verifyText(c->validate()));
|
||
|
|
||
|
_ca_pubkey->setText(c->getPublicKeyText());
|
||
|
_ca_digest->setText(c->getMD5DigestText());
|
||
|
_ca_sig->setText(c->getSignatureText());
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void KCertPart::displayPKCS12Cert(KSSLCertificate *c) {
|
||
|
// We have the file, lets work with it.
|
||
|
_p12_subject->setValues(c->getSubject());
|
||
|
_p12_issuer->setValues(c->getIssuer());
|
||
|
|
||
|
// Set the valid period
|
||
14 years ago
|
TQPalette cspl = _p12_validFrom->palette();
|
||
13 years ago
|
if (TQDateTime::currentDateTime() < c->getQDTNotBefore()) {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
|
||
15 years ago
|
} else {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
|
||
15 years ago
|
}
|
||
|
_p12_validFrom->setPalette(cspl);
|
||
|
_p12_validFrom->setText(c->getNotBefore());
|
||
|
|
||
|
cspl = _p12_validUntil->palette();
|
||
13 years ago
|
if (TQDateTime::currentDateTime() > c->getQDTNotAfter()) {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
|
||
15 years ago
|
} else {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
|
||
15 years ago
|
}
|
||
|
_p12_validUntil->setPalette(cspl);
|
||
|
_p12_validUntil->setText(c->getNotAfter());
|
||
|
|
||
|
_p12_serialNum->setText(c->getSerialNumber());
|
||
|
cspl = _p12_certState->palette();
|
||
|
if (!c->isValid()) {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(196,33,21));
|
||
15 years ago
|
} else {
|
||
14 years ago
|
cspl.setColor(TQColorGroup::Foreground, TQColor(42,153,59));
|
||
15 years ago
|
}
|
||
|
_p12_certState->setPalette(cspl);
|
||
|
_p12_certState->setText(KSSLCertificate::verifyText(c->validate()));
|
||
|
|
||
|
_p12_pubkey->setText(c->getPublicKeyText());
|
||
|
_p12_digest->setText(c->getMD5DigestText());
|
||
|
_p12_sig->setText(c->getSignatureText());
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void KCertPart::slotChain(int c) {
|
||
|
if (c == 0) {
|
||
|
displayPKCS12Cert(_p12->getCertificate());
|
||
|
_p12_certState->setText(KSSLCertificate::verifyText(_p12->validate()));
|
||
|
} else {
|
||
13 years ago
|
displayPKCS12Cert(_p12->getCertificate()->chain().getChain().at(c-1));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCertPart::slotImport() {
|
||
|
if (_p12) {
|
||
|
KSimpleConfig cfg("ksslcertificates", false);
|
||
|
|
||
|
if (cfg.hasGroup(_p12->getCertificate()->getSubject())) {
|
||
14 years ago
|
TQString msg = _curName + "\n" + i18n("A certificate with that name already exists. Are you sure that you wish to replace it?");
|
||
15 years ago
|
int rc= KMessageBox::warningContinueCancel(_frame, msg, i18n("Certificate Import"),i18n("Replace"));
|
||
|
if (rc == KMessageBox::Cancel) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
cfg.setGroup(_p12->getCertificate()->getSubject());
|
||
|
cfg.writeEntry("PKCS12Base64", _p12->toString());
|
||
|
cfg.writeEntry("Password", "");
|
||
|
cfg.sync();
|
||
|
if (!_silentImport)
|
||
11 years ago
|
KMessageBox::information(_frame, i18n("Certificate has been successfully imported into TDE.\nYou can manage your certificate settings from the Trinity Control Center."), i18n("Certificate Import"));
|
||
15 years ago
|
} else if (_ca) {
|
||
12 years ago
|
TDEConfig cfg("ksslcalist", true, false);
|
||
15 years ago
|
if (cfg.hasGroup(_ca->getSubject())) {
|
||
14 years ago
|
TQString msg = _curName + "\n" + i18n("A certificate with that name already exists. Are you sure that you wish to replace it?");
|
||
15 years ago
|
int rc= KMessageBox::warningContinueCancel(_frame, msg, i18n("Certificate Import"),i18n("Replace"));
|
||
|
if (rc == KMessageBox::Cancel) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
_signers->addCA(_ca->toString(),
|
||
|
_ca->x509V3Extensions().certTypeSSLCA(),
|
||
|
_ca->x509V3Extensions().certTypeEmailCA(),
|
||
|
_ca->x509V3Extensions().certTypeCodeCA());
|
||
|
if (!_silentImport)
|
||
|
_signers->regenerate();
|
||
|
|
||
|
if (!_silentImport)
|
||
11 years ago
|
KMessageBox::information(_frame, i18n("Certificate has been successfully imported into TDE.\nYou can manage your certificate settings from the Trinity Control Center."), i18n("Certificate Import"));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCertPart::slotSave() {
|
||
|
saveFile();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCertPart::slotDone() {
|
||
|
KParts::BrowserInterface *iface = d->browserExtension->browserInterface();
|
||
|
iface->callMethod("goHistory(int)", -1);
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCertPart::slotLaunch() {
|
||
|
KShellProcess p;
|
||
12 years ago
|
p << "tdecmshell" << "crypto";
|
||
12 years ago
|
p.start(TDEProcess::DontCare);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KCertPart::slotSelectionChanged(TQListViewItem *x) {
|
||
15 years ago
|
KX509Item *x5i = dynamic_cast<KX509Item*>(x);
|
||
|
KPKCS12Item *p12i = dynamic_cast<KPKCS12Item*>(x);
|
||
|
_p12 = NULL;
|
||
|
_ca = NULL;
|
||
13 years ago
|
if (x && x->parent() == _parentCA) {
|
||
15 years ago
|
if (!x5i) {
|
||
|
return;
|
||
|
}
|
||
|
x5i->cert->revalidate();
|
||
|
_blankFrame->hide();
|
||
|
_pkcsFrame->hide();
|
||
|
_x509Frame->show();
|
||
|
_ca = x5i->cert;
|
||
|
_import->setEnabled(true);
|
||
|
_save->setEnabled(true);
|
||
|
_curName = x5i->_prettyName;
|
||
|
displayCACert(_ca);
|
||
13 years ago
|
} else if (x && x->parent() == NULL && x->rtti() == 1) {
|
||
15 years ago
|
if (!x5i) {
|
||
|
return;
|
||
|
}
|
||
|
x5i->cert->revalidate();
|
||
|
_blankFrame->hide();
|
||
|
_pkcsFrame->hide();
|
||
|
_x509Frame->show();
|
||
|
_ca = x5i->cert;
|
||
|
_import->setEnabled(false);
|
||
|
_save->setEnabled(false);
|
||
|
_curName = x5i->_prettyName;
|
||
|
displayCACert(_ca);
|
||
13 years ago
|
} else if (x && x->parent() == _parentP12) {
|
||
15 years ago
|
if (!p12i) {
|
||
|
return;
|
||
|
}
|
||
|
p12i->cert->revalidate();
|
||
|
_blankFrame->hide();
|
||
|
_x509Frame->hide();
|
||
|
_pkcsFrame->show();
|
||
|
_p12 = p12i->cert;
|
||
|
_import->setEnabled(true);
|
||
|
_save->setEnabled(true);
|
||
|
_curName = p12i->_prettyName;
|
||
|
displayPKCS12();
|
||
|
} else {
|
||
|
_pkcsFrame->hide();
|
||
|
_x509Frame->hide();
|
||
|
_blankFrame->show();
|
||
|
_import->setEnabled(false);
|
||
|
_save->setEnabled(false);
|
||
|
_curName = "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCertPart::slotImportAll() {
|
||
|
KSSLPKCS12 *p12Save = _p12;
|
||
|
KSSLCertificate *caSave = _ca;
|
||
14 years ago
|
TQString curNameSave = _curName;
|
||
15 years ago
|
|
||
|
_p12 = NULL;
|
||
|
_ca = NULL;
|
||
|
_silentImport = true;
|
||
|
|
||
|
for (KPKCS12Item *t = dynamic_cast<KPKCS12Item*>(_parentP12->firstChild());
|
||
|
t;
|
||
|
t = dynamic_cast<KPKCS12Item*>(t->nextSibling())) {
|
||
|
if (t) {
|
||
|
_p12 = t->cert;
|
||
|
_curName = t->_prettyName;
|
||
|
}
|
||
|
slotImport();
|
||
|
}
|
||
|
_p12 = NULL;
|
||
|
|
||
|
for (KX509Item *t = dynamic_cast<KX509Item*>(_parentCA->firstChild());
|
||
|
t;
|
||
|
t = dynamic_cast<KX509Item*>(t->nextSibling())) {
|
||
|
if (t) {
|
||
|
_ca = t->cert;
|
||
|
_curName = t->_prettyName;
|
||
|
}
|
||
|
slotImport();
|
||
|
}
|
||
|
_ca = NULL;
|
||
|
|
||
|
_signers->regenerate();
|
||
|
_silentImport = false;
|
||
|
_p12 = p12Save;
|
||
|
_ca = caSave;
|
||
|
_curName = curNameSave;
|
||
11 years ago
|
KMessageBox::information(_frame, i18n("Certificates have been successfully imported into TDE.\nYou can manage your certificate settings from the Trinity Control Center."), i18n("Certificate Import"));
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
12 years ago
|
TDEAboutData *KCertPart::createAboutData()
|
||
15 years ago
|
{
|
||
12 years ago
|
return new TDEAboutData("KCertPart", I18N_NOOP("TDE Certificate Part"), "1.0");
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
#include "tdecertpart.moc"
|
||
15 years ago
|
|