• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/kssl
 

tdeio/kssl

  • tdeio
  • kssl
ksslcsessioncache.cpp
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 <tqpair.h>
22 #include <tqstring.h>
23 #include <tqptrlist.h>
24 
25 #include <kdebug.h>
26 #include <kstaticdeleter.h>
27 #include <kurl.h>
28 
29 #ifdef Q_WS_WIN
30 #include "ksslconfig_win.h"
31 #else
32 #include "ksslconfig.h"
33 #endif
34 
35 #include "ksslcsessioncache.h"
36 
37 /*
38  * Operation:
39  *
40  * Sessions will be stored per running application, not KDE
41  * wide, to avoid security problems with hostile programs
42  * that negotiate sessions with weak cryptographic keys and store
43  * them for everybody to use - I really don't want that.
44  *
45  * Retrieval is organised similiar to George's thoughts in the KSSLD
46  * certificate cache: The cache is organised as a list, with the
47  * recently fetched (or stored) session first.
48  *
49  * The cache has an artificial limit of 32 sessions (should really
50  * be enough), and relies on the peer server for timeouts
51  *
52  */
53 #define MAX_ENTRIES 32
54 
55 #ifdef KSSL_HAVE_SSL
56 
57 typedef QPair<TQString,TQString> KSSLCSession;
58 typedef TQPtrList<KSSLCSession> KSSLCSessions;
59 
60 static KSSLCSessions *sessions = 0L;
61 static KStaticDeleter<KSSLCSessions> med;
62 
63 
64 static TQString URLtoKey(const KURL &kurl) {
65  return kurl.host() + ":" + kurl.protocol() + ":" + TQString::number(kurl.port());
66 }
67 
68 
69 static void setup() {
70  KSSLCSessions *ses = new KSSLCSessions;
71  ses->setAutoDelete(true);
72  med.setObject(sessions, ses);
73 }
74 
75 #endif
76 
77 TQString KSSLCSessionCache::getSessionForURL(const KURL &kurl) {
78 #ifdef KSSL_HAVE_SSL
79  if (!sessions) return TQString::null;
80  TQString key = URLtoKey(kurl);
81 
82  for(KSSLCSession *it = sessions->first(); it; it=sessions->next()) {
83  if (it->first == key) {
84  sessions->take();
85  sessions->prepend(it);
86  return it->second;
87  }
88  }
89 
90  // Negative caching disabled: cache pollution
91 #if 0
92  kdDebug(7029) <<"Negative caching " <<key <<endl;
93  if (sessions->count() >= MAX_ENTRIES) sessions->removeLast();
94  sessions->prepend(new KSSLCSession(key, TQString::null));
95 #endif
96 
97 #endif
98  return TQString::null;
99 }
100 
101 
102 void KSSLCSessionCache::putSessionForURL(const KURL &kurl, const TQString &session) {
103 #ifdef KSSL_HAVE_SSL
104  if (!sessions) setup();
105  TQString key = URLtoKey(kurl);
106  KSSLCSession *it;
107 
108  for(it = sessions->first(); it && it->first != key; it=sessions->next());
109 
110  if (it) {
111  sessions->take();
112  it->second = session;
113  } else {
114  it = new KSSLCSession(key, session);
115  if (sessions->count() >= MAX_ENTRIES) sessions->removeLast();
116  }
117 
118  sessions->prepend(it);
119 #endif
120 }

tdeio/kssl

Skip menu "tdeio/kssl"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/kssl

Skip menu "tdeio/kssl"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/kssl by doxygen 1.8.8
This website is maintained by Timothy Pearson.