• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kssl
 

kio/kssl

  • kio
  • kssl
ksslpkcs7.cc
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 
21 
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 
26 #include <kopenssl.h>
27 
28 #include <tqstring.h>
29 #include <tqfile.h>
30 #include <ksslall.h>
31 #include <kdebug.h>
32 #include <ktempfile.h>
33 #include <kmdcodec.h>
34 
35 #include <assert.h>
36 
37 #ifdef KSSL_HAVE_SSL
38 #define sk_new kossl->sk_new
39 #define sk_push kossl->sk_push
40 #define sk_free kossl->sk_free
41 #define sk_value kossl->sk_value
42 #define sk_num kossl->sk_num
43 #define sk_dup kossl->sk_dup
44 #endif
45 
46 
47 KSSLPKCS7::KSSLPKCS7() {
48  _pkcs = NULL;
49  _cert = NULL;
50  kossl = KOSSL::self();
51 }
52 
53 
54 
55 KSSLPKCS7::~KSSLPKCS7() {
56 #ifdef KSSL_HAVE_SSL
57  if (_pkcs) kossl->PKCS7_free(_pkcs);
58 #endif
59  if (_cert) delete _cert;
60 }
61 
62 
63 KSSLPKCS7* KSSLPKCS7::fromString(TQString base64) {
64 #ifdef KSSL_HAVE_SSL
65 KTempFile ktf;
66 
67  if (base64.isEmpty()) return NULL;
68  TQByteArray qba, qbb = TQCString(base64.latin1()).copy();
69  KCodecs::base64Decode(qbb, qba);
70  ktf.file()->writeBlock(qba);
71  ktf.close();
72  KSSLPKCS7* rc = loadCertFile(ktf.name());
73  ktf.unlink();
74  return rc;
75 #endif
76 return NULL;
77 }
78 
79 
80 
81 KSSLPKCS7* KSSLPKCS7::loadCertFile(TQString filename) {
82 #ifdef KSSL_HAVE_SSL
83 TQFile qf(filename);
84 PKCS7 *newpkcs = NULL;
85 
86  if (!qf.open(IO_ReadOnly))
87  return NULL;
88 
89  FILE *fp = fdopen(qf.handle(), "r");
90  if (!fp) return NULL;
91 
92  newpkcs = KOSSL::self()->d2i_PKCS7_fp(fp, &newpkcs);
93 
94  if (!newpkcs) return NULL;
95 
96  KSSLPKCS7 *c = new KSSLPKCS7;
97  c->setCert(newpkcs);
98 
99  return c;
100 #endif
101 return NULL;
102 }
103 
104 
105 void KSSLPKCS7::setCert(PKCS7 *c) {
106 #ifdef KSSL_HAVE_SSL
107  _pkcs = c;
108  //STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
109  //X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
110  // set _chain and _cert here.
111 #endif
112 }
113 
114 
115 KSSLCertificate *KSSLPKCS7::getCertificate() {
116  return _cert;
117 }
118 
119 
120 KSSLCertChain *KSSLPKCS7::getChain() {
121  return _chain;
122 }
123 
124 
125 TQString KSSLPKCS7::toString() {
126 TQString base64;
127 #ifdef KSSL_HAVE_SSL
128 unsigned char *p;
129 int len;
130 
131  len = kossl->i2d_PKCS7(_pkcs, NULL);
132  if (len >= 0) {
133  char *buf = new char[len];
134  p = (unsigned char *)buf;
135  kossl->i2d_PKCS7(_pkcs, &p);
136  TQByteArray qba;
137  qba.setRawData(buf, len);
138  base64 = KCodecs::base64Encode(qba);
139  qba.resetRawData(buf, len);
140  delete[] buf;
141  }
142 #endif
143 return base64;
144 }
145 
146 
147 
148 bool KSSLPKCS7::toFile(TQString filename) {
149 #ifdef KSSL_HAVE_SSL
150 TQFile out(filename);
151 
152  if (!out.open(IO_WriteOnly)) return false;
153 
154  int fd = out.handle();
155  FILE *fp = fdopen(fd, "w");
156 
157  if (!fp) {
158  unlink(filename.latin1());
159  return false;
160  }
161 
162  kossl->i2d_PKCS7_fp(fp, _pkcs);
163 
164  fclose(fp);
165  return true;
166 #endif
167 return false;
168 }
169 
170 
171 KSSLCertificate::KSSLValidation KSSLPKCS7::validate() {
172 #ifdef KSSL_HAVE_SSL
173 KSSLCertificate::KSSLValidation xx = _cert->validate();
174 return xx;
175 #else
176 return KSSLCertificate::NoSSL;
177 #endif
178 }
179 
180 
181 KSSLCertificate::KSSLValidation KSSLPKCS7::revalidate() {
182  if (_cert)
183  return _cert->revalidate();
184  return KSSLCertificate::Unknown;
185 }
186 
187 
188 bool KSSLPKCS7::isValid() {
189 return (validate() == KSSLCertificate::Ok);
190 }
191 
192 
193 TQString KSSLPKCS7::name() {
194  if (_cert)
195  return _cert->getSubject();
196  return TQString();
197 }
198 
199 
200 #ifdef KSSL_HAVE_SSL
201 #undef sk_new
202 #undef sk_push
203 #undef sk_free
204 #undef sk_value
205 #undef sk_num
206 #undef sk_dup
207 #endif
208 

kio/kssl

Skip menu "kio/kssl"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kio/kssl

Skip menu "kio/kssl"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kssl by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |