TDE core libraries
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.

ksslcertificatecache.cc 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 2000, 2001 George Staikos <staikos@kde.org>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #include "ksslcertificatecache.h"
  21. #include "ksslcertchain.h"
  22. #include "ksslcertificate.h"
  23. #include <stdlib.h>
  24. #include <kdebug.h>
  25. #include <dcopclient.h>
  26. #include <kdatastream.h>
  27. class KSSLCertificateCache::KSSLCertificateCachePrivate {
  28. public:
  29. DCOPClient *dcc;
  30. KSSLCertificateCachePrivate() { dcc = new DCOPClient; dcc->attach(); }
  31. ~KSSLCertificateCachePrivate() { delete dcc;}
  32. };
  33. KSSLCertificateCache::KSSLCertificateCache() {
  34. d = new KSSLCertificateCachePrivate;
  35. }
  36. KSSLCertificateCache::~KSSLCertificateCache() {
  37. delete d;
  38. }
  39. void KSSLCertificateCache::saveToDisk() {
  40. kdDebug() << "Deprecated function KSSLCertificateCache::saveToDisk() called" << endl;
  41. }
  42. void KSSLCertificateCache::clearList() {
  43. kdDebug() << "Deprecated function KSSLCertificateCache::clearList() called" << endl;
  44. }
  45. void KSSLCertificateCache::loadDefaultPolicies() {
  46. kdDebug() << "Deprecated function KSSLCertificateCache::loadDefaultPolicies() called" << endl;
  47. }
  48. void KSSLCertificateCache::reload() {
  49. TQByteArray data, retval;
  50. TQCString rettype;
  51. TQDataStream arg(data, IO_WriteOnly);
  52. d->dcc->call("kded", "kssld",
  53. "cacheReload()",
  54. data, rettype, retval);
  55. }
  56. void KSSLCertificateCache::addCertificate(KSSLCertificate& cert,
  57. KSSLCertificatePolicy policy, bool permanent) {
  58. TQByteArray data, retval;
  59. TQCString rettype;
  60. TQDataStream arg(data, IO_WriteOnly);
  61. arg << cert;
  62. arg << policy;
  63. arg << permanent;
  64. d->dcc->call("kded", "kssld",
  65. "cacheAddCertificate(KSSLCertificate,KSSLCertificateCache::KSSLCertificatePolicy,bool)",
  66. data, rettype, retval);
  67. }
  68. // KDE 4: Make it const TQString &
  69. KSSLCertificateCache::KSSLCertificatePolicy KSSLCertificateCache::getPolicyByCN(TQString& cn) {
  70. TQByteArray data, retval;
  71. TQCString rettype;
  72. TQDataStream arg(data, IO_WriteOnly);
  73. arg << cn;
  74. bool rc = d->dcc->call("kded", "kssld",
  75. "cacheGetPolicyByCN(TQString)",
  76. data, rettype, retval);
  77. if (rc && rettype == "KSSLCertificateCache::KSSLCertificatePolicy") {
  78. TQDataStream retStream(retval, IO_ReadOnly);
  79. KSSLCertificateCache::KSSLCertificatePolicy drc;
  80. retStream >> drc;
  81. return drc;
  82. }
  83. return KSSLCertificateCache::Ambiguous;
  84. }
  85. KSSLCertificateCache::KSSLCertificatePolicy KSSLCertificateCache::getPolicyByCertificate(KSSLCertificate& cert) {
  86. TQByteArray data, retval;
  87. TQCString rettype;
  88. TQDataStream arg(data, IO_WriteOnly);
  89. arg << cert;
  90. bool rc = d->dcc->call("kded", "kssld",
  91. "cacheGetPolicyByCertificate(KSSLCertificate)",
  92. data, rettype, retval);
  93. if (rc && rettype == "KSSLCertificateCache::KSSLCertificatePolicy") {
  94. TQDataStream retStream(retval, IO_ReadOnly);
  95. KSSLCertificateCache::KSSLCertificatePolicy drc;
  96. retStream >> drc;
  97. return drc;
  98. }
  99. return KSSLCertificateCache::Ambiguous;
  100. }
  101. // KDE 4: Make it const TQString &
  102. bool KSSLCertificateCache::seenCN(TQString& cn) {
  103. TQByteArray data, retval;
  104. TQCString rettype;
  105. TQDataStream arg(data, IO_WriteOnly);
  106. arg << cn;
  107. bool rc = d->dcc->call("kded", "kssld",
  108. "cacheSeenCN(TQString)",
  109. data, rettype, retval);
  110. if (rc && rettype == "bool") {
  111. TQDataStream retStream(retval, IO_ReadOnly);
  112. bool drc;
  113. retStream >> drc;
  114. return drc;
  115. }
  116. return false;
  117. }
  118. bool KSSLCertificateCache::seenCertificate(KSSLCertificate& cert) {
  119. TQByteArray data, retval;
  120. TQCString rettype;
  121. TQDataStream arg(data, IO_WriteOnly);
  122. arg << cert;
  123. bool rc = d->dcc->call("kded", "kssld",
  124. "cacheSeenCertificate(KSSLCertificate)",
  125. data, rettype, retval);
  126. if (rc && rettype == "bool") {
  127. TQDataStream retStream(retval, IO_ReadOnly);
  128. bool drc;
  129. retStream >> drc;
  130. return drc;
  131. }
  132. return false;
  133. }
  134. bool KSSLCertificateCache::isPermanent(KSSLCertificate& cert) {
  135. TQByteArray data, retval;
  136. TQCString rettype;
  137. TQDataStream arg(data, IO_WriteOnly);
  138. arg << cert;
  139. bool rc = d->dcc->call("kded", "kssld",
  140. "cacheIsPermanent(KSSLCertificate)",
  141. data, rettype, retval);
  142. if (rc && rettype == "bool") {
  143. TQDataStream retStream(retval, IO_ReadOnly);
  144. bool drc;
  145. retStream >> drc;
  146. return drc;
  147. }
  148. return false;
  149. }
  150. // KDE 4: Make it const TQString &
  151. bool KSSLCertificateCache::removeByCN(TQString& cn) {
  152. TQByteArray data, retval;
  153. TQCString rettype;
  154. TQDataStream arg(data, IO_WriteOnly);
  155. arg << cn;
  156. bool rc = d->dcc->call("kded", "kssld",
  157. "cacheRemoveByCN(TQString)",
  158. data, rettype, retval);
  159. if (rc && rettype == "bool") {
  160. TQDataStream retStream(retval, IO_ReadOnly);
  161. bool drc;
  162. retStream >> drc;
  163. return drc;
  164. }
  165. return false;
  166. }
  167. bool KSSLCertificateCache::removeByCertificate(KSSLCertificate& cert) {
  168. TQByteArray data, retval;
  169. TQCString rettype;
  170. TQDataStream arg(data, IO_WriteOnly);
  171. arg << cert;
  172. bool rc = d->dcc->call("kded", "kssld",
  173. "cacheRemoveByCertificate(KSSLCertificate)",
  174. data, rettype, retval);
  175. if (rc && rettype == "bool") {
  176. TQDataStream retStream(retval, IO_ReadOnly);
  177. bool drc;
  178. retStream >> drc;
  179. return drc;
  180. }
  181. return false;
  182. }
  183. // KDE 4: Make it const TQString &
  184. bool KSSLCertificateCache::modifyByCN(TQString& cn,
  185. KSSLCertificateCache::KSSLCertificatePolicy policy,
  186. bool permanent,
  187. TQDateTime& expires) {
  188. TQByteArray data, retval;
  189. TQCString rettype;
  190. TQDataStream arg(data, IO_WriteOnly);
  191. arg << cn << policy << permanent << expires;
  192. bool rc = d->dcc->call("kded", "kssld",
  193. "cacheModifyByCN(TQString,KSSLCertificateCache::KSSLCertificatePolicy,bool,TQDateTime)",
  194. data, rettype, retval);
  195. if (rc && rettype == "bool") {
  196. TQDataStream retStream(retval, IO_ReadOnly);
  197. bool drc;
  198. retStream >> drc;
  199. return drc;
  200. }
  201. return false;
  202. }
  203. bool KSSLCertificateCache::modifyByCertificate(KSSLCertificate& cert,
  204. KSSLCertificateCache::KSSLCertificatePolicy policy,
  205. bool permanent,
  206. TQDateTime& expires) {
  207. TQByteArray data, retval;
  208. TQCString rettype;
  209. TQDataStream arg(data, IO_WriteOnly);
  210. arg << cert << policy << permanent << expires;
  211. bool rc = d->dcc->call("kded", "kssld",
  212. "cacheModifyByCertificate(KSSLCertificate,KSSLCertificateCache::KSSLCertificatePolicy,bool,TQDateTime)",
  213. data, rettype, retval);
  214. if (rc && rettype == "bool") {
  215. TQDataStream retStream(retval, IO_ReadOnly);
  216. bool drc;
  217. retStream >> drc;
  218. return drc;
  219. }
  220. return false;
  221. }
  222. TQStringList KSSLCertificateCache::getHostList(KSSLCertificate& cert) {
  223. TQByteArray data, retval;
  224. TQCString rettype;
  225. TQDataStream arg(data, IO_WriteOnly);
  226. arg << cert;
  227. bool rc = d->dcc->call("kded", "kssld",
  228. "cacheGetHostList(KSSLCertificate)",
  229. data, rettype, retval);
  230. if (rc && rettype == TQSTRINGLIST_OBJECT_NAME_STRING) {
  231. TQDataStream retStream(retval, IO_ReadOnly);
  232. TQStringList drc;
  233. retStream >> drc;
  234. return drc;
  235. }
  236. return TQStringList();
  237. }
  238. // KDE 4: Make it const TQString &
  239. bool KSSLCertificateCache::addHost(KSSLCertificate& cert, TQString& host) {
  240. TQByteArray data, retval;
  241. TQCString rettype;
  242. TQDataStream arg(data, IO_WriteOnly);
  243. arg << cert << host;
  244. bool rc = d->dcc->call("kded", "kssld",
  245. "cacheAddHost(KSSLCertificate,TQString)",
  246. data, rettype, retval);
  247. if (rc && rettype == "bool") {
  248. TQDataStream retStream(retval, IO_ReadOnly);
  249. bool drc;
  250. retStream >> drc;
  251. return drc;
  252. }
  253. return false;
  254. }
  255. // KDE 4: Make it const TQString &
  256. bool KSSLCertificateCache::removeHost(KSSLCertificate& cert, TQString& host) {
  257. TQByteArray data, retval;
  258. TQCString rettype;
  259. TQDataStream arg(data, IO_WriteOnly);
  260. arg << cert << host;
  261. bool rc = d->dcc->call("kded", "kssld",
  262. "cacheRemoveHost(KSSLCertificate,TQString)",
  263. data, rettype, retval);
  264. if (rc && rettype == "bool") {
  265. TQDataStream retStream(retval, IO_ReadOnly);
  266. bool drc;
  267. retStream >> drc;
  268. return drc;
  269. }
  270. return false;
  271. }
  272. TQStringList KSSLCertificateCache::getKDEKeyByEmail(const TQString &email) {
  273. TQByteArray data, retval;
  274. TQCString rettype;
  275. TQDataStream arg(data, IO_WriteOnly);
  276. arg << email;
  277. bool rc = d->dcc->call("kded", "kssld",
  278. "getKDEKeyByEmail(TQString)",
  279. data, rettype, retval);
  280. if (rc && rettype == TQSTRINGLIST_OBJECT_NAME_STRING) {
  281. TQDataStream retStream(retval, IO_ReadOnly);
  282. TQStringList drc;
  283. retStream >> drc;
  284. return drc;
  285. }
  286. return TQStringList();
  287. }
  288. KSSLCertificate *KSSLCertificateCache::getCertByMD5Digest(const TQString &key) {
  289. TQByteArray data, retval;
  290. TQCString rettype;
  291. TQDataStream arg(data, IO_WriteOnly);
  292. arg << key;
  293. bool rc = d->dcc->call("kded", "kssld",
  294. "getCertByMD5Digest(TQString)",
  295. data, rettype, retval);
  296. if (rc && rettype == "KSSLCertificate") {
  297. TQDataStream retStream(retval, IO_ReadOnly);
  298. KSSLCertificate *drc = new KSSLCertificate;
  299. retStream >> *drc;
  300. if (drc->getCert())
  301. return drc;
  302. delete drc; // should not happen too often if used in conjunction with getKDEKeyByEmail
  303. }
  304. return 0L;
  305. }
  306. TQDataStream& operator<<(TQDataStream& s, const KSSLCertificateCache::KSSLCertificatePolicy& p) {
  307. s << (TQ_UINT32)p;
  308. return s;
  309. }
  310. TQDataStream& operator>>(TQDataStream& s, KSSLCertificateCache::KSSLCertificatePolicy& p) {
  311. TQ_UINT32 pd;
  312. s >> pd;
  313. p = (KSSLCertificateCache::KSSLCertificatePolicy) pd;
  314. return s;
  315. }