security/manager/ssl/src/nsClientAuthRemember.h

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

     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/. */
     7 #ifndef __NSCLIENTAUTHREMEMBER_H__
     8 #define __NSCLIENTAUTHREMEMBER_H__
    10 #include "mozilla/ReentrantMonitor.h"
    11 #include "nsTHashtable.h"
    12 #include "nsIObserver.h"
    13 #include "nsIX509Cert.h"
    14 #include "nsNSSCertificate.h"
    15 #include "nsString.h"
    16 #include "nsWeakReference.h"
    17 #include "mozilla/Attributes.h"
    19 class nsClientAuthRemember
    20 {
    21 public:
    23   nsClientAuthRemember()
    24   {
    25   }
    27   nsClientAuthRemember(const nsClientAuthRemember &other)
    28   {
    29     this->operator=(other);
    30   }
    32   nsClientAuthRemember &operator=(const nsClientAuthRemember &other)
    33   {
    34     mAsciiHost = other.mAsciiHost;
    35     mFingerprint = other.mFingerprint;
    36     mDBKey = other.mDBKey;
    37     return *this;
    38   }
    40   nsCString mAsciiHost;
    41   nsCString mFingerprint;
    42   nsCString mDBKey;
    43 };
    46 // hash entry class
    47 class nsClientAuthRememberEntry MOZ_FINAL : public PLDHashEntryHdr
    48 {
    49   public:
    50     // Hash methods
    51     typedef const char* KeyType;
    52     typedef const char* KeyTypePointer;
    54     // do nothing with aHost - we require mHead to be set before we're live!
    55     nsClientAuthRememberEntry(KeyTypePointer aHostWithCertUTF8)
    56     {
    57     }
    59     nsClientAuthRememberEntry(const nsClientAuthRememberEntry& toCopy)
    60     {
    61       mSettings = toCopy.mSettings;
    62     }
    64     ~nsClientAuthRememberEntry()
    65     {
    66     }
    68     KeyType GetKey() const
    69     {
    70       return HostWithCertPtr();
    71     }
    73     KeyTypePointer GetKeyPointer() const
    74     {
    75       return HostWithCertPtr();
    76     }
    78     bool KeyEquals(KeyTypePointer aKey) const
    79     {
    80       return !strcmp(HostWithCertPtr(), aKey);
    81     }
    83     static KeyTypePointer KeyToPointer(KeyType aKey)
    84     {
    85       return aKey;
    86     }
    88     static PLDHashNumber HashKey(KeyTypePointer aKey)
    89     {
    90       // PL_DHashStringKey doesn't use the table parameter, so we can safely
    91       // pass nullptr
    92       return PL_DHashStringKey(nullptr, aKey);
    93     }
    95     enum { ALLOW_MEMMOVE = false };
    97     // get methods
    98     inline const nsCString &HostWithCert() const { return mHostWithCert; }
   100     inline KeyTypePointer HostWithCertPtr() const
   101     {
   102       return mHostWithCert.get();
   103     }
   105     nsClientAuthRemember mSettings;
   106     nsCString mHostWithCert;
   107 };
   109 class nsClientAuthRememberService MOZ_FINAL : public nsIObserver,
   110                                               public nsSupportsWeakReference
   111 {
   112 public:
   113   NS_DECL_THREADSAFE_ISUPPORTS
   114   NS_DECL_NSIOBSERVER
   116   nsClientAuthRememberService();
   117   ~nsClientAuthRememberService();
   119   nsresult Init();
   121   static void GetHostWithCert(const nsACString & aHostName, 
   122                               const nsACString & nickname, nsACString& _retval);
   124   nsresult RememberDecision(const nsACString & aHostName, 
   125                             CERTCertificate *aServerCert, CERTCertificate *aClientCert);
   126   nsresult HasRememberedDecision(const nsACString & aHostName, 
   127                                  CERTCertificate *aServerCert, 
   128                                  nsACString & aCertDBKey, bool *_retval);
   130   void ClearRememberedDecisions();
   131   static void ClearAllRememberedDecisions();
   133 protected:
   134     mozilla::ReentrantMonitor monitor;
   135     nsTHashtable<nsClientAuthRememberEntry> mSettingsTable;
   137     void RemoveAllFromMemory();
   138     nsresult AddEntryToList(const nsACString &host, 
   139                             const nsACString &server_fingerprint,
   140                             const nsACString &db_key);
   141 };
   143 #endif

mercurial