LCOV - code coverage report
Current view: directory - security/manager/ssl/src - nsClientAuthRemember.h (source / functions) Found Hit Coverage
Test: app.info Lines: 27 0 0.0 %
Date: 2012-06-02 Functions: 10 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Red Hat, Inc.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2008
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Kai Engert <kengert@redhat.com>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef __NSCLIENTAUTHREMEMBER_H__
      41                 : #define __NSCLIENTAUTHREMEMBER_H__
      42                 : 
      43                 : #include "mozilla/ReentrantMonitor.h"
      44                 : #include "nsTHashtable.h"
      45                 : #include "nsIObserver.h"
      46                 : #include "nsIX509Cert.h"
      47                 : #include "nsAutoPtr.h"
      48                 : #include "nsNSSCertificate.h"
      49                 : #include "nsString.h"
      50                 : #include "nsWeakReference.h"
      51                 : 
      52                 : class nsClientAuthRemember
      53               0 : {
      54                 : public:
      55                 : 
      56               0 :   nsClientAuthRemember()
      57               0 :   {
      58               0 :   }
      59                 :   
      60                 :   nsClientAuthRemember(const nsClientAuthRemember &other)
      61                 :   {
      62                 :     this->operator=(other);
      63                 :   }
      64                 : 
      65               0 :   nsClientAuthRemember &operator=(const nsClientAuthRemember &other)
      66                 :   {
      67               0 :     mAsciiHost = other.mAsciiHost;
      68               0 :     mFingerprint = other.mFingerprint;
      69               0 :     mDBKey = other.mDBKey;
      70               0 :     return *this;
      71                 :   }
      72                 : 
      73                 :   nsCString mAsciiHost;
      74                 :   nsCString mFingerprint;
      75                 :   nsCString mDBKey;
      76                 : };
      77                 : 
      78                 : 
      79                 : // hash entry class
      80                 : class nsClientAuthRememberEntry : public PLDHashEntryHdr
      81                 : {
      82                 :   public:
      83                 :     // Hash methods
      84                 :     typedef const char* KeyType;
      85                 :     typedef const char* KeyTypePointer;
      86                 : 
      87                 :     // do nothing with aHost - we require mHead to be set before we're live!
      88               0 :     nsClientAuthRememberEntry(KeyTypePointer aHostWithCertUTF8)
      89               0 :     {
      90               0 :     }
      91                 : 
      92               0 :     nsClientAuthRememberEntry(const nsClientAuthRememberEntry& toCopy)
      93               0 :     {
      94               0 :       mSettings = toCopy.mSettings;
      95               0 :     }
      96                 : 
      97               0 :     ~nsClientAuthRememberEntry()
      98               0 :     {
      99               0 :     }
     100                 : 
     101                 :     KeyType GetKey() const
     102                 :     {
     103                 :       return HostWithCertPtr();
     104                 :     }
     105                 : 
     106                 :     KeyTypePointer GetKeyPointer() const
     107                 :     {
     108                 :       return HostWithCertPtr();
     109                 :     }
     110                 : 
     111               0 :     bool KeyEquals(KeyTypePointer aKey) const
     112                 :     {
     113               0 :       return !strcmp(HostWithCertPtr(), aKey);
     114                 :     }
     115                 : 
     116               0 :     static KeyTypePointer KeyToPointer(KeyType aKey)
     117                 :     {
     118               0 :       return aKey;
     119                 :     }
     120                 : 
     121               0 :     static PLDHashNumber HashKey(KeyTypePointer aKey)
     122                 :     {
     123                 :       // PL_DHashStringKey doesn't use the table parameter, so we can safely
     124                 :       // pass nsnull
     125               0 :       return PL_DHashStringKey(nsnull, aKey);
     126                 :     }
     127                 : 
     128                 :     enum { ALLOW_MEMMOVE = false };
     129                 : 
     130                 :     // get methods
     131                 :     inline const nsCString &HostWithCert() const { return mHostWithCert; }
     132                 : 
     133               0 :     inline KeyTypePointer HostWithCertPtr() const
     134                 :     {
     135               0 :       return mHostWithCert.get();
     136                 :     }
     137                 : 
     138                 :     nsClientAuthRemember mSettings;
     139                 :     nsCString mHostWithCert;
     140                 : };
     141                 : 
     142                 : class nsClientAuthRememberService : public nsIObserver,
     143                 :                                     public nsSupportsWeakReference
     144                 : {
     145                 : public:
     146                 :   NS_DECL_ISUPPORTS
     147                 :   NS_DECL_NSIOBSERVER
     148                 : 
     149                 :   nsClientAuthRememberService();
     150                 :   ~nsClientAuthRememberService();
     151                 : 
     152                 :   nsresult Init();
     153                 : 
     154                 :   static void GetHostWithCert(const nsACString & aHostName, 
     155                 :                               const nsACString & nickname, nsACString& _retval);
     156                 : 
     157                 :   nsresult RememberDecision(const nsACString & aHostName, 
     158                 :                             CERTCertificate *aServerCert, CERTCertificate *aClientCert);
     159                 :   nsresult HasRememberedDecision(const nsACString & aHostName, 
     160                 :                                  CERTCertificate *aServerCert, 
     161                 :                                  nsACString & aCertDBKey, bool *_retval);
     162                 : 
     163                 :   void ClearRememberedDecisions();
     164                 : 
     165                 : protected:
     166                 :     mozilla::ReentrantMonitor monitor;
     167                 :     nsTHashtable<nsClientAuthRememberEntry> mSettingsTable;
     168                 : 
     169                 :     void RemoveAllFromMemory();
     170                 :     nsresult AddEntryToList(const nsACString &host, 
     171                 :                             const nsACString &server_fingerprint,
     172                 :                             const nsACString &db_key);
     173                 : };
     174                 : 
     175                 : #endif

Generated by: LCOV version 1.7