2009-05-21 02:21:51 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-31 13:33:35 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-05-21 02:21:51 +04:00
|
|
|
|
|
|
|
#ifndef __NSCLIENTAUTHREMEMBER_H__
|
|
|
|
#define __NSCLIENTAUTHREMEMBER_H__
|
|
|
|
|
2011-04-29 23:21:57 +04:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2009-05-21 02:21:51 +04:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIX509Cert.h"
|
|
|
|
#include "nsNSSCertificate.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWeakReference.h"
|
2012-07-19 08:37:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2009-05-21 02:21:51 +04:00
|
|
|
|
2016-11-25 12:28:22 +03:00
|
|
|
namespace mozilla {
|
2017-01-12 19:38:48 +03:00
|
|
|
class OriginAttributes;
|
2016-11-25 12:28:22 +03:00
|
|
|
}
|
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
using mozilla::OriginAttributes;
|
2016-11-25 12:28:22 +03:00
|
|
|
|
2009-05-21 02:21:51 +04:00
|
|
|
class nsClientAuthRemember
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsClientAuthRemember()
|
|
|
|
{
|
|
|
|
}
|
2016-12-01 07:06:40 +03:00
|
|
|
|
|
|
|
nsClientAuthRemember(const nsClientAuthRemember& aOther)
|
2009-05-21 02:21:51 +04:00
|
|
|
{
|
2016-12-01 07:06:40 +03:00
|
|
|
this->operator=(aOther);
|
2009-05-21 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
2016-12-01 07:06:40 +03:00
|
|
|
nsClientAuthRemember& operator=(const nsClientAuthRemember& aOther)
|
2009-05-21 02:21:51 +04:00
|
|
|
{
|
2016-12-01 07:06:40 +03:00
|
|
|
mAsciiHost = aOther.mAsciiHost;
|
|
|
|
mFingerprint = aOther.mFingerprint;
|
|
|
|
mDBKey = aOther.mDBKey;
|
2009-05-21 02:21:51 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString mAsciiHost;
|
|
|
|
nsCString mFingerprint;
|
|
|
|
nsCString mDBKey;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// hash entry class
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsClientAuthRememberEntry final : public PLDHashEntryHdr
|
2009-05-21 02:21:51 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Hash methods
|
|
|
|
typedef const char* KeyType;
|
|
|
|
typedef const char* KeyTypePointer;
|
|
|
|
|
|
|
|
// do nothing with aHost - we require mHead to be set before we're live!
|
2014-09-01 03:26:27 +04:00
|
|
|
explicit nsClientAuthRememberEntry(KeyTypePointer aHostWithCertUTF8)
|
2009-05-21 02:21:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-01 07:06:40 +03:00
|
|
|
nsClientAuthRememberEntry(const nsClientAuthRememberEntry& aToCopy)
|
2009-05-21 02:21:51 +04:00
|
|
|
{
|
2016-12-01 07:06:40 +03:00
|
|
|
mSettings = aToCopy.mSettings;
|
2009-05-21 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~nsClientAuthRememberEntry()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyType GetKey() const
|
|
|
|
{
|
2016-12-01 07:06:40 +03:00
|
|
|
return EntryKeyPtr();
|
2009-05-21 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
KeyTypePointer GetKeyPointer() const
|
|
|
|
{
|
2016-12-01 07:06:40 +03:00
|
|
|
return EntryKeyPtr();
|
2009-05-21 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool KeyEquals(KeyTypePointer aKey) const
|
2009-05-21 02:21:51 +04:00
|
|
|
{
|
2016-12-01 07:06:40 +03:00
|
|
|
return !strcmp(EntryKeyPtr(), aKey);
|
2009-05-21 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey)
|
|
|
|
{
|
|
|
|
return aKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
|
|
|
{
|
2016-03-16 07:33:44 +03:00
|
|
|
return PLDHashTable::HashStringKey(aKey);
|
2009-05-21 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
enum { ALLOW_MEMMOVE = false };
|
2009-05-21 02:21:51 +04:00
|
|
|
|
|
|
|
// get methods
|
2016-12-01 07:06:40 +03:00
|
|
|
inline const nsCString& GetEntryKey() const { return mEntryKey; }
|
2009-05-21 02:21:51 +04:00
|
|
|
|
2016-12-01 07:06:40 +03:00
|
|
|
inline KeyTypePointer EntryKeyPtr() const
|
2009-05-21 02:21:51 +04:00
|
|
|
{
|
2016-12-01 07:06:40 +03:00
|
|
|
return mEntryKey.get();
|
2009-05-21 02:21:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsClientAuthRemember mSettings;
|
2016-12-01 07:06:40 +03:00
|
|
|
nsCString mEntryKey;
|
2009-05-21 02:21:51 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsClientAuthRememberService final : public nsIObserver,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsSupportsWeakReference
|
2009-05-21 02:21:51 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 06:24:14 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-05-21 02:21:51 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
nsClientAuthRememberService();
|
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
|
2016-11-25 12:28:22 +03:00
|
|
|
static void GetEntryKey(const nsACString& aHostName,
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes& aOriginAttributes,
|
2016-11-25 12:28:22 +03:00
|
|
|
const nsACString& aFingerprint,
|
2016-12-01 07:06:40 +03:00
|
|
|
/*out*/ nsACString& aEntryKey);
|
2016-11-25 12:28:22 +03:00
|
|
|
|
|
|
|
nsresult RememberDecision(const nsACString& aHostName,
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes& aOriginAttributes,
|
2016-11-25 12:28:22 +03:00
|
|
|
CERTCertificate* aServerCert,
|
|
|
|
CERTCertificate* aClientCert);
|
2009-05-21 02:21:51 +04:00
|
|
|
|
2016-11-25 12:28:22 +03:00
|
|
|
nsresult HasRememberedDecision(const nsACString& aHostName,
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes& aOriginAttributes,
|
2016-11-25 12:28:22 +03:00
|
|
|
CERTCertificate* aServerCert,
|
|
|
|
nsACString& aCertDBKey, bool* aRetVal);
|
2009-05-21 02:21:51 +04:00
|
|
|
|
|
|
|
void ClearRememberedDecisions();
|
2012-12-07 07:05:27 +04:00
|
|
|
static void ClearAllRememberedDecisions();
|
2009-05-21 02:21:51 +04:00
|
|
|
|
|
|
|
protected:
|
2014-06-24 02:40:03 +04:00
|
|
|
~nsClientAuthRememberService();
|
|
|
|
|
2011-04-29 23:21:57 +04:00
|
|
|
mozilla::ReentrantMonitor monitor;
|
2009-05-21 02:21:51 +04:00
|
|
|
nsTHashtable<nsClientAuthRememberEntry> mSettingsTable;
|
|
|
|
|
|
|
|
void RemoveAllFromMemory();
|
2016-11-25 12:28:22 +03:00
|
|
|
nsresult AddEntryToList(const nsACString& aHost,
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes& aOriginAttributes,
|
2016-11-25 12:28:22 +03:00
|
|
|
const nsACString& aServerFingerprint,
|
|
|
|
const nsACString& aDBKey);
|
2009-05-21 02:21:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|