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

tdeio/kssl

  • tdeio
  • kssl
ksslpkcs7.cpp
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
38KSSLPKCS7::KSSLPKCS7() {
39 _pkcs = NULL;
40 _cert = NULL;
41 kossl = KOSSL::self();
42}
43
44
45
46KSSLPKCS7::~KSSLPKCS7() {
47#ifdef KSSL_HAVE_SSL
48 if (_pkcs) kossl->PKCS7_free(_pkcs);
49#endif
50 if (_cert) delete _cert;
51}
52
53
54KSSLPKCS7* KSSLPKCS7::fromString(TQString base64) {
55#ifdef KSSL_HAVE_SSL
56KTempFile ktf;
57
58 if (base64.isEmpty()) return NULL;
59 TQByteArray qba, qbb = TQCString(base64.latin1()).copy();
60 KCodecs::base64Decode(qbb, qba);
61 ktf.file()->writeBlock(qba);
62 ktf.close();
63 KSSLPKCS7* rc = loadCertFile(ktf.name());
64 ktf.unlink();
65 return rc;
66#endif
67return NULL;
68}
69
70
71
72KSSLPKCS7* KSSLPKCS7::loadCertFile(TQString filename) {
73#ifdef KSSL_HAVE_SSL
74TQFile qf(filename);
75PKCS7 *newpkcs = NULL;
76
77 if (!qf.open(IO_ReadOnly))
78 return NULL;
79
80 FILE *fp = fdopen(qf.handle(), "r");
81 if (!fp) return NULL;
82
83 newpkcs = KOSSL::self()->d2i_PKCS7_fp(fp, &newpkcs);
84
85 if (!newpkcs) return NULL;
86
87 KSSLPKCS7 *c = new KSSLPKCS7;
88 c->setCert(newpkcs);
89
90 return c;
91#endif
92return NULL;
93}
94
95
96void KSSLPKCS7::setCert(PKCS7 *c) {
97#ifdef KSSL_HAVE_SSL
98 _pkcs = c;
99 //STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
100 //X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
101 // set _chain and _cert here.
102#endif
103}
104
105
106KSSLCertificate *KSSLPKCS7::getCertificate() {
107 return _cert;
108}
109
110
111KSSLCertChain *KSSLPKCS7::getChain() {
112 return _chain;
113}
114
115
116TQString KSSLPKCS7::toString() {
117TQString base64;
118#ifdef KSSL_HAVE_SSL
119unsigned char *p;
120int len;
121
122 len = kossl->i2d_PKCS7(_pkcs, NULL);
123 if (len >= 0) {
124 char *buf = new char[len];
125 p = (unsigned char *)buf;
126 kossl->i2d_PKCS7(_pkcs, &p);
127 TQByteArray qba;
128 qba.setRawData(buf, len);
129 base64 = KCodecs::base64Encode(qba);
130 qba.resetRawData(buf, len);
131 delete[] buf;
132 }
133#endif
134return base64;
135}
136
137
138
139bool KSSLPKCS7::toFile(TQString filename) {
140#ifdef KSSL_HAVE_SSL
141TQFile out(filename);
142
143 if (!out.open(IO_WriteOnly)) return false;
144
145 int fd = out.handle();
146 FILE *fp = fdopen(fd, "w");
147
148 if (!fp) {
149 unlink(filename.latin1());
150 return false;
151 }
152
153 kossl->i2d_PKCS7_fp(fp, _pkcs);
154
155 fclose(fp);
156 return true;
157#endif
158return false;
159}
160
161
162KSSLCertificate::KSSLValidation KSSLPKCS7::validate() {
163#ifdef KSSL_HAVE_SSL
164KSSLCertificate::KSSLValidation xx = _cert->validate();
165return xx;
166#else
167return KSSLCertificate::NoSSL;
168#endif
169}
170
171
172KSSLCertificate::KSSLValidation KSSLPKCS7::revalidate() {
173 if (_cert)
174 return _cert->revalidate();
175 return KSSLCertificate::Unknown;
176}
177
178
179bool KSSLPKCS7::isValid() {
180return (validate() == KSSLCertificate::Ok);
181}
182
183
184TQString KSSLPKCS7::name() {
185 if (_cert)
186 return _cert->getSubject();
187 return TQString();
188}
189
KSSLCertChain
KDE Certificate Chain Representation Class.
Definition: ksslcertchain.h:45
KSSLCertificate
KDE X.509 Certificate.
Definition: ksslcertificate.h:77
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:122
KSSLCertificate::revalidate
KSSLValidation revalidate()
Check if this is a valid certificate.
Definition: ksslcertificate.cpp:805
KSSLCertificate::getSubject
TQString getSubject() const
Get the subject of the certificate (X.509 map).
Definition: ksslcertificate.cpp:193
KSSLCertificate::validate
KSSLValidation validate()
Check if this is a valid certificate.
Definition: ksslcertificate.cpp:643
KSSLPKCS7
KDE PKCS#7 Certificate.
Definition: ksslpkcs7.h:60
KSSLPKCS7::setCert
void setCert(PKCS7 *c)
Raw set the PKCS7 object.
Definition: ksslpkcs7.cpp:96
KSSLPKCS7::validate
KSSLCertificate::KSSLValidation validate()
Check the chain to make sure it's valid.
Definition: ksslpkcs7.cpp:162
KSSLPKCS7::fromString
static KSSLPKCS7 * fromString(TQString base64)
Create a KSSLPKCS7 object from a Base64 in a TQString.
Definition: ksslpkcs7.cpp:54
KSSLPKCS7::toFile
bool toFile(TQString filename)
Write the PKCS#7 to a file in raw mode.
Definition: ksslpkcs7.cpp:139
KSSLPKCS7::getChain
KSSLCertChain * getChain()
Get the certificate chain.
Definition: ksslpkcs7.cpp:111
KSSLPKCS7::isValid
bool isValid()
Return true if the chain is valid.
Definition: ksslpkcs7.cpp:179
KSSLPKCS7::toString
TQString toString()
Convert to a Base64 string.
Definition: ksslpkcs7.cpp:116
KSSLPKCS7::name
TQString name()
The name of this certificate.
Definition: ksslpkcs7.cpp:184
KSSLPKCS7::getCertificate
KSSLCertificate * getCertificate()
Get the bottom level X.509 certificate.
Definition: ksslpkcs7.cpp:106
KSSLPKCS7::loadCertFile
static KSSLPKCS7 * loadCertFile(TQString filename)
Create a KSSLPKCS7 object by reading a PKCS#7 file.
Definition: ksslpkcs7.cpp:72
KSSLPKCS7::~KSSLPKCS7
virtual ~KSSLPKCS7()
Destroy this PKCS#7 certificate.
Definition: ksslpkcs7.cpp:46
KSSLPKCS7::revalidate
KSSLCertificate::KSSLValidation revalidate()
Check the chain to make sure it's valid.
Definition: ksslpkcs7.cpp:172

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.9.4
This website is maintained by Timothy Pearson.