Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/security/manager/ssl/nsClientAuthRemember.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 *
3
 * This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef __NSCLIENTAUTHREMEMBER_H__
8
#define __NSCLIENTAUTHREMEMBER_H__
9
10
#include "mozilla/HashFunctions.h"
11
#include "mozilla/Move.h"
12
#include "mozilla/ReentrantMonitor.h"
13
#include "nsTHashtable.h"
14
#include "nsIObserver.h"
15
#include "nsIX509Cert.h"
16
#include "nsNSSCertificate.h"
17
#include "nsString.h"
18
#include "nsWeakReference.h"
19
#include "mozilla/Attributes.h"
20
21
namespace mozilla {
22
  class OriginAttributes;
23
}
24
25
using mozilla::OriginAttributes;
26
27
class nsClientAuthRemember
28
{
29
public:
30
31
  nsClientAuthRemember()
32
0
  {
33
0
  }
34
35
  nsClientAuthRemember(const nsClientAuthRemember& aOther)
36
0
  {
37
0
    this->operator=(aOther);
38
0
  }
39
40
  nsClientAuthRemember& operator=(const nsClientAuthRemember& aOther)
41
0
  {
42
0
    mAsciiHost = aOther.mAsciiHost;
43
0
    mFingerprint = aOther.mFingerprint;
44
0
    mDBKey = aOther.mDBKey;
45
0
    return *this;
46
0
  }
47
48
  nsCString mAsciiHost;
49
  nsCString mFingerprint;
50
  nsCString mDBKey;
51
};
52
53
54
// hash entry class
55
class nsClientAuthRememberEntry final : public PLDHashEntryHdr
56
{
57
  public:
58
    // Hash methods
59
    typedef const char* KeyType;
60
    typedef const char* KeyTypePointer;
61
62
    // do nothing with aHost - we require mHead to be set before we're live!
63
    explicit nsClientAuthRememberEntry(KeyTypePointer aHostWithCertUTF8)
64
0
    {
65
0
    }
66
67
    nsClientAuthRememberEntry(nsClientAuthRememberEntry&& aToMove)
68
      : PLDHashEntryHdr(std::move(aToMove))
69
      , mSettings(std::move(aToMove.mSettings))
70
      , mEntryKey(std::move(aToMove.mEntryKey))
71
0
    {
72
0
    }
73
74
    ~nsClientAuthRememberEntry()
75
0
    {
76
0
    }
77
78
    KeyType GetKey() const
79
0
    {
80
0
      return EntryKeyPtr();
81
0
    }
82
83
    KeyTypePointer GetKeyPointer() const
84
0
    {
85
0
      return EntryKeyPtr();
86
0
    }
87
88
    bool KeyEquals(KeyTypePointer aKey) const
89
0
    {
90
0
      return !strcmp(EntryKeyPtr(), aKey);
91
0
    }
92
93
    static KeyTypePointer KeyToPointer(KeyType aKey)
94
0
    {
95
0
      return aKey;
96
0
    }
97
98
    static PLDHashNumber HashKey(KeyTypePointer aKey)
99
0
    {
100
0
      return mozilla::HashString(aKey);
101
0
    }
102
103
    enum { ALLOW_MEMMOVE = false };
104
105
    // get methods
106
0
    inline const nsCString& GetEntryKey() const { return mEntryKey; }
107
108
    inline KeyTypePointer EntryKeyPtr() const
109
0
    {
110
0
      return mEntryKey.get();
111
0
    }
112
113
    nsClientAuthRemember mSettings;
114
    nsCString mEntryKey;
115
};
116
117
class nsClientAuthRememberService final : public nsIObserver,
118
                                          public nsSupportsWeakReference
119
{
120
public:
121
  NS_DECL_THREADSAFE_ISUPPORTS
122
  NS_DECL_NSIOBSERVER
123
124
  nsClientAuthRememberService();
125
126
  nsresult Init();
127
128
  static void GetEntryKey(const nsACString& aHostName,
129
                          const OriginAttributes& aOriginAttributes,
130
                          const nsACString& aFingerprint,
131
                          /*out*/ nsACString& aEntryKey);
132
133
  nsresult RememberDecision(const nsACString& aHostName,
134
                            const OriginAttributes& aOriginAttributes,
135
                            CERTCertificate* aServerCert,
136
                            CERTCertificate* aClientCert);
137
138
  nsresult HasRememberedDecision(const nsACString& aHostName,
139
                                 const OriginAttributes& aOriginAttributes,
140
                                 CERTCertificate* aServerCert,
141
                                 nsACString& aCertDBKey, bool* aRetVal);
142
143
  void ClearRememberedDecisions();
144
  static void ClearAllRememberedDecisions();
145
146
protected:
147
    ~nsClientAuthRememberService();
148
149
    mozilla::ReentrantMonitor monitor;
150
    nsTHashtable<nsClientAuthRememberEntry> mSettingsTable;
151
152
    void RemoveAllFromMemory();
153
    nsresult AddEntryToList(const nsACString& aHost,
154
                            const OriginAttributes& aOriginAttributes,
155
                            const nsACString& aServerFingerprint,
156
                            const nsACString& aDBKey);
157
};
158
159
#endif