1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/manager/ssl/src/nsClientAuthRemember.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef __NSCLIENTAUTHREMEMBER_H__ 1.11 +#define __NSCLIENTAUTHREMEMBER_H__ 1.12 + 1.13 +#include "mozilla/ReentrantMonitor.h" 1.14 +#include "nsTHashtable.h" 1.15 +#include "nsIObserver.h" 1.16 +#include "nsIX509Cert.h" 1.17 +#include "nsNSSCertificate.h" 1.18 +#include "nsString.h" 1.19 +#include "nsWeakReference.h" 1.20 +#include "mozilla/Attributes.h" 1.21 + 1.22 +class nsClientAuthRemember 1.23 +{ 1.24 +public: 1.25 + 1.26 + nsClientAuthRemember() 1.27 + { 1.28 + } 1.29 + 1.30 + nsClientAuthRemember(const nsClientAuthRemember &other) 1.31 + { 1.32 + this->operator=(other); 1.33 + } 1.34 + 1.35 + nsClientAuthRemember &operator=(const nsClientAuthRemember &other) 1.36 + { 1.37 + mAsciiHost = other.mAsciiHost; 1.38 + mFingerprint = other.mFingerprint; 1.39 + mDBKey = other.mDBKey; 1.40 + return *this; 1.41 + } 1.42 + 1.43 + nsCString mAsciiHost; 1.44 + nsCString mFingerprint; 1.45 + nsCString mDBKey; 1.46 +}; 1.47 + 1.48 + 1.49 +// hash entry class 1.50 +class nsClientAuthRememberEntry MOZ_FINAL : public PLDHashEntryHdr 1.51 +{ 1.52 + public: 1.53 + // Hash methods 1.54 + typedef const char* KeyType; 1.55 + typedef const char* KeyTypePointer; 1.56 + 1.57 + // do nothing with aHost - we require mHead to be set before we're live! 1.58 + nsClientAuthRememberEntry(KeyTypePointer aHostWithCertUTF8) 1.59 + { 1.60 + } 1.61 + 1.62 + nsClientAuthRememberEntry(const nsClientAuthRememberEntry& toCopy) 1.63 + { 1.64 + mSettings = toCopy.mSettings; 1.65 + } 1.66 + 1.67 + ~nsClientAuthRememberEntry() 1.68 + { 1.69 + } 1.70 + 1.71 + KeyType GetKey() const 1.72 + { 1.73 + return HostWithCertPtr(); 1.74 + } 1.75 + 1.76 + KeyTypePointer GetKeyPointer() const 1.77 + { 1.78 + return HostWithCertPtr(); 1.79 + } 1.80 + 1.81 + bool KeyEquals(KeyTypePointer aKey) const 1.82 + { 1.83 + return !strcmp(HostWithCertPtr(), aKey); 1.84 + } 1.85 + 1.86 + static KeyTypePointer KeyToPointer(KeyType aKey) 1.87 + { 1.88 + return aKey; 1.89 + } 1.90 + 1.91 + static PLDHashNumber HashKey(KeyTypePointer aKey) 1.92 + { 1.93 + // PL_DHashStringKey doesn't use the table parameter, so we can safely 1.94 + // pass nullptr 1.95 + return PL_DHashStringKey(nullptr, aKey); 1.96 + } 1.97 + 1.98 + enum { ALLOW_MEMMOVE = false }; 1.99 + 1.100 + // get methods 1.101 + inline const nsCString &HostWithCert() const { return mHostWithCert; } 1.102 + 1.103 + inline KeyTypePointer HostWithCertPtr() const 1.104 + { 1.105 + return mHostWithCert.get(); 1.106 + } 1.107 + 1.108 + nsClientAuthRemember mSettings; 1.109 + nsCString mHostWithCert; 1.110 +}; 1.111 + 1.112 +class nsClientAuthRememberService MOZ_FINAL : public nsIObserver, 1.113 + public nsSupportsWeakReference 1.114 +{ 1.115 +public: 1.116 + NS_DECL_THREADSAFE_ISUPPORTS 1.117 + NS_DECL_NSIOBSERVER 1.118 + 1.119 + nsClientAuthRememberService(); 1.120 + ~nsClientAuthRememberService(); 1.121 + 1.122 + nsresult Init(); 1.123 + 1.124 + static void GetHostWithCert(const nsACString & aHostName, 1.125 + const nsACString & nickname, nsACString& _retval); 1.126 + 1.127 + nsresult RememberDecision(const nsACString & aHostName, 1.128 + CERTCertificate *aServerCert, CERTCertificate *aClientCert); 1.129 + nsresult HasRememberedDecision(const nsACString & aHostName, 1.130 + CERTCertificate *aServerCert, 1.131 + nsACString & aCertDBKey, bool *_retval); 1.132 + 1.133 + void ClearRememberedDecisions(); 1.134 + static void ClearAllRememberedDecisions(); 1.135 + 1.136 +protected: 1.137 + mozilla::ReentrantMonitor monitor; 1.138 + nsTHashtable<nsClientAuthRememberEntry> mSettingsTable; 1.139 + 1.140 + void RemoveAllFromMemory(); 1.141 + nsresult AddEntryToList(const nsACString &host, 1.142 + const nsACString &server_fingerprint, 1.143 + const nsACString &db_key); 1.144 +}; 1.145 + 1.146 +#endif