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

KIO

  • sources
  • kde-4.12
  • kdelibs
  • 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 
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  delete _cert;
60 }
61 
62 
63 KSSLPKCS7* 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
75 return NULL;
76 }
77 
78 
79 
80 KSSLPKCS7* KSSLPKCS7::loadCertFile(const QString &filename) {
81 #ifdef KSSL_HAVE_SSL
82 QFile qf(filename);
83 PKCS7 *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
100 return NULL;
101 }
102 
103 
104 void 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 
114 KSSLCertificate *KSSLPKCS7::getCertificate() {
115  return _cert;
116 }
117 
118 
119 KSSLCertChain *KSSLPKCS7::getChain() {
120  return _chain;
121 }
122 
123 
124 QString KSSLPKCS7::toString() const {
125 QString base64;
126 #ifdef KSSL_HAVE_SSL
127 unsigned char *p;
128 int 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
139 return base64;
140 }
141 
142 
143 
144 bool KSSLPKCS7::toFile(const QString &filename) {
145 #ifdef KSSL_HAVE_SSL
146 QFile 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
163 return false;
164 }
165 
166 
167 KSSLCertificate::KSSLValidation KSSLPKCS7::validate() const {
168 #ifdef KSSL_HAVE_SSL
169 KSSLCertificate::KSSLValidation xx = _cert->validate();
170 return xx;
171 #else
172 return KSSLCertificate::NoSSL;
173 #endif
174 }
175 
176 
177 KSSLCertificate::KSSLValidation KSSLPKCS7::revalidate() {
178  if (_cert)
179  return _cert->revalidate();
180  return KSSLCertificate::Unknown;
181 }
182 
183 
184 bool KSSLPKCS7::isValid() const {
185 return (validate() == KSSLCertificate::Ok);
186 }
187 
188 
189 QString 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 
fp
static const char fp[]
Definition: des.cpp:68
KSSLCertificate::Unknown
Definition: ksslcertificate.h:119
KSSLPKCS7::KSSLPKCS7
KSSLPKCS7()
Definition: ksslpkcs7.cpp:47
kdebug.h
KSSLCertificate::validate
KSSLValidation validate()
Check if this is a valid certificate.
Definition: ksslcertificate.cpp:612
KSSLPKCS7
KDE PKCS#7 Certificate.
Definition: ksslpkcs7.h:55
KSSLCertificate
KDE X.509 Certificate.
Definition: ksslcertificate.h:74
KSSLCertificate::revalidate
KSSLValidation revalidate()
Check if this is a valid certificate.
Definition: ksslcertificate.cpp:777
QString
KTemporaryFile
KSSLCertificate::getSubject
QString getSubject() const
Get the subject of the certificate (X.509 map).
Definition: ksslcertificate.cpp:167
KSSLPKCS7::getChain
KSSLCertChain * getChain()
Get the certificate chain.
Definition: ksslpkcs7.cpp:119
KSSLCertificate::Ok
Definition: ksslcertificate.h:119
KSSLCertChain
KDE Certificate Chain Representation Class.
Definition: ksslcertchain.h:43
KSSLCertificate::KSSLValidation
KSSLValidation
Result of the validate() call.
Definition: ksslcertificate.h:119
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
KSSLCertificate::NoSSL
Definition: ksslcertificate.h:121
KSSLPKCS7::getCertificate
KSSLCertificate * getCertificate()
Get the bottom level X.509 certificate.
Definition: ksslpkcs7.cpp:114
KSSLPKCS7::fromString
static KSSLPKCS7 * fromString(const QString &base64)
Create a KSSLPKCS7 object from a Base64 in a QString.
Definition: ksslpkcs7.cpp:63
KSSLPKCS7::setCert
void setCert(PKCS7 *c)
Raw set the PKCS7 object.
Definition: ksslpkcs7.cpp:104
KSSLPKCS7::validate
KSSLCertificate::KSSLValidation validate() const
Check the chain to make sure it's valid.
Definition: ksslpkcs7.cpp:167
ktemporaryfile.h
KSSLPKCS7::~KSSLPKCS7
virtual ~KSSLPKCS7()
Destroy this PKCS#7 certificate.
Definition: ksslpkcs7.cpp:55
kcodecs.h
kopenssl.h
KSSLPKCS7::isValid
bool isValid() const
Return true if the chain is valid.
Definition: ksslpkcs7.cpp:184
KSSLPKCS7::toString
QString toString() const
Convert to a Base64 string.
Definition: ksslpkcs7.cpp:124
KSSLPKCS7::loadCertFile
static KSSLPKCS7 * loadCertFile(const QString &filename)
Create a KSSLPKCS7 object by reading a PKCS#7 file.
Definition: ksslpkcs7.cpp:80
ksslall.h
KSSLPKCS7::toFile
bool toFile(const QString &filename)
Write the PKCS#7 to a file in raw mode.
Definition: ksslpkcs7.cpp:144
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:03 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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