TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ksslsession.cc 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 2003 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. #include "ksslsession.h"
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <kopenssl.h>
  25. #include <kmdcodec.h>
  26. KSSLSession::KSSLSession() : _session(0L) {
  27. }
  28. KSSLSession::~KSSLSession() {
  29. #ifdef KSSL_HAVE_SSL
  30. if (_session) {
  31. KOpenSSLProxy::self()->SSL_SESSION_free(static_cast<SSL_SESSION*>(_session));
  32. _session = 0L;
  33. }
  34. #endif
  35. }
  36. TQString KSSLSession::toString() const {
  37. TQString rc;
  38. #ifdef KSSL_HAVE_SSL
  39. TQByteArray qba;
  40. SSL_SESSION *session = static_cast<SSL_SESSION*>(_session);
  41. unsigned int slen = KOpenSSLProxy::self()->i2d_SSL_SESSION(session, 0L);
  42. unsigned char *csess = new unsigned char[slen];
  43. unsigned char *p = csess;
  44. if (!KOpenSSLProxy::self()->i2d_SSL_SESSION(session, &p)) {
  45. delete[] csess;
  46. return TQString::null;
  47. }
  48. // encode it into a QString
  49. qba.duplicate((const char*)csess, slen);
  50. delete[] csess;
  51. rc = KCodecs::base64Encode(qba);
  52. #endif
  53. return rc;
  54. }
  55. KSSLSession *KSSLSession::fromString(const TQString& s) {
  56. KSSLSession *session = 0L;
  57. #ifdef KSSL_HAVE_SSL
  58. TQByteArray qba, qbb = s.local8Bit().copy();
  59. KCodecs::base64Decode(qbb, qba);
  60. unsigned char *qbap = reinterpret_cast<unsigned char *>(qba.data());
  61. SSL_SESSION *ss = KOSSL::self()->d2i_SSL_SESSION(0L, &qbap, qba.size());
  62. if (ss) {
  63. session = new KSSLSession;
  64. session->_session = ss;
  65. }
  66. #endif
  67. return session;
  68. }