KIO
ksslsession.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ksslsession.h"
00022
00023 #include <config.h>
00024 #include <ksslconfig.h>
00025
00026 #include <kopenssl.h>
00027 #include <kcodecs.h>
00028
00029 KSSLSession::KSSLSession() : _session(0L) {
00030 }
00031
00032
00033 KSSLSession::~KSSLSession() {
00034 #ifdef KSSL_HAVE_SSL
00035 if (_session) {
00036 KOpenSSLProxy::self()->SSL_SESSION_free(static_cast<SSL_SESSION*>(_session));
00037 _session = 0L;
00038 }
00039 #endif
00040 }
00041
00042
00043 QString KSSLSession::toString() const {
00044 QString rc;
00045 #ifdef KSSL_HAVE_SSL
00046 SSL_SESSION *session = static_cast<SSL_SESSION*>(_session);
00047 int slen = KOpenSSLProxy::self()->i2d_SSL_SESSION(session, 0L);
00048
00049 if (slen >= 0) {
00050
00051
00052 char *csess = new char[slen];
00053 unsigned char *p = (unsigned char*)csess;
00054
00055 if (!KOpenSSLProxy::self()->i2d_SSL_SESSION(session, &p)) {
00056 delete[] csess;
00057 return QString();
00058 }
00059
00060
00061 rc = QByteArray(csess,slen).toBase64();
00062 delete[] csess;
00063 }
00064 #endif
00065 return rc;
00066 }
00067
00068
00069 KSSLSession *KSSLSession::fromString(const QString& s) {
00070 KSSLSession *session = 0L;
00071 #ifdef KSSL_HAVE_SSL
00072 QByteArray qba, qbb = s.toLocal8Bit();
00073 qba = QByteArray::fromBase64(qbb);
00074 unsigned char *qbap = reinterpret_cast<unsigned char *>(qba.data());
00075 SSL_SESSION *ss = KOSSL::self()->d2i_SSL_SESSION(0L, &qbap, qba.size());
00076 if (ss) {
00077 session = new KSSLSession;
00078 session->_session = ss;
00079 }
00080 #endif
00081 return session;
00082 }
00083
00084