summaryrefslogtreecommitdiffstats
path: root/kfile-plugins/cert
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch)
tree2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /kfile-plugins/cert
downloadtdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz
tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kfile-plugins/cert')
-rw-r--r--kfile-plugins/cert/Makefile.am22
-rw-r--r--kfile-plugins/cert/configure.in.in2
-rw-r--r--kfile-plugins/cert/kfile_cert.cpp161
-rw-r--r--kfile-plugins/cert/kfile_cert.desktop60
-rw-r--r--kfile-plugins/cert/kfile_cert.h42
5 files changed, 287 insertions, 0 deletions
diff --git a/kfile-plugins/cert/Makefile.am b/kfile-plugins/cert/Makefile.am
new file mode 100644
index 0000000..0c8c1be
--- /dev/null
+++ b/kfile-plugins/cert/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for cert file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kfile_cert.h
+
+kde_module_LTLIBRARIES = kfile_cert.la
+
+kfile_cert_la_SOURCES = kfile_cert.cpp
+kfile_cert_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kfile_cert_la_LIBADD = $(LIB_KSYCOCA)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) kfile_cert.cpp -o $(podir)/kfile_cert.pot
+
+services_DATA = kfile_cert.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kfile-plugins/cert/configure.in.in b/kfile-plugins/cert/configure.in.in
new file mode 100644
index 0000000..29f0193
--- /dev/null
+++ b/kfile-plugins/cert/configure.in.in
@@ -0,0 +1,2 @@
+KDE_CHECK_SSL
+AM_CONDITIONAL(include_kfileplugin_cert_SUBDIR, test "$have_ssl" = yes)
diff --git a/kfile-plugins/cert/kfile_cert.cpp b/kfile-plugins/cert/kfile_cert.cpp
new file mode 100644
index 0000000..78c20f5
--- /dev/null
+++ b/kfile-plugins/cert/kfile_cert.cpp
@@ -0,0 +1,161 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Leonid Zeitlin *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include <config.h>
+#include "kfile_cert.h"
+
+#include <kgenericfactory.h>
+#include <ksslcertificate.h>
+#include <ksslx509map.h>
+#include <kopenssl.h>
+//#include <kstandarddirs.h>
+//#include <kdebug.h>
+//#include <kio/global.h>
+
+#include <qdatetime.h>
+#include <qfile.h>
+#include <qcstring.h>
+//#include <qfileinfo.h>
+//#include <qdir.h>
+
+typedef KGenericFactory<CertPlugin> CertFactory;
+
+K_EXPORT_COMPONENT_FACTORY(kfile_cert, CertFactory("kfile-cert"))
+
+CertPlugin::CertPlugin(QObject *parent, const char *name, const QStringList &args)
+ : KFilePlugin(parent, name, args)
+{
+ //add the mimetype here - example:
+ //KFileMimeTypeInfo* info = addMimeTypeInfo( "text/html" );
+ KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-x509-ca-cert" );
+
+ // our new group
+ KFileMimeTypeInfo::GroupInfo* group = 0L;
+ KFileMimeTypeInfo::ItemInfo* item;
+
+ group = addGroupInfo(info, "certInfo", i18n("Certificate Information"));
+ item = addItemInfo(group, "ValidFrom", i18n("Valid From"), QVariant::DateTime);
+ item = addItemInfo(group, "ValidUntil", i18n("Valid Until"), QVariant::DateTime);
+ item = addItemInfo(group, "State", i18n("State"), QVariant::String);
+ item = addItemInfo(group, "SerialNo", i18n("Serial Number"), QVariant::String);
+
+ group = addGroupInfo(info, "certSubjectInfo", i18n("Subject"));
+ item = addItemInfo(group, "O", i18n("Organization"), QVariant::String);
+ item = addItemInfo(group, "OU", i18n("Organizational Unit"), QVariant::String);
+ item = addItemInfo(group, "L", i18n("Locality"), QVariant::String);
+ item = addItemInfo(group, "C", i18n("Country"), QVariant::String);
+ item = addItemInfo(group, "CN", i18n("Common Name"), QVariant::String);
+ item = addItemInfo(group, "E", i18n("Email"), QVariant::String);
+
+ group = addGroupInfo(info, "certIssuerInfo", i18n("Issuer"));
+ item = addItemInfo(group, "O", i18n("Organization"), QVariant::String);
+ item = addItemInfo(group, "OU", i18n("Organizational Unit"), QVariant::String);
+ item = addItemInfo(group, "L", i18n("Locality"), QVariant::String);
+ item = addItemInfo(group, "C", i18n("Country"), QVariant::String);
+ item = addItemInfo(group, "CN", i18n("Common Name"), QVariant::String);
+ item = addItemInfo(group, "E", i18n("Email"), QVariant::String);
+
+ //setUnit(item, KFileMimeTypeInfo::KiloBytes);
+
+ // strings are possible, too:
+ //addItemInfo(group, "Text", i18n("Document Type"), QVariant::String);
+}
+
+void CertPlugin::appendDNItems(KFileMetaInfoGroup &group, const QString &DN)
+{
+ KSSLX509Map map(DN);
+ QString value;
+ //QString dbg;
+ QStringList keys = group.supportedKeys();
+ QStringList::ConstIterator end = keys.end();
+ for (QStringList::ConstIterator it = keys.begin(); it != end; ++it) {
+ value = map.getValue(*it);
+ //dbg += *it + " = " + value + "; ";
+ if (!value.isNull()) appendItem(group, *it, value);
+ //appendItem(group, "CN", dbg);
+ }
+}
+
+static KSSLCertificate *readCertFromFile(const QString &path)
+{
+ KSSLCertificate *ret = NULL;
+
+ QFile file(path);
+ if (!file.open(IO_ReadOnly)) return NULL;
+ QByteArray file_data = file.readAll();
+ file.close();
+
+ QCString file_string = QCString(file_data.data(), file_data.size());
+ // try as is:
+ ret = KSSLCertificate::fromString(file_string);
+ if (ret) return ret;
+ // didn't work. Let's see if begin/end lines are there:
+ KOSSL::self()->ERR_clear_error();
+ const char *begin_line = "-----BEGIN CERTIFICATE-----\n";
+ const char *end_line = "\n-----END CERTIFICATE-----";
+ int begin_pos = file_string.find(begin_line);
+ if (begin_pos >= 0) {
+ begin_pos += strlen(begin_line);
+ int end_pos = file_string.find(end_line, begin_pos);
+ if (end_pos >= 0) {
+ // read the data between begin and end lines
+ QCString body = file_string.mid(begin_pos, end_pos - begin_pos);
+ ret = KSSLCertificate::fromString(body);
+ return ret; // even if it's NULL, we can't help it
+ }
+ }
+ // still didn't work. Assume the file was in DER (binary) encoding
+ unsigned char *p = (unsigned char*) file_data.data();
+ KOSSL::self()->ERR_clear_error();
+ X509 *x = KOSSL::self()->d2i_X509(NULL, &p, file_data.size());
+ if (x) {
+ ret = KSSLCertificate::fromX509(x);
+ KOSSL::self()->X509_free(x);
+ return ret;
+ }
+ else return NULL;
+}
+
+bool CertPlugin::readInfo(KFileMetaInfo& info, uint /*what*/)
+{
+ KSSLCertificate *cert = readCertFromFile(info.path());
+ if (cert) {
+ KFileMetaInfoGroup group = appendGroup(info, "certInfo");
+ appendItem(group, "ValidFrom", cert->getQDTNotBefore());
+ appendItem(group, "ValidUntil", cert->getQDTNotAfter());
+ appendItem(group, "State", KSSLCertificate::verifyText(cert->validate()));
+ appendItem(group, "SerialNo", cert->getSerialNumber());
+
+ group = appendGroup(info, "certSubjectInfo");
+ appendDNItems(group, cert->getSubject());
+
+ group = appendGroup(info, "certIssuerInfo");
+ appendDNItems(group, cert->getIssuer());
+
+ delete cert;
+ return true;
+ }
+ else {
+ KOSSL::self()->ERR_clear_error(); // don't leave errors behind
+ return false;
+ }
+}
+
+#include "kfile_cert.moc"
diff --git a/kfile-plugins/cert/kfile_cert.desktop b/kfile-plugins/cert/kfile_cert.desktop
new file mode 100644
index 0000000..a1571fd
--- /dev/null
+++ b/kfile-plugins/cert/kfile_cert.desktop
@@ -0,0 +1,60 @@
+[Desktop Entry]
+Type=Service
+Name=Certificate Info
+Name[bg]=Информация за удостоверение
+Name[br]=Titouroù diwar-benn an testeni
+Name[ca]=Informació del certificat
+Name[cs]=Informace o certifikátu
+Name[da]=Information om certifikat
+Name[de]=Information zum Zertifikat
+Name[el]=Πληροφορίες πιστοποιητικού
+Name[eo]=Atesta informo
+Name[es]=Información del certificado
+Name[et]=Sertifikaadi info
+Name[eu]=Ziurtagiriaren informazioa
+Name[fa]=اطلاعات گواهی‌نامه
+Name[fi]=Sertifikaatin tiedot
+Name[fr]=Informations sur le certificat
+Name[fy]=Sertifikaatynformaasje
+Name[ga]=Eolas faoin Teastas
+Name[gl]=Informacións do Certificado
+Name[hi]=प्रमाणपत्र जानकारी
+Name[hr]=Podaci potvrde
+Name[hu]=Tanúsítvány-jellemzők
+Name[is]=Upplýsingar um skírteini
+Name[it]=Informazioni del certificato
+Name[ja]=認証情報
+Name[ka]=სერტიფიკატის ინფორმაცია
+Name[kk]=Куәлік мәліметтері
+Name[km]=ព័ត៌មាន​វិញ្ញាបនបត្រ
+Name[lt]=Sertifikato informacija
+Name[mk]=Информации за сертификати
+Name[ms]=Maklumat Sijil
+Name[nb]=Sertifikatinformasjon
+Name[nds]=Zertifikaat-Informatschonen
+Name[ne]=प्रमाणपत्र सूचना
+Name[nl]=Certificaatinformatie
+Name[nn]=Informasjon om sertifikat
+Name[pa]=ਸਰਟੀਫਿਕੇਟ ਜਾਣਕਾਰੀ
+Name[pl]=Informacja o certyfikacie
+Name[pt]=Informações do Certificado
+Name[pt_BR]=Informações sobre Certificado
+Name[ru]=Информация о сертификате
+Name[sk]=Informácie o certifikáte
+Name[sl]=Informacija o certifikatu
+Name[sr]=Информације о сертификату
+Name[sr@Latn]=Informacije o sertifikatu
+Name[sv]=Information om certifikat
+Name[ta]=சான்றிதழ் தகவல்
+Name[tr]=Sertifika Bilgisi
+Name[uk]=Інформація про сертифікат
+Name[uz]=Sertifikat haqida maʼlumot
+Name[uz@cyrillic]=Сертификат ҳақида маълумот
+Name[vi]=Thông tin chứng nhận
+Name[zh_CN]=证书信息
+Name[zh_TW]=憑證資訊
+ServiceTypes=KFilePlugin
+X-KDE-Library=kfile_cert
+MimeType=application/x-x509-ca-cert
+PreferredGroups=certInfo,certSubjectInfo
+PreferredItems=State,CN,O,OU,L,C
diff --git a/kfile-plugins/cert/kfile_cert.h b/kfile-plugins/cert/kfile_cert.h
new file mode 100644
index 0000000..544ef39
--- /dev/null
+++ b/kfile-plugins/cert/kfile_cert.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Leonid Zeitlin *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef __KFILE_CERT_H__
+#define __KFILE_CERT_H__
+
+/**
+ * Note: For further information look into <$KDEDIR/include/kfilemetainfo.h>
+ */
+#include <kfilemetainfo.h>
+
+class QStringList;
+class QString;
+
+class CertPlugin: public KFilePlugin {
+ Q_OBJECT
+private:
+ void appendDNItems(KFileMetaInfoGroup &group, const QString &DN);
+public:
+ CertPlugin(QObject *parent, const char *name, const QStringList& args);
+ virtual bool readInfo(KFileMetaInfo& info, uint what);
+};
+
+#endif // __KFILE_CERT_H__
+