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

KIO

  • kio
  • kssl
ksslcsessioncache.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 *
3 * Copyright (C) 2003 Stefan Rompf <sux@loplof.de>
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#include "ksslcsessioncache.h"
22
23#include <QtCore/QCoreApplication>
24#include <QtCore/QPair>
25#include <QtCore/QString>
26
27#include <kdebug.h>
28#include <kurl.h>
29
30#include <ksslconfig.h>
31
32/*
33 * Operation:
34 *
35 * Sessions will be stored per running application, not KDE
36 * wide, to avoid security problems with hostile programs
37 * that negotiate sessions with weak cryptographic keys and store
38 * them for everybody to use - I really don't want that.
39 *
40 * Retrieval is organized similar to George's thoughts in the KSSLD
41 * certificate cache: The cache is organised as a list, with the
42 * recently fetched (or stored) session first.
43 *
44 * The cache has an artificial limit of 32 sessions (should really
45 * be enough), and relies on the peer server for timeouts
46 *
47 */
48#define MAX_ENTRIES 32
49
50#ifdef KSSL_HAVE_SSL
51
52typedef QPair<QString,QString> KSSLCSession;
53typedef QList<KSSLCSession> KSSLCSessions;
54
55static KSSLCSessions *sessions = 0L;
56
57static QString URLtoKey(const KUrl &kurl) {
58 return kurl.host() + ':' + kurl.protocol() + ':' + QString::number(kurl.port());
59}
60
61
62static void cleanupKSSLCSessions() {
63 delete sessions;
64 sessions = 0;
65}
66
67static void setup() {
68 sessions = new KSSLCSessions;
69 qAddPostRoutine(cleanupKSSLCSessions);
70}
71
72#endif
73
74QString KSSLCSessionCache::getSessionForUrl(const KUrl &kurl) {
75#ifdef KSSL_HAVE_SSL
76 if (!sessions) return QString();
77 QString key = URLtoKey(kurl);
78
79 for (int i = 0; i < sessions->size(); ++i) {
80 if (sessions->at(i).first == key) {
81 QString snd = sessions->at(i).second;
82 sessions->prepend(sessions->takeAt(i));
83 return snd;
84 }
85 }
86
87 // Negative caching disabled: cache pollution
88#if 0
89 kDebug(7029) <<"Negative caching " <<key;
90 if (sessions->count() >= MAX_ENTRIES) sessions->removeLast();
91 sessions->prepend(new KSSLCSession(key, QString()));
92#endif
93
94#endif
95 return QString();
96}
97
98
99void KSSLCSessionCache::putSessionForUrl(const KUrl &kurl, const QString &session) {
100#ifdef KSSL_HAVE_SSL
101 if (!sessions) setup();
102 QString key = URLtoKey(kurl);
103 KSSLCSessions::iterator it = sessions->begin();
104
105 while ( it != sessions->end() ) {
106 if ( it->first == key )
107 break;
108 ++it;
109 }
110
111 if (it != sessions->end()) {
112 it->second = session;
113 } else {
114 if (sessions->size() >= MAX_ENTRIES)
115 sessions->removeLast();
116 sessions->prepend(KSSLCSession(key, session));
117 }
118
119#endif
120}
KSSLCSessionCache::getSessionForUrl
static QString getSessionForUrl(const KUrl &kurl)
Retrieve a SSL session (client side only)
Definition: ksslcsessioncache.cpp:74
KSSLCSessionCache::putSessionForUrl
static void putSessionForUrl(const KUrl &kurl, const QString &session)
Store a SSL session (client side only)
Definition: ksslcsessioncache.cpp:99
KUrl
KUrl::protocol
QString protocol() const
QList
QPair
kDebug
#define kDebug
kdebug.h
MAX_ENTRIES
#define MAX_ENTRIES
Definition: ksslcsessioncache.cpp:48
ksslcsessioncache.h
kurl.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