Bug 1502774 - Part 1: Remove XPCOM component registrations for HTTP authenticator classes r=valentin

Differential Revision: https://phabricator.services.mozilla.com/D10025

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2018-10-29 14:40:29 +00:00
parent 9cfb46e7a6
commit 7a780d8462
14 changed files with 133 additions and 51 deletions

View File

@ -7,18 +7,6 @@
//-----------------------------------------------------------------------------
#define NS_HTTPNEGOTIATEAUTH_CID \
{ /* 75c80fd0-accb-432c-af59-ec60668c3990 */ \
0x75c80fd0, \
0xaccb, \
0x432c, \
{0xaf, 0x59, 0xec, 0x60, 0x66, 0x8c, 0x39, 0x90} \
}
#include "nsHttpNegotiateAuth.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpNegotiateAuth)
//-----------------------------------------------------------------------------
#define NS_NEGOTIATEAUTH_CID \
{ /* 96ec4163-efc8-407a-8735-007fb26be4e8 */ \
0x96ec4163, \
@ -184,7 +172,6 @@ NS_DEFINE_NAMED_CID(NS_SYSNTLMAUTH_CID);
#else
NS_DEFINE_NAMED_CID(NS_SAMBANTLMAUTH_CID);
#endif
NS_DEFINE_NAMED_CID(NS_HTTPNEGOTIATEAUTH_CID);
NS_DEFINE_NAMED_CID(NS_AUTHSASL_CID);
@ -198,7 +185,6 @@ static const mozilla::Module::CIDEntry kAuthCIDs[] = {
#else
{ &kNS_SAMBANTLMAUTH_CID, false, nullptr, nsSambaNTLMAuthConstructor },
#endif
{ &kNS_HTTPNEGOTIATEAUTH_CID, false, nullptr, nsHttpNegotiateAuthConstructor },
{ &kNS_AUTHSASL_CID, false, nullptr, nsAuthSASLConstructor },
{ nullptr }
};
@ -213,7 +199,6 @@ static const mozilla::Module::ContractIDEntry kAuthContracts[] = {
#elif !defined(XP_MACOSX)
{ NS_AUTH_MODULE_CONTRACTID_PREFIX "sys-ntlm", &kNS_SAMBANTLMAUTH_CID },
#endif
{ NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX "negotiate", &kNS_HTTPNEGOTIATEAUTH_CID },
{ NS_AUTH_MODULE_CONTRACTID_PREFIX "sasl-gssapi", &kNS_AUTHSASL_CID },
{ nullptr }
};

View File

@ -49,6 +49,7 @@
#include "nsICancelable.h"
#include "nsUnicharUtils.h"
#include "mozilla/net/HttpAuthUtils.h"
#include "mozilla/ClearOnShutdown.h"
using mozilla::Base64Decode;
@ -62,6 +63,8 @@ static const char kNegotiateAuthAllowNonFqdn[] = "network.negotiate-auth.allow-n
static const char kNegotiateAuthSSPI[] = "network.auth.use-sspi";
static const char kSSOinPBmode[] = "network.auth.private-browsing-sso";
mozilla::StaticRefPtr<nsHttpNegotiateAuth> nsHttpNegotiateAuth::gSingleton;
#define kNegotiateLen (sizeof(kNegotiate)-1)
#define DEFAULT_THREAD_TIMEOUT_MS 30000
@ -105,6 +108,21 @@ TestNotInPBMode(nsIHttpAuthenticableChannel *authChannel, bool proxyAuth)
return false;
}
already_AddRefed<nsIHttpAuthenticator>
nsHttpNegotiateAuth::GetOrCreate()
{
nsCOMPtr<nsIHttpAuthenticator> authenticator;
if (gSingleton) {
authenticator = gSingleton;
} else {
gSingleton = new nsHttpNegotiateAuth();
mozilla::ClearOnShutdown(&gSingleton);
authenticator = gSingleton;
}
return authenticator.forget();
}
NS_IMETHODIMP
nsHttpNegotiateAuth::GetAuthFlags(uint32_t *flags)
{
@ -382,12 +400,8 @@ class GetNextTokenRunnable final : public mozilla::Runnable
nsresult rv;
// Use negotiate service to call GenerateCredentials outside of main thread
nsAutoCString contractId;
contractId.AssignLiteral(NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX);
contractId.AppendLiteral("negotiate");
nsCOMPtr<nsIHttpAuthenticator> authenticator =
do_GetService(contractId.get(), &rv);
NS_ENSURE_SUCCESS(rv, rv);
new nsHttpNegotiateAuth();
nsISupports *sessionState = mSessionState;
nsISupports *continuationState = mContinuationState;

View File

@ -10,6 +10,7 @@
#include "nsIURI.h"
#include "mozilla/Attributes.h"
#include "mozilla/LazyIdleThread.h"
#include "mozilla/StaticPtr.h"
// The nsHttpNegotiateAuth class provides responses for the GSS-API Negotiate method
// as specified by Microsoft in draft-brezak-spnego-http-04.txt
@ -20,6 +21,8 @@ public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIHTTPAUTHENTICATOR
static already_AddRefed<nsIHttpAuthenticator> GetOrCreate();
private:
~nsHttpNegotiateAuth() {}
@ -31,5 +34,8 @@ private:
// Thread for GenerateCredentialsAsync
RefPtr<mozilla::LazyIdleThread> mNegotiateThread;
// Singleton pointer
static mozilla::StaticRefPtr<nsHttpNegotiateAuth> gSingleton;
};
#endif /* nsHttpNegotiateAuth_h__ */

View File

@ -233,22 +233,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFtpProtocolHandler, Init)
#undef LOG
#undef LOG_ENABLED
#include "nsHttpAuthManager.h"
#include "nsHttpBasicAuth.h"
#include "nsHttpDigestAuth.h"
#include "nsHttpNTLMAuth.h"
#include "nsHttpActivityDistributor.h"
#include "ThrottleQueue.h"
#undef LOG
#undef LOG_ENABLED
namespace mozilla {
namespace net {
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpNTLMAuth)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsHttpHandler, nsHttpHandler::GetInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpsHandler, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpAuthManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpActivityDistributor)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpBasicAuth)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpDigestAuth)
NS_GENERIC_FACTORY_CONSTRUCTOR(ThrottleQueue)
} // namespace net
} // namespace mozilla
@ -684,9 +678,6 @@ NS_DEFINE_NAMED_CID(NS_MIMEHEADERPARAM_CID);
NS_DEFINE_NAMED_CID(NS_FILEPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_HTTPPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_HTTPSPROTOCOLHANDLER_CID);
NS_DEFINE_NAMED_CID(NS_HTTPBASICAUTH_CID);
NS_DEFINE_NAMED_CID(NS_HTTPDIGESTAUTH_CID);
NS_DEFINE_NAMED_CID(NS_HTTPNTLMAUTH_CID);
NS_DEFINE_NAMED_CID(NS_HTTPAUTHMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_HTTPACTIVITYDISTRIBUTOR_CID);
NS_DEFINE_NAMED_CID(NS_THROTTLEQUEUE_CID);
@ -791,9 +782,6 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_FILEPROTOCOLHANDLER_CID, false, nullptr, nsFileProtocolHandlerConstructor },
{ &kNS_HTTPPROTOCOLHANDLER_CID, false, nullptr, mozilla::net::nsHttpHandlerConstructor },
{ &kNS_HTTPSPROTOCOLHANDLER_CID, false, nullptr, mozilla::net::nsHttpsHandlerConstructor },
{ &kNS_HTTPBASICAUTH_CID, false, nullptr, mozilla::net::nsHttpBasicAuthConstructor },
{ &kNS_HTTPDIGESTAUTH_CID, false, nullptr, mozilla::net::nsHttpDigestAuthConstructor },
{ &kNS_HTTPNTLMAUTH_CID, false, nullptr, mozilla::net::nsHttpNTLMAuthConstructor },
{ &kNS_HTTPAUTHMANAGER_CID, false, nullptr, mozilla::net::nsHttpAuthManagerConstructor },
{ &kNS_HTTPACTIVITYDISTRIBUTOR_CID, false, nullptr, mozilla::net::nsHttpActivityDistributorConstructor },
{ &kNS_THROTTLEQUEUE_CID, false, nullptr, mozilla::net::ThrottleQueueConstructor },
@ -905,9 +893,6 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "file", &kNS_FILEPROTOCOLHANDLER_CID },
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &kNS_HTTPPROTOCOLHANDLER_CID },
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "https", &kNS_HTTPSPROTOCOLHANDLER_CID },
{ NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX "basic", &kNS_HTTPBASICAUTH_CID },
{ NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX "digest", &kNS_HTTPDIGESTAUTH_CID },
{ NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX "ntlm", &kNS_HTTPNTLMAUTH_CID },
{ NS_HTTPAUTHMANAGER_CONTRACTID, &kNS_HTTPAUTHMANAGER_CID },
{ NS_HTTPACTIVITYDISTRIBUTOR_CONTRACTID, &kNS_HTTPACTIVITYDISTRIBUTOR_CID },
{ NS_THROTTLEQUEUE_CONTRACTID, &kNS_THROTTLEQUEUE_CID },

View File

@ -133,6 +133,7 @@ FINAL_LIBRARY = 'xul'
LOCAL_INCLUDES += [
'/dom/base',
'/extensions/auth',
'/netwerk/base',
'/netwerk/cookie',
]

View File

@ -10,10 +10,28 @@
#include "plstr.h"
#include "nsString.h"
#include "mozilla/Base64.h"
#include "mozilla/ClearOnShutdown.h"
namespace mozilla {
namespace net {
StaticRefPtr<nsHttpBasicAuth> nsHttpBasicAuth::gSingleton;
already_AddRefed<nsIHttpAuthenticator>
nsHttpBasicAuth::GetOrCreate()
{
nsCOMPtr<nsIHttpAuthenticator> authenticator;
if (gSingleton) {
authenticator = gSingleton;
} else {
gSingleton = new nsHttpBasicAuth();
ClearOnShutdown(&gSingleton);
authenticator = gSingleton;
}
return authenticator.forget();
}
//-----------------------------------------------------------------------------
// nsHttpBasicAuth::nsISupports
//-----------------------------------------------------------------------------

View File

@ -7,6 +7,8 @@
#define nsBasicAuth_h__
#include "nsIHttpAuthenticator.h"
#include "mozilla/RefPtr.h"
#include "mozilla/StaticPtr.h"
namespace mozilla { namespace net {
@ -22,8 +24,13 @@ public:
NS_DECL_NSIHTTPAUTHENTICATOR
nsHttpBasicAuth() = default;
static already_AddRefed<nsIHttpAuthenticator> GetOrCreate();
private:
virtual ~nsHttpBasicAuth() = default;
static StaticRefPtr<nsHttpBasicAuth> gSingleton;
};
} // namespace net

View File

@ -25,6 +25,10 @@
#include "nsIHttpAuthenticableChannel.h"
#include "nsIURI.h"
#include "nsContentUtils.h"
#include "nsHttpBasicAuth.h"
#include "nsHttpDigestAuth.h"
#include "nsHttpNegotiateAuth.h"
#include "nsHttpNTLMAuth.h"
#include "nsServiceManagerUtils.h"
#include "nsILoadContext.h"
#include "nsIURL.h"
@ -1095,11 +1099,23 @@ nsHttpChannelAuthProvider::GetAuthenticator(const char *challenge,
// normalize to lowercase
ToLowerCase(authType);
nsAutoCString contractid;
contractid.AssignLiteral(NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX);
contractid.Append(authType);
nsCOMPtr<nsIHttpAuthenticator> authenticator;
if (authType.EqualsLiteral("negotiate")) {
authenticator = nsHttpNegotiateAuth::GetOrCreate();
} else if (authType.EqualsLiteral("basic")) {
authenticator = nsHttpBasicAuth::GetOrCreate();
} else if (authType.EqualsLiteral("digest")) {
authenticator = nsHttpDigestAuth::GetOrCreate();
} else if (authType.EqualsLiteral("ntlm")) {
authenticator = nsHttpNTLMAuth::GetOrCreate();
} else {
return NS_ERROR_SERVICE_NOT_FOUND;
}
return CallGetService(contractid.get(), auth);
MOZ_ASSERT(authenticator);
authenticator.forget(auth);
return NS_OK;
}
void

View File

@ -7,6 +7,7 @@
// HttpLog.h should generally be included first
#include "HttpLog.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Sprintf.h"
#include "mozilla/Unused.h"
@ -25,6 +26,23 @@
namespace mozilla {
namespace net {
StaticRefPtr<nsHttpDigestAuth> nsHttpDigestAuth::gSingleton;
already_AddRefed<nsIHttpAuthenticator>
nsHttpDigestAuth::GetOrCreate()
{
nsCOMPtr<nsIHttpAuthenticator> authenticator;
if (gSingleton) {
authenticator = gSingleton;
} else {
gSingleton = new nsHttpDigestAuth();
ClearOnShutdown(&gSingleton);
authenticator = gSingleton;
}
return authenticator.forget();
}
//-----------------------------------------------------------------------------
// nsHttpDigestAuth::nsISupports
//-----------------------------------------------------------------------------

View File

@ -11,6 +11,7 @@
#include "nsStringFwd.h"
#include "nsCOMPtr.h"
#include "mozilla/Attributes.h"
#include "mozilla/StaticPtr.h"
class nsICryptoHash;
@ -38,6 +39,8 @@ class nsHttpDigestAuth final : public nsIHttpAuthenticator
nsHttpDigestAuth() = default;
static already_AddRefed<nsIHttpAuthenticator> GetOrCreate();
protected:
~nsHttpDigestAuth() = default;
@ -87,6 +90,8 @@ class nsHttpDigestAuth final : public nsIHttpAuthenticator
protected:
nsCOMPtr<nsICryptoHash> mVerifier;
char mHashBuf[DIGEST_LENGTH];
static StaticRefPtr<nsHttpDigestAuth> gSingleton;
};
} // namespace net

View File

@ -35,6 +35,7 @@
#include "nsIChannel.h"
#include "nsUnicharUtils.h"
#include "mozilla/net/HttpAuthUtils.h"
#include "mozilla/ClearOnShutdown.h"
namespace mozilla {
namespace net {
@ -45,6 +46,8 @@ static const char kTrustedURIs[] = "network.automatic-ntlm-auth.trusted-uris";
static const char kForceGeneric[] = "network.auth.force-generic-ntlm";
static const char kSSOinPBmode[] = "network.auth.private-browsing-sso";
StaticRefPtr<nsHttpNTLMAuth> nsHttpNTLMAuth::gSingleton;
static bool
IsNonFqdn(nsIURI *uri)
{
@ -144,6 +147,21 @@ NS_IMPL_ISUPPORTS0(nsNTLMSessionState)
//-----------------------------------------------------------------------------
already_AddRefed<nsIHttpAuthenticator>
nsHttpNTLMAuth::GetOrCreate()
{
nsCOMPtr<nsIHttpAuthenticator> authenticator;
if (gSingleton) {
authenticator = gSingleton;
} else {
gSingleton = new nsHttpNTLMAuth();
ClearOnShutdown(&gSingleton);
authenticator = gSingleton;
}
return authenticator.forget();
}
NS_IMPL_ISUPPORTS(nsHttpNTLMAuth, nsIHttpAuthenticator)
NS_IMETHODIMP

View File

@ -6,6 +6,7 @@
#define nsHttpNTLMAuth_h__
#include "nsIHttpAuthenticator.h"
#include "mozilla/StaticPtr.h"
namespace mozilla { namespace net {
@ -17,12 +18,16 @@ public:
nsHttpNTLMAuth() : mUseNative(false) {}
static already_AddRefed<nsIHttpAuthenticator> GetOrCreate();
private:
virtual ~nsHttpNTLMAuth() = default;
// This flag indicates whether we are using the native NTLM implementation
// or the internal one.
bool mUseNative;
static StaticRefPtr<nsHttpNTLMAuth> gSingleton;
};
} // namespace net

View File

@ -9,11 +9,15 @@
#include "base/basictypes.h"
#include "nsHttpBasicAuth.h"
#include "nsHttpChunkedDecoder.h"
#include "nsHttpDigestAuth.h"
#include "nsHttpHandler.h"
#include "nsHttpTransaction.h"
#include "nsHttpNegotiateAuth.h"
#include "nsHttpNTLMAuth.h"
#include "nsHttpRequestHead.h"
#include "nsHttpResponseHead.h"
#include "nsHttpChunkedDecoder.h"
#include "nsHttpTransaction.h"
#include "nsTransportUtils.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
@ -2022,12 +2026,17 @@ nsHttpTransaction::CheckForStickyAuthSchemeAt(nsHttpAtom const& header)
while (p.ReadWord(schema)) {
ToLowerCase(schema);
nsAutoCString contractid;
contractid.AssignLiteral(NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX);
contractid.Append(schema);
// using a new instance because of thread safety of auth modules refcnt
nsCOMPtr<nsIHttpAuthenticator> authenticator(do_CreateInstance(contractid.get()));
nsCOMPtr<nsIHttpAuthenticator> authenticator;
if (schema.EqualsLiteral("negotiate")) {
authenticator = new nsHttpNegotiateAuth();
} else if (schema.EqualsLiteral("basic")) {
authenticator = new nsHttpBasicAuth();
} else if (schema.EqualsLiteral("digest")) {
authenticator = new nsHttpDigestAuth();
} else if (schema.EqualsLiteral("ntlm")) {
authenticator = new nsHttpNTLMAuth();
}
if (authenticator) {
uint32_t flags;
nsresult rv = authenticator->GetAuthFlags(&flags);

View File

@ -219,8 +219,3 @@ interface nsIHttpAuthenticator : nsISupports
*/
const unsigned long IDENTITY_ENCRYPTED = (1<<12);
};
%{C++
#define NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX \
"@mozilla.org/network/http-authenticator;1?scheme="
%}