KVIrc 5.2.6
Developer APIs
KviSSL.h
Go to the documentation of this file.
1#ifndef _KVI_SSL_H_
2#define _KVI_SSL_H_
3//=============================================================================
4//
5// File : KviSSL.h
6// Creation date : Mon May 27 2002 21:36:12 CEST by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
27#include "kvi_settings.h"
28
29#ifdef COMPILE_SSL_SUPPORT
30
31#include "KviCString.h"
32#include "KviPointerHashTable.h"
33#include "kvi_sockettype.h"
34
35// Apple deprecated openssl since osx 10.7:
36
37#ifdef DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
38#undef DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
39#define DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
40#endif
41
42#include <openssl/ssl.h>
43
44class KVILIB_API KviSSLCertificate
45{
46public:
47 KviSSLCertificate(X509 * x509);
48 ~KviSSLCertificate();
49
50protected:
51 X509 * m_pX509;
52 KviPointerHashTable<const char *, KviCString> * m_pSubject;
53 KviPointerHashTable<const char *, KviCString> * m_pIssuer;
54 int m_iPubKeyBits;
55 KviCString m_szPubKeyType;
56 KviCString m_szSerialNumber;
57 int m_iVersion;
58 KviCString m_szSignatureType;
59 KviCString m_szSignatureContents;
60
61private:
62 void extractSubject();
63 void extractIssuer();
64 void extractPubKeyInfo();
65 void extractSerialNumber();
66 void extractSignature();
67 const char * dictEntry(KviPointerHashTable<const char *, KviCString> * dict, const char * entry);
68 void splitX509String(KviPointerHashTable<const char *, KviCString> * dict, const char * t);
69 int getFingerprint(unsigned char * bufferData, unsigned int * bufferLen, const char * digestName);
70
71public:
72 void setX509(X509 * x509);
73 char * getX509Base64(); //not owned, you'll need to free this
74
75 const char * signatureType() { return m_szSignatureType.ptr(); };
76 const char * signatureContents() { return m_szSignatureContents.ptr(); };
77
78 const char * subjectCountry() { return dictEntry(m_pSubject, "C"); };
79 const char * subjectStateOrProvince() { return dictEntry(m_pSubject, "ST"); };
80 const char * subjectLocality() { return dictEntry(m_pSubject, "L"); };
81 const char * subjectOrganization() { return dictEntry(m_pSubject, "O"); };
82 const char * subjectOrganizationalUnit() { return dictEntry(m_pSubject, "OU"); };
83 const char * subjectCommonName() { return dictEntry(m_pSubject, "CN"); };
84
85 const char * issuerCountry() { return dictEntry(m_pIssuer, "C"); };
86 const char * issuerStateOrProvince() { return dictEntry(m_pIssuer, "ST"); };
87 const char * issuerLocality() { return dictEntry(m_pIssuer, "L"); };
88 const char * issuerOrganization() { return dictEntry(m_pIssuer, "O"); };
89 const char * issuerOrganizationalUnit() { return dictEntry(m_pIssuer, "OU"); };
90 const char * issuerCommonName() { return dictEntry(m_pIssuer, "CN"); };
91
92 int publicKeyBits() { return m_iPubKeyBits; };
93 const char * publicKeyType() { return m_szPubKeyType.ptr(); };
94
95 const char * serialNumber() { return m_szSerialNumber.len() ? m_szSerialNumber.ptr() : nullptr; };
96
97 int version() { return m_iVersion; };
98
99 bool fingerprintIsValid();
100 int fingerprintDigestId();
101 const char * fingerprintDigestStr();
102 const char * fingerprintContents(QString digestName = "");
103
104#ifdef COMPILE_ON_WINDOWS
105 // On windows we need to override new and delete operators
106 // to ensure that always the right new/delete pair is called for an object instance
107 // This bug is present in all the classes exported by a module that
108 // can be instantiated/destroyed from external modules.
109 // (this is a well known bug described in Q122675 of MSDN)
110 void * operator new(size_t tSize);
111 void operator delete(void * p);
112#endif
113};
114
115class KVILIB_API KviSSLCipherInfo
116{
117public:
118#if OPENSSL_VERSION_NUMBER >= 0x10000000L
119 KviSSLCipherInfo(const SSL_CIPHER * c, const SSL * s);
120#else
121 KviSSLCipherInfo(SSL_CIPHER * c, SSL * s);
122#endif
123 ~KviSSLCipherInfo();
124
125protected:
126 KviCString m_szVersion;
127 int m_iNumBits;
128 int m_iNumBitsUsed;
129 KviCString m_szName;
130 KviCString m_szDescription;
131
132public:
133 const char * name() { return m_szName.ptr(); };
134 const char * description() { return m_szDescription.ptr(); };
135 int bits() { return m_iNumBits; };
136 int bitsUsed() { return m_iNumBitsUsed; };
137 const char * version() { return m_szVersion.ptr(); };
138#ifdef COMPILE_ON_WINDOWS
139 // On windows we need to override new and delete operators
140 // to ensure that always the right new/delete pair is called for an object instance
141 // This bug is present in all the classes exported by a module that
142 // can be instantiated/destroyed from external modules.
143 // (this is a well known bug described in Q122675 of MSDN)
144 void * operator new(size_t tSize);
145 void operator delete(void * p);
146#endif
147};
148
149#ifdef Success
150#undef Success
151#endif
152
153class KVILIB_API KviSSL
154{
155public:
156 enum Method
157 {
158 Client,
159 Server
160 };
161 enum Result
162 {
163 Success,
164 NotInitialized,
165 WantRead,
166 WantWrite,
167 ZeroReturn,
168 FileIoError,
170 ObscureError,
171 SSLError,
172 SyscallError,
174 };
175
176public:
177 KviSSL();
178 ~KviSSL();
179
180public:
181 SSL * m_pSSL;
182 SSL_CTX * m_pSSLCtx;
183 KviCString m_szPass;
184
185public:
186 static void globalInit();
187 static void globalDestroy();
188 static void globalSSLInit();
189 static void globalSSLDestroy();
190
191public:
192 bool initSocket(kvi_socket_t fd);
193 bool initContext(KviSSL::Method m);
194 void shutdown();
195 bool setTLSHostname(const char * name);
196 bool enableADHCiphers();
197 KviSSL::Result connect();
198 KviSSL::Result accept();
199 int read(char * buffer, int len);
200 int write(const char * buffer, int len);
201 // SSL ERRORS
202 unsigned long getLastError(bool bPeek = false);
203 bool getLastErrorString(KviCString & buffer, bool bPeek = false);
204 // Protocol error
205 KviSSL::Result getProtocolError(int ret);
206 KviSSLCertificate * getPeerCertificate();
207 KviSSLCertificate * getLocalCertificate();
208 KviSSLCipherInfo * getCurrentCipherInfo();
209 KviSSL::Result useCertificateFile(QString cert, QString pass);
210 KviSSL::Result usePrivateKeyFile(QString key, QString pass);
211#ifdef COMPILE_ON_WINDOWS
212 // On windows we need to override new and delete operators
213 // to ensure that always the right new/delete pair is called for an object instance
214 // This bug is present in all the classes exported by a module that
215 // can be instantiated/destroyed from external modules.
216 // (this is a well known bug described in Q122675 of MSDN)
217 void * operator new(size_t tSize);
218 void operator delete(void * p);
219#endif
220private:
221 KviSSL::Result connectOrAcceptError(int ret);
222};
223
224#endif //COMPILE_SSL_SUPPORT
225
226#endif //_KVI_SSL_H_
Pointer Hash Table.
connect(m_pFtp, SIGNAL(commandFinished(int, bool)), this, SLOT(slotCommandFinished(int, bool)))
char * ptr() const
Definition KviCString.h:163
int len() const
Definition KviCString.h:165
#define m
Definition detector.cpp:78
#define t
Definition detector.cpp:85
#define s
Definition detector.cpp:84
#define p
Definition detector.cpp:81
This file contains compile time settings.
#define KVILIB_API
Definition kvi_settings.h:124
int kvi_socket_t
Definition kvi_sockettype.h:40
@ UnknownError
Definition KviError.h:50
@ SSLError
Definition KviError.h:162
@ Success
Definition KviError.h:49
@ RemoteEndClosedConnection
Definition KviError.h:97
QString version()
Definition KviRuntimeInfo.cpp:717
QString name()
Definition KviRuntimeInfo.cpp:703