• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kssl
ksslpkcs7.cpp
Go to the documentation of this file.
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#include <config.h>
23#include <ksslconfig.h>
24
25#include <kopenssl.h>
26
27#include <QtCore/QString>
28#include <QtCore/QFile>
29
30#include <ksslall.h>
31#include <kdebug.h>
32#include <ktemporaryfile.h>
33#include <kcodecs.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
47KSSLPKCS7::KSSLPKCS7() {
48 _pkcs = NULL;
49 _cert = NULL;
50 kossl = KOSSL::self();
51}
52
53
54
55KSSLPKCS7::~KSSLPKCS7() {
56#ifdef KSSL_HAVE_SSL
57 if (_pkcs) kossl->PKCS7_free(_pkcs);
58#endif
59 delete _cert;
60}
61
62
63KSSLPKCS7* KSSLPKCS7::fromString(const QString &base64) {
64#ifdef KSSL_HAVE_SSL
65 KTemporaryFile ktf;
66 ktf.open();
67
68 if (base64.isEmpty()) return NULL;
69 QByteArray qba = QByteArray::fromBase64(base64.toLatin1());
70 ktf.write(qba);
71 ktf.flush();
72 KSSLPKCS7* rc = loadCertFile(ktf.fileName());
73 return rc;
74#endif
75return NULL;
76}
77
78
79
80KSSLPKCS7* KSSLPKCS7::loadCertFile(const QString &filename) {
81#ifdef KSSL_HAVE_SSL
82QFile qf(filename);
83PKCS7 *newpkcs = NULL;
84
85 if (!qf.open(QIODevice::ReadOnly))
86 return NULL;
87
88 FILE *fp = fdopen(qf.handle(), "r");
89 if (!fp) return NULL;
90
91 newpkcs = KOSSL::self()->d2i_PKCS7_fp(fp, &newpkcs);
92
93 if (!newpkcs) return NULL;
94
95 KSSLPKCS7 *c = new KSSLPKCS7;
96 c->setCert(newpkcs);
97
98 return c;
99#endif
100return NULL;
101}
102
103
104void KSSLPKCS7::setCert(PKCS7 *c) {
105#ifdef KSSL_HAVE_SSL
106 _pkcs = c;
107 //STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
108 //X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
109 // set _chain and _cert here.
110#endif
111}
112
113
114KSSLCertificate *KSSLPKCS7::getCertificate() {
115 return _cert;
116}
117
118
119KSSLCertChain *KSSLPKCS7::getChain() {
120 return _chain;
121}
122
123
124QString KSSLPKCS7::toString() const {
125QString base64;
126#ifdef KSSL_HAVE_SSL
127unsigned char *p;
128int len;
129
130 len = kossl->i2d_PKCS7(_pkcs, NULL);
131 if (len >= 0) {
132 char *buf = new char[len];
133 p = (unsigned char *)buf;
134 kossl->i2d_PKCS7(_pkcs, &p);
135 base64 = QByteArray::fromRawData(buf,len).toBase64();
136 delete[] buf;
137 }
138#endif
139return base64;
140}
141
142
143
144bool KSSLPKCS7::toFile(const QString &filename) {
145#ifdef KSSL_HAVE_SSL
146QFile out(filename);
147
148 if (!out.open(QIODevice::WriteOnly)) return false;
149
150 int fd = out.handle();
151 FILE *fp = fdopen(fd, "w");
152
153 if (!fp) {
154 unlink(filename.toLatin1());
155 return false;
156 }
157
158 kossl->i2d_PKCS7_fp(fp, _pkcs);
159
160 fclose(fp);
161 return true;
162#endif
163return false;
164}
165
166
167KSSLCertificate::KSSLValidation KSSLPKCS7::validate() const {
168#ifdef KSSL_HAVE_SSL
169KSSLCertificate::KSSLValidation xx = _cert->validate();
170return xx;
171#else
172return KSSLCertificate::NoSSL;
173#endif
174}
175
176
177KSSLCertificate::KSSLValidation KSSLPKCS7::revalidate() {
178 if (_cert)
179 return _cert->revalidate();
180 return KSSLCertificate::Unknown;
181}
182
183
184bool KSSLPKCS7::isValid() const {
185return (validate() == KSSLCertificate::Ok);
186}
187
188
189QString KSSLPKCS7::name() const {
190 if (_cert)
191 return _cert->getSubject();
192 return QString();
193}
194
195
196#ifdef KSSL_HAVE_SSL
197#undef sk_new
198#undef sk_push
199#undef sk_free
200#undef sk_value
201#undef sk_num
202#undef sk_dup
203#endif
204
KSSLCertChain
KDE Certificate Chain Representation Class.
Definition: ksslcertchain.h:43
KSSLCertificate
KDE X.509 Certificate.
Definition: ksslcertificate.h:75
KSSLCertificate::KSSLValidation
KSSLValidation
Result of the validate() call.
Definition: ksslcertificate.h:119
KSSLCertificate::NoSSL
@ NoSSL
Definition: ksslcertificate.h:121
KSSLCertificate::Ok
@ Ok
Definition: ksslcertificate.h:119
KSSLCertificate::Unknown
@ Unknown
Definition: ksslcertificate.h:119
KSSLCertificate::revalidate
KSSLValidation revalidate()
Check if this is a valid certificate.
Definition: ksslcertificate.cpp:788
KSSLCertificate::getSubject
QString getSubject() const
Get the subject of the certificate (X.509 map).
Definition: ksslcertificate.cpp:167
KSSLCertificate::validate
KSSLValidation validate()
Check if this is a valid certificate.
Definition: ksslcertificate.cpp:623
KSSLPKCS7
KDE PKCS#7 Certificate.
Definition: ksslpkcs7.h:55
KSSLPKCS7::setCert
void setCert(PKCS7 *c)
Raw set the PKCS7 object.
Definition: ksslpkcs7.cpp:104
KSSLPKCS7::toFile
bool toFile(const QString &filename)
Write the PKCS#7 to a file in raw mode.
Definition: ksslpkcs7.cpp:144
KSSLPKCS7::fromString
static KSSLPKCS7 * fromString(const QString &base64)
Create a KSSLPKCS7 object from a Base64 in a QString.
Definition: ksslpkcs7.cpp:63
KSSLPKCS7::getChain
KSSLCertChain * getChain()
Get the certificate chain.
Definition: ksslpkcs7.cpp:119
KSSLPKCS7::isValid
bool isValid() const
Return true if the chain is valid.
Definition: ksslpkcs7.cpp:184
KSSLPKCS7::KSSLPKCS7
KSSLPKCS7()
Definition: ksslpkcs7.cpp:47
KSSLPKCS7::getCertificate
KSSLCertificate * getCertificate()
Get the bottom level X.509 certificate.
Definition: ksslpkcs7.cpp:114
KSSLPKCS7::toString
QString toString() const
Convert to a Base64 string.
Definition: ksslpkcs7.cpp:124
KSSLPKCS7::~KSSLPKCS7
virtual ~KSSLPKCS7()
Destroy this PKCS#7 certificate.
Definition: ksslpkcs7.cpp:55
KSSLPKCS7::revalidate
KSSLCertificate::KSSLValidation revalidate()
Check the chain to make sure it's valid.
Definition: ksslpkcs7.cpp:177
KSSLPKCS7::name
QString name() const
The name of this certificate.
Definition: ksslpkcs7.cpp:189
KSSLPKCS7::validate
KSSLCertificate::KSSLValidation validate() const
Check the chain to make sure it's valid.
Definition: ksslpkcs7.cpp:167
KSSLPKCS7::loadCertFile
static KSSLPKCS7 * loadCertFile(const QString &filename)
Create a KSSLPKCS7 object by reading a PKCS#7 file.
Definition: ksslpkcs7.cpp:80
KTemporaryFile
fp
static const char fp[]
Definition: des.cpp:68
kcodecs.h
kdebug.h
kopenssl.h
ksslall.h
ktemporaryfile.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal