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.
400 lines
11 KiB
400 lines
11 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
*
|
||
|
* Copyright (C) 2000, 2001 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.
|
||
|
*/
|
||
|
|
||
|
|
||
|
#include "ksslcertificatecache.h"
|
||
|
#include "ksslcertchain.h"
|
||
|
#include "ksslcertificate.h"
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <dcopclient.h>
|
||
|
#include <kdatastream.h>
|
||
|
|
||
|
|
||
|
class KSSLCertificateCache::KSSLCertificateCachePrivate {
|
||
|
public:
|
||
|
DCOPClient *dcc;
|
||
|
|
||
|
KSSLCertificateCachePrivate() { dcc = new DCOPClient; dcc->attach(); }
|
||
|
~KSSLCertificateCachePrivate() { delete dcc;}
|
||
|
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
KSSLCertificateCache::KSSLCertificateCache() {
|
||
|
d = new KSSLCertificateCachePrivate;
|
||
|
}
|
||
|
|
||
|
|
||
|
KSSLCertificateCache::~KSSLCertificateCache() {
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
|
||
|
void KSSLCertificateCache::saveToDisk() {
|
||
|
kdDebug() << "Deprecated function KSSLCertificateCache::saveToDisk() called" << endl;
|
||
|
}
|
||
|
|
||
|
|
||
|
void KSSLCertificateCache::clearList() {
|
||
|
kdDebug() << "Deprecated function KSSLCertificateCache::clearList() called" << endl;
|
||
|
}
|
||
|
|
||
|
|
||
|
void KSSLCertificateCache::loadDefaultPolicies() {
|
||
|
kdDebug() << "Deprecated function KSSLCertificateCache::loadDefaultPolicies() called" << endl;
|
||
|
}
|
||
|
|
||
|
|
||
|
void KSSLCertificateCache::reload() {
|
||
14 years ago
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
d->dcc->call("kded", "kssld",
|
||
|
"cacheReload()",
|
||
|
data, rettype, retval);
|
||
|
}
|
||
|
|
||
|
|
||
|
void KSSLCertificateCache::addCertificate(KSSLCertificate& cert,
|
||
|
KSSLCertificatePolicy policy, bool permanent) {
|
||
14 years ago
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert;
|
||
|
arg << policy;
|
||
|
arg << permanent;
|
||
|
d->dcc->call("kded", "kssld",
|
||
|
"cacheAddCertificate(KSSLCertificate,KSSLCertificateCache::KSSLCertificatePolicy,bool)",
|
||
|
data, rettype, retval);
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
// KDE 4: Make it const TQString &
|
||
|
KSSLCertificateCache::KSSLCertificatePolicy KSSLCertificateCache::getPolicyByCN(TQString& cn) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cn;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"cacheGetPolicyByCN(TQString)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "KSSLCertificateCache::KSSLCertificatePolicy") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
KSSLCertificateCache::KSSLCertificatePolicy drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
return KSSLCertificateCache::Ambiguous;
|
||
|
}
|
||
|
|
||
|
|
||
|
KSSLCertificateCache::KSSLCertificatePolicy KSSLCertificateCache::getPolicyByCertificate(KSSLCertificate& cert) {
|
||
14 years ago
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
|
"cacheGetPolicyByCertificate(KSSLCertificate)",
|
||
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "KSSLCertificateCache::KSSLCertificatePolicy") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
KSSLCertificateCache::KSSLCertificatePolicy drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
return KSSLCertificateCache::Ambiguous;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
// KDE 4: Make it const TQString &
|
||
|
bool KSSLCertificateCache::seenCN(TQString& cn) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cn;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"cacheSeenCN(TQString)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KSSLCertificateCache::seenCertificate(KSSLCertificate& cert) {
|
||
14 years ago
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
|
"cacheSeenCertificate(KSSLCertificate)",
|
||
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KSSLCertificateCache::isPermanent(KSSLCertificate& cert) {
|
||
14 years ago
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
|
"cacheIsPermanent(KSSLCertificate)",
|
||
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
// KDE 4: Make it const TQString &
|
||
|
bool KSSLCertificateCache::removeByCN(TQString& cn) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cn;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"cacheRemoveByCN(TQString)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KSSLCertificateCache::removeByCertificate(KSSLCertificate& cert) {
|
||
14 years ago
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
|
"cacheRemoveByCertificate(KSSLCertificate)",
|
||
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
// KDE 4: Make it const TQString &
|
||
|
bool KSSLCertificateCache::modifyByCN(TQString& cn,
|
||
15 years ago
|
KSSLCertificateCache::KSSLCertificatePolicy policy,
|
||
|
bool permanent,
|
||
14 years ago
|
TQDateTime& expires) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cn << policy << permanent << expires;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"cacheModifyByCN(TQString,KSSLCertificateCache::KSSLCertificatePolicy,bool,TQDateTime)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KSSLCertificateCache::modifyByCertificate(KSSLCertificate& cert,
|
||
|
KSSLCertificateCache::KSSLCertificatePolicy policy,
|
||
|
bool permanent,
|
||
14 years ago
|
TQDateTime& expires) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert << policy << permanent << expires;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"cacheModifyByCertificate(KSSLCertificate,KSSLCertificateCache::KSSLCertificatePolicy,bool,TQDateTime)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQStringList KSSLCertificateCache::getHostList(KSSLCertificate& cert) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
|
"cacheGetHostList(KSSLCertificate)",
|
||
|
data, rettype, retval);
|
||
|
|
||
14 years ago
|
if (rc && rettype == TQSTRINGLIST_OBJECT_NAME_STRING) {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
|
TQStringList drc;
|
||
15 years ago
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
14 years ago
|
return TQStringList();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
// KDE 4: Make it const TQString &
|
||
|
bool KSSLCertificateCache::addHost(KSSLCertificate& cert, TQString& host) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert << host;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"cacheAddHost(KSSLCertificate,TQString)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
// KDE 4: Make it const TQString &
|
||
|
bool KSSLCertificateCache::removeHost(KSSLCertificate& cert, TQString& host) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << cert << host;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"cacheRemoveHost(KSSLCertificate,TQString)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "bool") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
bool drc;
|
||
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQStringList KSSLCertificateCache::getKDEKeyByEmail(const TQString &email) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << email;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"getKDEKeyByEmail(TQString)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
14 years ago
|
if (rc && rettype == TQSTRINGLIST_OBJECT_NAME_STRING) {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
|
TQStringList drc;
|
||
15 years ago
|
retStream >> drc;
|
||
|
return drc;
|
||
|
}
|
||
|
|
||
14 years ago
|
return TQStringList();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
KSSLCertificate *KSSLCertificateCache::getCertByMD5Digest(const TQString &key) {
|
||
|
TQByteArray data, retval;
|
||
|
TQCString rettype;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
15 years ago
|
arg << key;
|
||
|
bool rc = d->dcc->call("kded", "kssld",
|
||
14 years ago
|
"getCertByMD5Digest(TQString)",
|
||
15 years ago
|
data, rettype, retval);
|
||
|
|
||
|
if (rc && rettype == "KSSLCertificate") {
|
||
14 years ago
|
TQDataStream retStream(retval, IO_ReadOnly);
|
||
15 years ago
|
KSSLCertificate *drc = new KSSLCertificate;
|
||
|
retStream >> *drc;
|
||
|
if (drc->getCert())
|
||
|
return drc;
|
||
|
delete drc; // should not happen too often if used in conjunction with getKDEKeyByEmail
|
||
|
}
|
||
|
|
||
|
return 0L;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQDataStream& operator<<(TQDataStream& s, const KSSLCertificateCache::KSSLCertificatePolicy& p) {
|
||
14 years ago
|
s << (TQ_UINT32)p;
|
||
15 years ago
|
return s;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQDataStream& operator>>(TQDataStream& s, KSSLCertificateCache::KSSLCertificatePolicy& p) {
|
||
14 years ago
|
TQ_UINT32 pd;
|
||
15 years ago
|
s >> pd;
|
||
|
p = (KSSLCertificateCache::KSSLCertificatePolicy) pd;
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|