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

tdeio/kssl

  • tdeio
  • 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 <tdetempfile.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 
KSSLCertificate::validate
KSSLValidation validate()
Check if this is a valid certificate.
Definition: ksslcertificate.cc:590
KSSLPKCS7
KDE PKCS#7 Certificate.
Definition: ksslpkcs7.h:60
KSSLCertificate
KDE X.509 Certificate.
Definition: ksslcertificate.h:75
KSSLCertificate::revalidate
KSSLValidation revalidate()
Check if this is a valid certificate.
Definition: ksslcertificate.cc:753
KSSLPKCS7::getChain
KSSLCertChain * getChain()
Get the certificate chain.
Definition: ksslpkcs7.cc:120
KSSLPKCS7::toFile
bool toFile(TQString filename)
Write the PKCS#7 to a file in raw mode.
Definition: ksslpkcs7.cc:148
KSSLPKCS7::isValid
bool isValid()
Return true if the chain is valid.
Definition: ksslpkcs7.cc:188
KSSLCertChain
KDE Certificate Chain Representation Class.
Definition: ksslcertchain.h:45
KSSLPKCS7::fromString
static KSSLPKCS7 * fromString(TQString base64)
Create a KSSLPKCS7 object from a Base64 in a TQString.
Definition: ksslpkcs7.cc:63
KSSLCertificate::KSSLValidation
KSSLValidation
A CA certificate can be validated as Irrelevant when it was not used to sign any other relevant certi...
Definition: ksslcertificate.h:113
KSSLPKCS7::validate
KSSLCertificate::KSSLValidation validate()
Check the chain to make sure it&#39;s valid.
Definition: ksslpkcs7.cc:171
KSSLPKCS7::revalidate
KSSLCertificate::KSSLValidation revalidate()
Check the chain to make sure it&#39;s valid.
Definition: ksslpkcs7.cc:181
KSSLPKCS7::getCertificate
KSSLCertificate * getCertificate()
Get the bottom level X.509 certificate.
Definition: ksslpkcs7.cc:115
KSSLPKCS7::name
TQString name()
The name of this certificate.
Definition: ksslpkcs7.cc:193
KSSLPKCS7::setCert
void setCert(PKCS7 *c)
Raw set the PKCS7 object.
Definition: ksslpkcs7.cc:105
KSSLPKCS7::loadCertFile
static KSSLPKCS7 * loadCertFile(TQString filename)
Create a KSSLPKCS7 object by reading a PKCS#7 file.
Definition: ksslpkcs7.cc:81
KSSLPKCS7::~KSSLPKCS7
virtual ~KSSLPKCS7()
Destroy this PKCS#7 certificate.
Definition: ksslpkcs7.cc:55
KSSLCertificate::getSubject
TQString getSubject() const
Get the subject of the certificate (X.509 map).
Definition: ksslcertificate.cc:166
KSSLPKCS7::toString
TQString toString()
Convert to a Base64 string.
Definition: ksslpkcs7.cc:125

tdeio/kssl

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

tdeio/kssl

Skip menu "tdeio/kssl"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/kssl by doxygen 1.8.11
This website is maintained by Timothy Pearson.