michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __NSCLIENTAUTHREMEMBER_H__ michael@0: #define __NSCLIENTAUTHREMEMBER_H__ michael@0: michael@0: #include "mozilla/ReentrantMonitor.h" michael@0: #include "nsTHashtable.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsIX509Cert.h" michael@0: #include "nsNSSCertificate.h" michael@0: #include "nsString.h" michael@0: #include "nsWeakReference.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsClientAuthRemember michael@0: { michael@0: public: michael@0: michael@0: nsClientAuthRemember() michael@0: { michael@0: } michael@0: michael@0: nsClientAuthRemember(const nsClientAuthRemember &other) michael@0: { michael@0: this->operator=(other); michael@0: } michael@0: michael@0: nsClientAuthRemember &operator=(const nsClientAuthRemember &other) michael@0: { michael@0: mAsciiHost = other.mAsciiHost; michael@0: mFingerprint = other.mFingerprint; michael@0: mDBKey = other.mDBKey; michael@0: return *this; michael@0: } michael@0: michael@0: nsCString mAsciiHost; michael@0: nsCString mFingerprint; michael@0: nsCString mDBKey; michael@0: }; michael@0: michael@0: michael@0: // hash entry class michael@0: class nsClientAuthRememberEntry MOZ_FINAL : public PLDHashEntryHdr michael@0: { michael@0: public: michael@0: // Hash methods michael@0: typedef const char* KeyType; michael@0: typedef const char* KeyTypePointer; michael@0: michael@0: // do nothing with aHost - we require mHead to be set before we're live! michael@0: nsClientAuthRememberEntry(KeyTypePointer aHostWithCertUTF8) michael@0: { michael@0: } michael@0: michael@0: nsClientAuthRememberEntry(const nsClientAuthRememberEntry& toCopy) michael@0: { michael@0: mSettings = toCopy.mSettings; michael@0: } michael@0: michael@0: ~nsClientAuthRememberEntry() michael@0: { michael@0: } michael@0: michael@0: KeyType GetKey() const michael@0: { michael@0: return HostWithCertPtr(); michael@0: } michael@0: michael@0: KeyTypePointer GetKeyPointer() const michael@0: { michael@0: return HostWithCertPtr(); michael@0: } michael@0: michael@0: bool KeyEquals(KeyTypePointer aKey) const michael@0: { michael@0: return !strcmp(HostWithCertPtr(), aKey); michael@0: } michael@0: michael@0: static KeyTypePointer KeyToPointer(KeyType aKey) michael@0: { michael@0: return aKey; michael@0: } michael@0: michael@0: static PLDHashNumber HashKey(KeyTypePointer aKey) michael@0: { michael@0: // PL_DHashStringKey doesn't use the table parameter, so we can safely michael@0: // pass nullptr michael@0: return PL_DHashStringKey(nullptr, aKey); michael@0: } michael@0: michael@0: enum { ALLOW_MEMMOVE = false }; michael@0: michael@0: // get methods michael@0: inline const nsCString &HostWithCert() const { return mHostWithCert; } michael@0: michael@0: inline KeyTypePointer HostWithCertPtr() const michael@0: { michael@0: return mHostWithCert.get(); michael@0: } michael@0: michael@0: nsClientAuthRemember mSettings; michael@0: nsCString mHostWithCert; michael@0: }; michael@0: michael@0: class nsClientAuthRememberService MOZ_FINAL : public nsIObserver, michael@0: public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: nsClientAuthRememberService(); michael@0: ~nsClientAuthRememberService(); michael@0: michael@0: nsresult Init(); michael@0: michael@0: static void GetHostWithCert(const nsACString & aHostName, michael@0: const nsACString & nickname, nsACString& _retval); michael@0: michael@0: nsresult RememberDecision(const nsACString & aHostName, michael@0: CERTCertificate *aServerCert, CERTCertificate *aClientCert); michael@0: nsresult HasRememberedDecision(const nsACString & aHostName, michael@0: CERTCertificate *aServerCert, michael@0: nsACString & aCertDBKey, bool *_retval); michael@0: michael@0: void ClearRememberedDecisions(); michael@0: static void ClearAllRememberedDecisions(); michael@0: michael@0: protected: michael@0: mozilla::ReentrantMonitor monitor; michael@0: nsTHashtable mSettingsTable; michael@0: michael@0: void RemoveAllFromMemory(); michael@0: nsresult AddEntryToList(const nsACString &host, michael@0: const nsACString &server_fingerprint, michael@0: const nsACString &db_key); michael@0: }; michael@0: michael@0: #endif