Source code

Revision control

Other Tools

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef SSLTokensCache_h_
6
#define SSLTokensCache_h_
7
8
#include "nsIMemoryReporter.h"
9
#include "nsClassHashtable.h"
10
#include "nsTArray.h"
11
#include "mozilla/Maybe.h"
12
#include "mozilla/StaticMutex.h"
13
#include "mozilla/StaticPtr.h"
14
#include "nsXULAppAPI.h"
15
#include "TransportSecurityInfo.h" // For EVStatus
16
17
namespace mozilla {
18
namespace net {
19
20
struct SessionCacheInfo {
21
psm::EVStatus mEVStatus = psm::EVStatus::NotEV;
22
uint16_t mCertificateTransparencyStatus =
23
nsITransportSecurityInfo::CERTIFICATE_TRANSPARENCY_NOT_APPLICABLE;
24
nsTArray<uint8_t> mServerCertBytes;
25
Maybe<nsTArray<nsTArray<uint8_t>>> mSucceededCertChainBytes;
26
};
27
28
class SSLTokensCache : public nsIMemoryReporter {
29
public:
30
NS_DECL_THREADSAFE_ISUPPORTS
31
NS_DECL_NSIMEMORYREPORTER
32
33
friend class ExpirationComparator;
34
35
static nsresult Init();
36
static nsresult Shutdown();
37
38
static bool IsEnabled() { return sEnabled; }
39
40
static nsresult Put(const nsACString& aKey, const uint8_t* aToken,
41
uint32_t aTokenLen, nsITransportSecurityInfo* aSecInfo);
42
static nsresult Get(const nsACString& aKey, nsTArray<uint8_t>& aToken);
43
static bool GetSessionCacheInfo(const nsACString& aKey,
44
SessionCacheInfo& aResult);
45
static nsresult Remove(const nsACString& aKey);
46
47
private:
48
SSLTokensCache();
49
virtual ~SSLTokensCache();
50
51
nsresult RemoveLocked(const nsACString& aKey);
52
53
void InitPrefs();
54
void EvictIfNecessary();
55
void LogStats();
56
57
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
58
59
static mozilla::StaticRefPtr<SSLTokensCache> gInstance;
60
static StaticMutex sLock;
61
62
static Atomic<bool, Relaxed> sEnabled;
63
// Capacity of the cache in kilobytes
64
static Atomic<uint32_t, Relaxed> sCapacity;
65
66
uint32_t mCacheSize; // Actual cache size in bytes
67
68
class TokenCacheRecord {
69
public:
70
uint32_t Size() const;
71
void Reset();
72
73
nsCString mKey;
74
PRUint32 mExpirationTime;
75
nsTArray<uint8_t> mToken;
76
SessionCacheInfo mSessionCacheInfo;
77
};
78
79
nsClassHashtable<nsCStringHashKey, TokenCacheRecord> mTokenCacheRecords;
80
nsTArray<TokenCacheRecord*> mExpirationArray;
81
};
82
83
} // namespace net
84
} // namespace mozilla
85
86
#endif // SSLTokensCache_h_