1 #ifndef SQUID_SSL_CONTEXT_STORAGE_H
2 #define SQUID_SSL_CONTEXT_STORAGE_H
7 #include "CacheManager.h"
8 #include "ip/Address.h"
9 #include "mgr/Action.h"
10 #include "mgr/Command.h"
17 #include <openssl/ssl.h>
19 /// TODO: Replace on real size.
20 #define SSL_CTX_SIZE 1024
25 /** Reports cached SSL certificate stats to Cache Manager.
26 * TODO: Use "Report" functions instead friend class.
28 class CertificateStorageAction
: public Mgr::Action
31 CertificateStorageAction(const Mgr::Command::Pointer
&cmd
);
32 static Pointer
Create(const Mgr::Command::Pointer
&cmd
);
33 virtual void dump (StoreEntry
*sentry
);
35 * We do not support aggregation of information across workers
36 * TODO: aggregate these stats
38 virtual bool aggregatable() const { return false; }
42 * Memory cache for store generated SSL context. Enforces total size limits
43 * using an LRU algorithm.
45 class LocalContextStorage
47 friend class CertificateStorageAction
;
49 /// Cache item is an (SSL_CTX, host name) tuple.
53 Item(SSL_CTX
* aSsl_ctx
, std::string
const & aName
);
56 SSL_CTX
* ssl_ctx
; ///< The SSL context.
57 std::string host_name
; ///< The host name of the SSL context.
60 typedef std::list
<Item
*> Queue
;
61 typedef Queue::iterator QueueIterator
;
63 /// host_name:queue_item mapping for fast lookups by host name
64 typedef std::map
<std::string
, QueueIterator
> Map
;
65 typedef Map::iterator MapIterator
;
66 typedef std::pair
<std::string
, QueueIterator
> MapPair
;
68 LocalContextStorage(size_t aMax_memory
);
69 ~LocalContextStorage();
70 /// Set maximum memory size for this storage.
71 void SetSize(size_t aMax_memory
);
72 /// Return a pointer to the added ssl_ctx or NULL if fails (eg. max cache size equal 0).
73 SSL_CTX
* add(char const * host_name
, SSL_CTX
* ssl_ctx
);
74 /// Find SSL_CTX in storage by host name. Lru queue will be updated.
75 SSL_CTX
* find(char const * host_name
);
76 void remove(char const * host_name
); ///< Delete the SSL context by hostname
79 void purgeOne(); ///< Delete oldest object.
80 /// Delete object by iterator. It is used in deletePurge() and remove(...) methods.
81 void deleteAt(MapIterator i
);
83 size_t max_memory
; ///< Max cache size.
84 size_t memory_used
; ///< Used cache size.
85 Map storage
; ///< The hostnames/SSL_CTX * pairs
86 Queue lru_queue
; ///< LRU cache index
89 /// Class for storing/manipulating LocalContextStorage per local listening address/port.
90 class GlobalContextStorage
92 friend class CertificateStorageAction
;
94 GlobalContextStorage();
95 ~GlobalContextStorage();
96 /// Create new SSL context storage for the local listening address/port.
97 void addLocalStorage(Ip::Address
const & address
, size_t size_of_store
);
98 /// Return the local storage for the given listening address/port.
99 LocalContextStorage
& getLocalStorage(Ip::Address
const & address
);
100 /// When reconfigring should be called this method.
101 void reconfigureStart();
103 /// Called by getLocalStorage method
104 void reconfigureFinish();
105 bool reconfiguring
; ///< True if system reconfiguring now.
106 /// Storage used on configure or reconfigure.
107 std::map
<Ip::Address
, size_t> configureStorage
;
108 /// Map for storing all local ip address and their local storages.
109 std::map
<Ip::Address
, LocalContextStorage
*> storage
;
112 /// Global cache for store all SSL server certificates.
113 extern GlobalContextStorage TheGlobalContextStorage
;
117 #endif // SQUID_SSL_CONTEXT_STORAGE_H