ksslcertificatecache.cc
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2000, 2001 George Staikos <staikos@kde.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 00022 #include "ksslcertificatecache.h" 00023 #include "ksslcertchain.h" 00024 #include "ksslcertificate.h" 00025 00026 #include <stdlib.h> 00027 #include <kdebug.h> 00028 #include <dcopclient.h> 00029 #include <kdatastream.h> 00030 00031 00032 class KSSLCertificateCache::KSSLCertificateCachePrivate { 00033 public: 00034 DCOPClient *dcc; 00035 00036 KSSLCertificateCachePrivate() { dcc = new DCOPClient; dcc->attach(); } 00037 ~KSSLCertificateCachePrivate() { delete dcc;} 00038 00039 }; 00040 00041 00042 00043 KSSLCertificateCache::KSSLCertificateCache() { 00044 d = new KSSLCertificateCachePrivate; 00045 } 00046 00047 00048 KSSLCertificateCache::~KSSLCertificateCache() { 00049 delete d; 00050 } 00051 00052 00053 void KSSLCertificateCache::saveToDisk() { 00054 kdDebug() << "Deprecated function KSSLCertificateCache::saveToDisk() called" << endl; 00055 } 00056 00057 00058 void KSSLCertificateCache::clearList() { 00059 kdDebug() << "Deprecated function KSSLCertificateCache::clearList() called" << endl; 00060 } 00061 00062 00063 void KSSLCertificateCache::loadDefaultPolicies() { 00064 kdDebug() << "Deprecated function KSSLCertificateCache::loadDefaultPolicies() called" << endl; 00065 } 00066 00067 00068 void KSSLCertificateCache::reload() { 00069 TQByteArray data, retval; 00070 TQCString rettype; 00071 TQDataStream arg(data, IO_WriteOnly); 00072 d->dcc->call("kded", "kssld", 00073 "cacheReload()", 00074 data, rettype, retval); 00075 } 00076 00077 00078 void KSSLCertificateCache::addCertificate(KSSLCertificate& cert, 00079 KSSLCertificatePolicy policy, bool permanent) { 00080 TQByteArray data, retval; 00081 TQCString rettype; 00082 TQDataStream arg(data, IO_WriteOnly); 00083 arg << cert; 00084 arg << policy; 00085 arg << permanent; 00086 d->dcc->call("kded", "kssld", 00087 "cacheAddCertificate(KSSLCertificate,KSSLCertificateCache::KSSLCertificatePolicy,bool)", 00088 data, rettype, retval); 00089 } 00090 00091 00092 // KDE 4: Make it const TQString & 00093 KSSLCertificateCache::KSSLCertificatePolicy KSSLCertificateCache::getPolicyByCN(TQString& cn) { 00094 TQByteArray data, retval; 00095 TQCString rettype; 00096 TQDataStream arg(data, IO_WriteOnly); 00097 arg << cn; 00098 bool rc = d->dcc->call("kded", "kssld", 00099 "cacheGetPolicyByCN(TQString)", 00100 data, rettype, retval); 00101 00102 if (rc && rettype == "KSSLCertificateCache::KSSLCertificatePolicy") { 00103 TQDataStream retStream(retval, IO_ReadOnly); 00104 KSSLCertificateCache::KSSLCertificatePolicy drc; 00105 retStream >> drc; 00106 return drc; 00107 } 00108 return KSSLCertificateCache::Ambiguous; 00109 } 00110 00111 00112 KSSLCertificateCache::KSSLCertificatePolicy KSSLCertificateCache::getPolicyByCertificate(KSSLCertificate& cert) { 00113 TQByteArray data, retval; 00114 TQCString rettype; 00115 TQDataStream arg(data, IO_WriteOnly); 00116 arg << cert; 00117 bool rc = d->dcc->call("kded", "kssld", 00118 "cacheGetPolicyByCertificate(KSSLCertificate)", 00119 data, rettype, retval); 00120 00121 if (rc && rettype == "KSSLCertificateCache::KSSLCertificatePolicy") { 00122 TQDataStream retStream(retval, IO_ReadOnly); 00123 KSSLCertificateCache::KSSLCertificatePolicy drc; 00124 retStream >> drc; 00125 return drc; 00126 } 00127 return KSSLCertificateCache::Ambiguous; 00128 } 00129 00130 00131 // KDE 4: Make it const TQString & 00132 bool KSSLCertificateCache::seenCN(TQString& cn) { 00133 TQByteArray data, retval; 00134 TQCString rettype; 00135 TQDataStream arg(data, IO_WriteOnly); 00136 arg << cn; 00137 bool rc = d->dcc->call("kded", "kssld", 00138 "cacheSeenCN(TQString)", 00139 data, rettype, retval); 00140 00141 if (rc && rettype == "bool") { 00142 TQDataStream retStream(retval, IO_ReadOnly); 00143 bool drc; 00144 retStream >> drc; 00145 return drc; 00146 } 00147 00148 return false; 00149 } 00150 00151 00152 bool KSSLCertificateCache::seenCertificate(KSSLCertificate& cert) { 00153 TQByteArray data, retval; 00154 TQCString rettype; 00155 TQDataStream arg(data, IO_WriteOnly); 00156 arg << cert; 00157 bool rc = d->dcc->call("kded", "kssld", 00158 "cacheSeenCertificate(KSSLCertificate)", 00159 data, rettype, retval); 00160 00161 if (rc && rettype == "bool") { 00162 TQDataStream retStream(retval, IO_ReadOnly); 00163 bool drc; 00164 retStream >> drc; 00165 return drc; 00166 } 00167 00168 return false; 00169 } 00170 00171 00172 bool KSSLCertificateCache::isPermanent(KSSLCertificate& cert) { 00173 TQByteArray data, retval; 00174 TQCString rettype; 00175 TQDataStream arg(data, IO_WriteOnly); 00176 arg << cert; 00177 bool rc = d->dcc->call("kded", "kssld", 00178 "cacheIsPermanent(KSSLCertificate)", 00179 data, rettype, retval); 00180 00181 if (rc && rettype == "bool") { 00182 TQDataStream retStream(retval, IO_ReadOnly); 00183 bool drc; 00184 retStream >> drc; 00185 return drc; 00186 } 00187 00188 return false; 00189 } 00190 00191 00192 // KDE 4: Make it const TQString & 00193 bool KSSLCertificateCache::removeByCN(TQString& cn) { 00194 TQByteArray data, retval; 00195 TQCString rettype; 00196 TQDataStream arg(data, IO_WriteOnly); 00197 arg << cn; 00198 bool rc = d->dcc->call("kded", "kssld", 00199 "cacheRemoveByCN(TQString)", 00200 data, rettype, retval); 00201 00202 if (rc && rettype == "bool") { 00203 TQDataStream retStream(retval, IO_ReadOnly); 00204 bool drc; 00205 retStream >> drc; 00206 return drc; 00207 } 00208 00209 return false; 00210 } 00211 00212 00213 bool KSSLCertificateCache::removeByCertificate(KSSLCertificate& cert) { 00214 TQByteArray data, retval; 00215 TQCString rettype; 00216 TQDataStream arg(data, IO_WriteOnly); 00217 arg << cert; 00218 bool rc = d->dcc->call("kded", "kssld", 00219 "cacheRemoveByCertificate(KSSLCertificate)", 00220 data, rettype, retval); 00221 00222 if (rc && rettype == "bool") { 00223 TQDataStream retStream(retval, IO_ReadOnly); 00224 bool drc; 00225 retStream >> drc; 00226 return drc; 00227 } 00228 00229 return false; 00230 } 00231 00232 00233 // KDE 4: Make it const TQString & 00234 bool KSSLCertificateCache::modifyByCN(TQString& cn, 00235 KSSLCertificateCache::KSSLCertificatePolicy policy, 00236 bool permanent, 00237 TQDateTime& expires) { 00238 TQByteArray data, retval; 00239 TQCString rettype; 00240 TQDataStream arg(data, IO_WriteOnly); 00241 arg << cn << policy << permanent << expires; 00242 bool rc = d->dcc->call("kded", "kssld", 00243 "cacheModifyByCN(TQString,KSSLCertificateCache::KSSLCertificatePolicy,bool,TQDateTime)", 00244 data, rettype, retval); 00245 00246 if (rc && rettype == "bool") { 00247 TQDataStream retStream(retval, IO_ReadOnly); 00248 bool drc; 00249 retStream >> drc; 00250 return drc; 00251 } 00252 00253 return false; 00254 } 00255 00256 00257 bool KSSLCertificateCache::modifyByCertificate(KSSLCertificate& cert, 00258 KSSLCertificateCache::KSSLCertificatePolicy policy, 00259 bool permanent, 00260 TQDateTime& expires) { 00261 TQByteArray data, retval; 00262 TQCString rettype; 00263 TQDataStream arg(data, IO_WriteOnly); 00264 arg << cert << policy << permanent << expires; 00265 bool rc = d->dcc->call("kded", "kssld", 00266 "cacheModifyByCertificate(KSSLCertificate,KSSLCertificateCache::KSSLCertificatePolicy,bool,TQDateTime)", 00267 data, rettype, retval); 00268 00269 if (rc && rettype == "bool") { 00270 TQDataStream retStream(retval, IO_ReadOnly); 00271 bool drc; 00272 retStream >> drc; 00273 return drc; 00274 } 00275 00276 return false; 00277 } 00278 00279 00280 TQStringList KSSLCertificateCache::getHostList(KSSLCertificate& cert) { 00281 TQByteArray data, retval; 00282 TQCString rettype; 00283 TQDataStream arg(data, IO_WriteOnly); 00284 arg << cert; 00285 bool rc = d->dcc->call("kded", "kssld", 00286 "cacheGetHostList(KSSLCertificate)", 00287 data, rettype, retval); 00288 00289 if (rc && rettype == TQSTRINGLIST_OBJECT_NAME_STRING) { 00290 TQDataStream retStream(retval, IO_ReadOnly); 00291 TQStringList drc; 00292 retStream >> drc; 00293 return drc; 00294 } 00295 return TQStringList(); 00296 } 00297 00298 00299 // KDE 4: Make it const TQString & 00300 bool KSSLCertificateCache::addHost(KSSLCertificate& cert, TQString& host) { 00301 TQByteArray data, retval; 00302 TQCString rettype; 00303 TQDataStream arg(data, IO_WriteOnly); 00304 arg << cert << host; 00305 bool rc = d->dcc->call("kded", "kssld", 00306 "cacheAddHost(KSSLCertificate,TQString)", 00307 data, rettype, retval); 00308 00309 if (rc && rettype == "bool") { 00310 TQDataStream retStream(retval, IO_ReadOnly); 00311 bool drc; 00312 retStream >> drc; 00313 return drc; 00314 } 00315 00316 return false; 00317 } 00318 00319 00320 // KDE 4: Make it const TQString & 00321 bool KSSLCertificateCache::removeHost(KSSLCertificate& cert, TQString& host) { 00322 TQByteArray data, retval; 00323 TQCString rettype; 00324 TQDataStream arg(data, IO_WriteOnly); 00325 arg << cert << host; 00326 bool rc = d->dcc->call("kded", "kssld", 00327 "cacheRemoveHost(KSSLCertificate,TQString)", 00328 data, rettype, retval); 00329 00330 if (rc && rettype == "bool") { 00331 TQDataStream retStream(retval, IO_ReadOnly); 00332 bool drc; 00333 retStream >> drc; 00334 return drc; 00335 } 00336 00337 return false; 00338 } 00339 00340 00341 TQStringList KSSLCertificateCache::getKDEKeyByEmail(const TQString &email) { 00342 TQByteArray data, retval; 00343 TQCString rettype; 00344 TQDataStream arg(data, IO_WriteOnly); 00345 arg << email; 00346 bool rc = d->dcc->call("kded", "kssld", 00347 "getKDEKeyByEmail(TQString)", 00348 data, rettype, retval); 00349 00350 if (rc && rettype == TQSTRINGLIST_OBJECT_NAME_STRING) { 00351 TQDataStream retStream(retval, IO_ReadOnly); 00352 TQStringList drc; 00353 retStream >> drc; 00354 return drc; 00355 } 00356 00357 return TQStringList(); 00358 } 00359 00360 00361 KSSLCertificate *KSSLCertificateCache::getCertByMD5Digest(const TQString &key) { 00362 TQByteArray data, retval; 00363 TQCString rettype; 00364 TQDataStream arg(data, IO_WriteOnly); 00365 arg << key; 00366 bool rc = d->dcc->call("kded", "kssld", 00367 "getCertByMD5Digest(TQString)", 00368 data, rettype, retval); 00369 00370 if (rc && rettype == "KSSLCertificate") { 00371 TQDataStream retStream(retval, IO_ReadOnly); 00372 KSSLCertificate *drc = new KSSLCertificate; 00373 retStream >> *drc; 00374 if (drc->getCert()) 00375 return drc; 00376 delete drc; // should not happen too often if used in conjunction with getKDEKeyByEmail 00377 } 00378 00379 return 0L; 00380 } 00381 00382 00383 TQDataStream& operator<<(TQDataStream& s, const KSSLCertificateCache::KSSLCertificatePolicy& p) { 00384 s << (TQ_UINT32)p; 00385 return s; 00386 } 00387 00388 00389 TQDataStream& operator>>(TQDataStream& s, KSSLCertificateCache::KSSLCertificatePolicy& p) { 00390 TQ_UINT32 pd; 00391 s >> pd; 00392 p = (KSSLCertificateCache::KSSLCertificatePolicy) pd; 00393 return s; 00394 } 00395 00396 00397 00398 00399