security/manager/ssl/src/nsClientAuthRemember.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial