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.

252 lines
6.1KB

  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 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 <tqstring.h>
  21. #include <tqstringlist.h>
  22. #include "ksslcertificate.h"
  23. #include "ksslsigners.h"
  24. #include <stdlib.h>
  25. #include <kdebug.h>
  26. #include <dcopclient.h>
  27. #include <kdatastream.h>
  28. KSSLSigners::KSSLSigners() {
  29. dcc = new DCOPClient;
  30. dcc->attach();
  31. }
  32. KSSLSigners::~KSSLSigners() {
  33. delete dcc;
  34. }
  35. bool KSSLSigners::addCA(KSSLCertificate& cert,
  36. bool ssl,
  37. bool email,
  38. bool code) {
  39. return addCA(cert.toString(), ssl, email, code);
  40. }
  41. bool KSSLSigners::addCA(TQString cert,
  42. bool ssl,
  43. bool email,
  44. bool code) {
  45. TQByteArray data, retval;
  46. TQCString rettype;
  47. TQDataStream arg(data, IO_WriteOnly);
  48. arg << cert;
  49. arg << ssl << email << code;
  50. bool rc = dcc->call("kded", "kssld",
  51. "caAdd(TQString,bool,bool,bool)",
  52. data, rettype, retval);
  53. if (rc && rettype == "bool") {
  54. TQDataStream retStream(retval, IO_ReadOnly);
  55. bool drc;
  56. retStream >> drc;
  57. return drc;
  58. }
  59. return false;
  60. }
  61. bool KSSLSigners::regenerate() {
  62. TQByteArray data, retval;
  63. TQCString rettype;
  64. TQDataStream arg(data, IO_WriteOnly);
  65. bool rc = dcc->call("kded", "kssld",
  66. "caRegenerate()",
  67. data, rettype, retval);
  68. if (rc && rettype == "bool") {
  69. TQDataStream retStream(retval, IO_ReadOnly);
  70. bool drc;
  71. retStream >> drc;
  72. return drc;
  73. }
  74. return false;
  75. }
  76. bool KSSLSigners::useForSSL(KSSLCertificate& cert) {
  77. return useForSSL(cert.getSubject());
  78. }
  79. bool KSSLSigners::useForSSL(TQString subject) {
  80. TQByteArray data, retval;
  81. TQCString rettype;
  82. TQDataStream arg(data, IO_WriteOnly);
  83. arg << subject;
  84. bool rc = dcc->call("kded", "kssld",
  85. "caUseForSSL(TQString)",
  86. data, rettype, retval);
  87. if (rc && rettype == "bool") {
  88. TQDataStream retStream(retval, IO_ReadOnly);
  89. bool drc;
  90. retStream >> drc;
  91. return drc;
  92. }
  93. return false;
  94. }
  95. bool KSSLSigners::useForEmail(KSSLCertificate& cert) {
  96. return useForEmail(cert.getSubject());
  97. }
  98. bool KSSLSigners::useForEmail(TQString subject) {
  99. TQByteArray data, retval;
  100. TQCString rettype;
  101. TQDataStream arg(data, IO_WriteOnly);
  102. arg << subject;
  103. bool rc = dcc->call("kded", "kssld",
  104. "caUseForEmail(TQString)",
  105. data, rettype, retval);
  106. if (rc && rettype == "bool") {
  107. TQDataStream retStream(retval, IO_ReadOnly);
  108. bool drc;
  109. retStream >> drc;
  110. return drc;
  111. }
  112. return false;
  113. }
  114. bool KSSLSigners::useForCode(KSSLCertificate& cert) {
  115. return useForCode(cert.getSubject());
  116. }
  117. bool KSSLSigners::useForCode(TQString subject) {
  118. TQByteArray data, retval;
  119. TQCString rettype;
  120. TQDataStream arg(data, IO_WriteOnly);
  121. arg << subject;
  122. bool rc = dcc->call("kded", "kssld",
  123. "caUseForCode(TQString)",
  124. data, rettype, retval);
  125. if (rc && rettype == "bool") {
  126. TQDataStream retStream(retval, IO_ReadOnly);
  127. bool drc;
  128. retStream >> drc;
  129. return drc;
  130. }
  131. return false;
  132. }
  133. bool KSSLSigners::remove(KSSLCertificate& cert) {
  134. return remove(cert.getSubject());
  135. }
  136. bool KSSLSigners::remove(TQString subject) {
  137. TQByteArray data, retval;
  138. TQCString rettype;
  139. TQDataStream arg(data, IO_WriteOnly);
  140. arg << subject;
  141. bool rc = dcc->call("kded", "kssld",
  142. "caRemove(TQString)",
  143. data, rettype, retval);
  144. if (rc && rettype == "bool") {
  145. TQDataStream retStream(retval, IO_ReadOnly);
  146. bool drc;
  147. retStream >> drc;
  148. return drc;
  149. }
  150. return false;
  151. }
  152. TQStringList KSSLSigners::list() {
  153. TQStringList drc;
  154. TQByteArray data, retval;
  155. TQCString rettype;
  156. TQDataStream arg(data, IO_WriteOnly);
  157. bool rc = dcc->call("kded", "kssld",
  158. "caList()",
  159. data, rettype, retval);
  160. if (rc && rettype == TQSTRINGLIST_OBJECT_NAME_STRING) {
  161. TQDataStream retStream(retval, IO_ReadOnly);
  162. retStream >> drc;
  163. }
  164. return drc;
  165. }
  166. TQString KSSLSigners::getCert(TQString subject) {
  167. TQString drc;
  168. TQByteArray data, retval;
  169. TQCString rettype;
  170. TQDataStream arg(data, IO_WriteOnly);
  171. arg << subject;
  172. bool rc = dcc->call("kded", "kssld",
  173. "caGetCert(TQString)",
  174. data, rettype, retval);
  175. if (rc && rettype == TQSTRING_OBJECT_NAME_STRING) {
  176. TQDataStream retStream(retval, IO_ReadOnly);
  177. retStream >> drc;
  178. }
  179. return drc;
  180. }
  181. bool KSSLSigners::setUse(TQString subject, bool ssl, bool email, bool code) {
  182. TQByteArray data, retval;
  183. TQCString rettype;
  184. TQDataStream arg(data, IO_WriteOnly);
  185. arg << subject << ssl << email << code;
  186. bool rc = dcc->call("kded", "kssld",
  187. "caSetUse(TQString,bool,bool,bool)",
  188. data, rettype, retval);
  189. if (rc && rettype == "bool") {
  190. TQDataStream retStream(retval, IO_ReadOnly);
  191. bool drc;
  192. retStream >> drc;
  193. return drc;
  194. }
  195. return false;
  196. }