adding crypto stuff to the tip
git-svn-id: svn://10.0.0.236/trunk@62624 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -69,6 +69,7 @@ DIRS += \
|
||||
widget/timer \
|
||||
include \
|
||||
modules/libutil \
|
||||
security \
|
||||
netwerk \
|
||||
uriloader \
|
||||
intl \
|
||||
|
||||
@@ -322,6 +322,7 @@ netwerk/protocol/ftp/src/Makefile
|
||||
netwerk/protocol/http/Makefile
|
||||
netwerk/protocol/http/public/Makefile
|
||||
netwerk/protocol/http/src/Makefile
|
||||
netwerk/protocol/http/res/Makefile
|
||||
netwerk/protocol/jar/Makefile
|
||||
netwerk/protocol/jar/public/Makefile
|
||||
netwerk/protocol/jar/src/Makefile
|
||||
@@ -335,8 +336,13 @@ netwerk/protocol/resource/src/Makefile
|
||||
netwerk/mime/Makefile
|
||||
netwerk/mime/public/Makefile
|
||||
netwerk/mime/src/Makefile
|
||||
netwerk/security/Makefile
|
||||
netwerk/security/browser/Makefile
|
||||
netwerk/security/psm/Makefile
|
||||
netwerk/socket/Makefile
|
||||
netwerk/socket/base/Makefile
|
||||
netwerk/socket/ssl/Makefile
|
||||
netwerk/socket/tests/Makefile
|
||||
netwerk/streamconv/Makefile
|
||||
netwerk/streamconv/converters/Makefile
|
||||
netwerk/streamconv/public/Makefile
|
||||
@@ -638,6 +644,12 @@ embedding/browser/build/Makefile
|
||||
embedding/browser/webBrowser/Makefile
|
||||
embedding/browser/setup/Makefile
|
||||
|
||||
# Security Makefiles
|
||||
security/Makefile
|
||||
security/psm/Makefile
|
||||
security/psm/lib/Makefile
|
||||
security/psm/lib/client/Makefile
|
||||
security/psm/lib/protocol/Makefile
|
||||
|
||||
# xpfe/browser/public/Makefile
|
||||
|
||||
|
||||
@@ -117,6 +117,10 @@ pull_nspr:
|
||||
cd $(MOZ_SRC)\.
|
||||
$(CVSCO_NSPR) mozilla/nsprpub
|
||||
|
||||
pull_psm:
|
||||
cd $(MOZ_SRC)\.
|
||||
$(CVSCO_PSM) mozilla/security
|
||||
|
||||
# pull either layout only or seamonkey the browser
|
||||
pull_layout:
|
||||
cd $(MOZ_SRC)\.
|
||||
@@ -131,14 +135,19 @@ pull_seamonkey:
|
||||
# nmake has to be hardcoded, or we have to depend on mozilla/config
|
||||
# being pulled already to figure out what $(NMAKE) should be.
|
||||
|
||||
clobber_all: clobber_nspr clobber_seamonkey
|
||||
clobber_all: clobber_nspr clobber_psm clobber_seamonkey
|
||||
|
||||
build_all: build_nspr build_seamonkey
|
||||
build_all: build_nspr build_psm build_seamonkey
|
||||
|
||||
clobber_nspr:
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\nsprpub
|
||||
nmake -f makefile.win clobber_all
|
||||
|
||||
clobber_psm:
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\security
|
||||
nmake -f makefile.win clobber_all
|
||||
|
||||
|
||||
clobber_seamonkey:
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
|
||||
-rd /s /q dist
|
||||
@@ -158,6 +167,10 @@ build_nspr:
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\nsprpub
|
||||
nmake -f makefile.win export
|
||||
|
||||
build_psm:
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\security
|
||||
nmake -f makefile.win export
|
||||
|
||||
build_seamonkey:
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
|
||||
set DIST_DIRS=1
|
||||
@@ -190,6 +203,8 @@ install:
|
||||
export:
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\nsprpub
|
||||
nmake -f makefile.win export
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\security
|
||||
nmake -f makefile.win export
|
||||
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
|
||||
set DIST_DIRS=1
|
||||
set LAYOUT_DIRS=1
|
||||
|
||||
@@ -145,6 +145,20 @@ else
|
||||
endif
|
||||
|
||||
|
||||
#######################################################################
|
||||
# PSM client libs
|
||||
#
|
||||
|
||||
PSM_CO_MODULE= mozilla/security
|
||||
PSM_CO_FLAGS := -P
|
||||
CVSCO_PSM = cvs $(CVS_FLAGS) co $(PSM_CO_FLAGS)
|
||||
PSM_CO_TAG = SeaMonkey_M14_BRANCH
|
||||
|
||||
ifdef PSM_CO_TAG
|
||||
PSM_CO_FLAGS := $(PSM_CO_FLAGS) -r $(PSM_CO_TAG)
|
||||
endif
|
||||
|
||||
|
||||
#######################################################################
|
||||
# NSPR
|
||||
#
|
||||
@@ -204,6 +218,11 @@ real_checkout:
|
||||
($(CVSCO_NSPR) $(NSPR_CO_MODULE) || touch cvs-failed.tmp) 2>&1 \
|
||||
| tee -a $(CVSCO_LOGFILE); \
|
||||
if test -f cvs-failed.tmp; then exit 1; else true; fi; \
|
||||
: Checkout PSM client libs; \
|
||||
echo $(CVSCO_PSM) $(PSM_CO_MODULE); \
|
||||
($(CVSCO_PSM) $(PSM_CO_MODULE) || touch cvs-failed.tmp) 2>&1 \
|
||||
| tee -a $(CVSCO_LOGFILE); \
|
||||
if test -f cvs-failed.tmp; then exit 1; else true; fi; \
|
||||
: Checkout the SeaMonkeyAll; \
|
||||
echo $(CVSCO) $(MOZ_CO_MODULE); \
|
||||
($(CVSCO) $(MOZ_CO_MODULE) || touch cvs-failed.tmp) 2>&1 \
|
||||
|
||||
@@ -54,6 +54,7 @@ DIRS = \
|
||||
db \
|
||||
dbm \
|
||||
modules\libutil \
|
||||
security \
|
||||
netwerk \
|
||||
widget\timer \
|
||||
js \
|
||||
|
||||
@@ -35,6 +35,7 @@ DIRS = \
|
||||
protocol \
|
||||
mime \
|
||||
streamconv \
|
||||
security \
|
||||
$(NULL)
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
|
||||
@@ -27,6 +27,7 @@ DIRS= \
|
||||
cache \
|
||||
base \
|
||||
dns \
|
||||
security \
|
||||
socket \
|
||||
mime \
|
||||
streamconv \
|
||||
|
||||
@@ -26,7 +26,7 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
DIRS = public src res
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
DEPTH=..\..\..
|
||||
DIRS= \
|
||||
public \
|
||||
src \
|
||||
src \
|
||||
res \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
1
mozilla/netwerk/protocol/http/res/MANIFEST
Normal file
1
mozilla/netwerk/protocol/http/res/MANIFEST
Normal file
@@ -0,0 +1 @@
|
||||
psm.js
|
||||
42
mozilla/netwerk/protocol/http/res/Makefile.in
Normal file
42
mozilla/netwerk/protocol/http/res/Makefile.in
Normal file
@@ -0,0 +1,42 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
FILES_DIR = $(DIST)/bin/chrome/netwerk/content/default/https/
|
||||
|
||||
EXPORT_RESOURCES = \
|
||||
$(srcdir)/psm.js \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
install::
|
||||
$(INSTALL) $(EXPORT_RESOURCES) $(FILES_DIR)
|
||||
|
||||
|
||||
|
||||
34
mozilla/netwerk/protocol/http/res/makefile.win
Normal file
34
mozilla/netwerk/protocol/http/res/makefile.win
Normal file
@@ -0,0 +1,34 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
DISTBROWSWER=$(DIST)\bin\chrome\netwerk\content\default\https\
|
||||
|
||||
install::
|
||||
$(MAKE_INSTALL) psm.js $(DISTBROWSWER)
|
||||
|
||||
clobber::
|
||||
rm -f $(DISTBROWSER)\successful.gif
|
||||
rm -f $(DISTBROWSER)\failure.gif
|
||||
7
mozilla/netwerk/protocol/http/res/psm.js
Normal file
7
mozilla/netwerk/protocol/http/res/psm.js
Normal file
@@ -0,0 +1,7 @@
|
||||
function displaySecurityAdvisor()
|
||||
{
|
||||
var psm = Components.classes["component://netscape/psm"].getService();
|
||||
psm = psm.QueryInterface(Components.interfaces.nsIPSMComponent);
|
||||
psm.DisplaySecurityAdvisor( null );
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ CPPSRCS = \
|
||||
nsBasicAuth.cpp \
|
||||
nsAuth.cpp \
|
||||
nsAuthEngine.cpp \
|
||||
nsHTTPSHandler.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
|
||||
@@ -39,11 +39,12 @@ DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
LLIBS= $(LLIBS) \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\necko.lib \
|
||||
$(DIST)\lib\necko.lib \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsHTTPSHandler.obj \
|
||||
.\$(OBJDIR)\nsHTTPHandler.obj \
|
||||
.\$(OBJDIR)\nsHTTPHandlerModule.obj \
|
||||
.\$(OBJDIR)\nsHTTPChannel.obj \
|
||||
@@ -55,7 +56,7 @@ CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsHTTPEncodeStream.obj \
|
||||
.\$(OBJDIR)\nsBasicAuth.obj \
|
||||
.\$(OBJDIR)\nsAuth.obj \
|
||||
.\$(OBJDIR)\nsAuthEngine.obj \
|
||||
.\$(OBJDIR)\nsAuthEngine.obj \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES=-I.
|
||||
|
||||
@@ -27,17 +27,25 @@
|
||||
|
||||
#include "nsIHTTPProtocolHandler.h"
|
||||
#include "nsHTTPHandler.h"
|
||||
#include "nsHTTPSHandler.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHTTPHandler, Init);
|
||||
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTTPSHandler);
|
||||
|
||||
#define NS_HTTPS_HANDLER_FACTORY_CID { 0xd2771480, 0xcac4, 0x11d3, { 0x8c, 0xaf, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "HTTP Handler",
|
||||
NS_IHTTPHANDLER_CID,
|
||||
NS_NETWORK_PROTOCOL_PROGID_PREFIX "http",
|
||||
nsHTTPHandlerConstructor }
|
||||
nsHTTPHandlerConstructor },
|
||||
{ "HTTPS Handler",
|
||||
NS_HTTPS_HANDLER_FACTORY_CID,
|
||||
NS_NETWORK_PROTOCOL_PROGID_PREFIX "https",
|
||||
nsHTTPSHandler::Create }
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsHTTPHandlerModule", components)
|
||||
|
||||
69
mozilla/netwerk/protocol/http/src/nsHTTPSHandler.cpp
Normal file
69
mozilla/netwerk/protocol/http/src/nsHTTPSHandler.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsHTTPSHandler.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
|
||||
nsHTTPSHandler::nsHTTPSHandler()
|
||||
: nsHTTPHandler()
|
||||
{
|
||||
}
|
||||
|
||||
nsHTTPSHandler::~nsHTTPSHandler()
|
||||
{
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPSHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
if (aOuter) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsHTTPSHandler* handler = new nsHTTPSHandler();
|
||||
if (!handler) return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(handler);
|
||||
rv = handler->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete handler;
|
||||
return rv;
|
||||
}
|
||||
rv = handler->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(handler);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsHTTPSHandler::CreateTransport(const char* host, PRInt32 port, const char* printHost,
|
||||
PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize,
|
||||
nsIChannel** o_pTrans)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, sts, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rv = sts->CreateTransportOfType("ssl", host, port, printHost, bufferSegmentSize, bufferMaxSize, o_pTrans);
|
||||
}
|
||||
|
||||
79
mozilla/netwerk/protocol/http/src/nsHTTPSHandler.h
Normal file
79
mozilla/netwerk/protocol/http/src/nsHTTPSHandler.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _nsHTTPSHandler_h_
|
||||
#define _nsHTTPSHandler_h_
|
||||
|
||||
#include "nsHTTPHandler.h"
|
||||
|
||||
#include "nsIHTTPProtocolHandler.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
class nsIChannel;
|
||||
class nsHTTPChannel;
|
||||
|
||||
class nsHTTPSHandler : public nsHTTPHandler
|
||||
{
|
||||
public:
|
||||
|
||||
nsHTTPSHandler(void);
|
||||
virtual ~nsHTTPSHandler();
|
||||
static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
//Functions from nsIProtocolHandler
|
||||
/*
|
||||
GetDefaultPort returns the default port associated with this
|
||||
protocol.
|
||||
*/
|
||||
NS_IMETHOD GetDefaultPort(PRInt32 *result)
|
||||
{
|
||||
static const PRInt32 defaultPort = 443;
|
||||
*result = defaultPort;
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
/*
|
||||
The GetScheme function uniquely identifies the scheme this handler
|
||||
is associated with.
|
||||
*/
|
||||
NS_IMETHOD GetScheme(char * *o_Scheme)
|
||||
{
|
||||
static const char* scheme = "https";
|
||||
*o_Scheme = nsCRT::strdup(scheme);
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called to create a transport from RequestTransport to accually
|
||||
* make a new channel.
|
||||
**/
|
||||
|
||||
virtual nsresult CreateTransport(const char* host, PRInt32 port,
|
||||
const char* printHost,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel** o_pTrans);
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPSHandler_h_ */
|
||||
33
mozilla/netwerk/security/Makefile.in
Normal file
33
mozilla/netwerk/security/Makefile.in
Normal file
@@ -0,0 +1,33 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = browser psm
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
3
mozilla/netwerk/security/browser/MANIFEST_CONTENT
Normal file
3
mozilla/netwerk/security/browser/MANIFEST_CONTENT
Normal file
@@ -0,0 +1,3 @@
|
||||
NavSecurityOverlay.xul
|
||||
NavSecurityUI.js
|
||||
NavSecurityOverlay.css
|
||||
3
mozilla/netwerk/security/browser/MANIFEST_SKIN
Normal file
3
mozilla/netwerk/security/browser/MANIFEST_SKIN
Normal file
@@ -0,0 +1,3 @@
|
||||
lock.gif
|
||||
unlock.gif
|
||||
broken.gif
|
||||
67
mozilla/netwerk/security/browser/Makefile.in
Normal file
67
mozilla/netwerk/security/browser/Makefile.in
Normal file
@@ -0,0 +1,67 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = secureui
|
||||
|
||||
IS_COMPONENT = 1
|
||||
LIBRARY_NAME = secureui
|
||||
|
||||
CPPSRCS = \
|
||||
nsSecureBrowserUIImpl.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS = -L$(DIST)/lib -lxpcom
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsSecureBrowserUI.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
SKIN_DIR = $(DIST)/bin/chrome/navigator/skin/default/
|
||||
EXPORT_SKINS = \
|
||||
$(srcdir)/broken.gif \
|
||||
$(srcdir)/lock.gif \
|
||||
$(srcdir)/unlock.gif \
|
||||
$(srcdir)/NavSecurityOverlay.css \
|
||||
$(NULL)
|
||||
|
||||
CONTENT_DIR = $(DIST)/bin/chrome/navigator/content/default/
|
||||
EXPORT_CONTENT = \
|
||||
$(srcdir)/NavSecurityOverlay.xul \
|
||||
$(srcdir)/NavSecurityUI.js \
|
||||
$(NULL)
|
||||
|
||||
install::
|
||||
$(INSTALL) $(EXPORT_SKINS) $(SKIN_DIR)
|
||||
$(INSTALL) $(EXPORT_CONTENT) $(CONTENT_DIR)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
15
mozilla/netwerk/security/browser/NavSecurityOverlay.css
Normal file
15
mozilla/netwerk/security/browser/NavSecurityOverlay.css
Normal file
@@ -0,0 +1,15 @@
|
||||
titledbutton#security-button {
|
||||
list-style-image:url("chrome://navigator/skin/unlock.gif");
|
||||
}
|
||||
|
||||
titledbutton#security-button[level="high"] {
|
||||
list-style-image:url("chrome://navigator/skin/lock.gif");
|
||||
}
|
||||
|
||||
titledbutton#security-button[level="low"] {
|
||||
list-style-image:url("chrome://navigator/skin/lock.gif");
|
||||
}
|
||||
|
||||
titledbutton#security-button[level="broken"] {
|
||||
list-style-image:url("chrome://navigator/skin/broken.gif");
|
||||
}
|
||||
14
mozilla/netwerk/security/browser/NavSecurityOverlay.xul
Normal file
14
mozilla/netwerk/security/browser/NavSecurityOverlay.xul
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<overlay id="NavSecurityOverlay"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<?xml-stylesheet href="chrome://navigator/skin/NavSecurityOverlay.css" type="text/css"?>
|
||||
<html:script language="JavaScript" src="chrome://navigator/content/NavSecurityUI.js" />
|
||||
|
||||
<box id="state-box">
|
||||
<titledbutton id="security-button" class="borderless" align="left" onclick="displayPageInfo()"/>
|
||||
</box>
|
||||
|
||||
</overlay>
|
||||
44
mozilla/netwerk/security/browser/NavSecurityUI.js
Normal file
44
mozilla/netwerk/security/browser/NavSecurityUI.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
window.addEventListener("load", SetSecurityButton, false);
|
||||
|
||||
function SetSecurityButton()
|
||||
{
|
||||
dump("in SetSecurityButton\n");
|
||||
|
||||
var ui = Components.classes["component://netscape/secure_browser_ui"].getService();
|
||||
ui = ui.QueryInterface(Components.interfaces.nsSecureBrowserUI);
|
||||
|
||||
var button = document.getElementById('security-button');
|
||||
if (button && window.content)
|
||||
ui.init(window.content, button);
|
||||
}
|
||||
|
||||
function displayPageInfo()
|
||||
{
|
||||
var psm = Components.classes["component://netscape/psm"].getService();
|
||||
psm = psm.QueryInterface(Components.interfaces.nsIPSMComponent);
|
||||
psm.DisplaySecurityAdvisor( null );
|
||||
}
|
||||
|
||||
|
||||
BIN
mozilla/netwerk/security/browser/broken.gif
Normal file
BIN
mozilla/netwerk/security/browser/broken.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 B |
BIN
mozilla/netwerk/security/browser/lock.gif
Normal file
BIN
mozilla/netwerk/security/browser/lock.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 76 B |
72
mozilla/netwerk/security/browser/makefile.win
Normal file
72
mozilla/netwerk/security/browser/makefile.win
Normal file
@@ -0,0 +1,72 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
MODULE = secureui
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DLLNAME = secureui
|
||||
PDBFILE = $(DLLNAME).pdb
|
||||
MAPFILE = $(DLLNAME).map
|
||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
LINCS = $(LINCS) \
|
||||
-I$(PUBLIC) \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(NULL)
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsSecureBrowserUIImpl.obj \
|
||||
$(NULL)
|
||||
|
||||
XPIDL_INCLUDES=-I$(DEPTH)\..\mozilla\dist\idl
|
||||
|
||||
XPIDLSRCS= \
|
||||
.\nsSecureBrowserUI.idl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) broken.gif $(DIST)\bin\chrome\navigator\skin\default
|
||||
$(MAKE_INSTALL) lock.gif $(DIST)\bin\chrome\navigator\skin\default
|
||||
$(MAKE_INSTALL) unlock.gif $(DIST)\bin\chrome\navigator\skin\default
|
||||
$(MAKE_INSTALL) NavSecurityOverlay.xul $(DIST)\bin\chrome\navigator\content\default
|
||||
$(MAKE_INSTALL) NavSecurityUI.js $(DIST)\bin\chrome\navigator\content\default
|
||||
$(MAKE_INSTALL) NavSecurityOverlay.css $(DIST)\bin\chrome\navigator\skin\default
|
||||
|
||||
clobber::
|
||||
rm $(DIST)\bin\components\$(DLLNAME).dll
|
||||
rm $(DIST)\bin\chrome\navigator\skin\default\broken.gif
|
||||
rm $(DIST)\bin\chrome\navigator\skin\default\lock.gif
|
||||
rm $(DIST)\bin\chrome\navigator\skin\default\unlock.gif
|
||||
rm $(DIST)\bin\chrome\navigator\content\default\NavSecurityOverlay.xul
|
||||
rm $(DIST)\bin\chrome\navigator\skin\default\NavSecurityOverlay.css
|
||||
39
mozilla/netwerk/security/browser/nsSecureBrowserUI.idl
Normal file
39
mozilla/netwerk/security/browser/nsSecureBrowserUI.idl
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "domstubs.idl"
|
||||
|
||||
[scriptable, uuid(081e31e0-a144-11d3-8c7c-00609792278c)]
|
||||
interface nsSecureBrowserUI : nsISupports
|
||||
{
|
||||
void init(in nsIDOMWindow window, in nsIDOMElement button);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_SECURE_BROWSER_UI_PROGID "component://netscape/secure_browser_ui"
|
||||
#define NS_SECURE_BROWSER_UI_CLASSNAME "Mozilla Secure Browser UI Handler"
|
||||
|
||||
#define NS_SECURE_BROWSER_UI_CID \
|
||||
{ 0x10fe7ea0, 0xa10a, 0x11d3, {0x8c, 0x7c, 0x00, 0x60, 0x97, 0x92, 0x27, 0x8c}}
|
||||
|
||||
%}
|
||||
503
mozilla/netwerk/security/browser/nsSecureBrowserUIImpl.cpp
Normal file
503
mozilla/netwerk/security/browser/nsSecureBrowserUIImpl.cpp
Normal file
@@ -0,0 +1,503 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsSecureBrowserUI.h"
|
||||
#include "nsSecureBrowserUIImpl.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIChannel.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
|
||||
|
||||
#define ENTER_SITE_PREF "security.warn_entering_secure"
|
||||
#define LEAVE_SITE_PREF "security.warn_leaving_secure"
|
||||
#define MIXEDCONTENT_PREF "security.warn_viewing_mixed"
|
||||
#define INSECURE_SUBMIT_PREF "security.warn_submit_insecure"
|
||||
|
||||
|
||||
nsSecureBrowserUIImpl* nsSecureBrowserUIImpl::mInstance = nsnull;
|
||||
|
||||
nsSecureBrowserUIImpl::nsSecureBrowserUIImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsSecureBrowserUIImpl::~nsSecureBrowserUIImpl()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSecureBrowserUIImpl, nsSecureBrowserUI);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::CreateSecureBrowserUI(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (!aResult) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
*aResult = nsnull;
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
|
||||
if (mInstance == nsnull)
|
||||
{
|
||||
mInstance = new nsSecureBrowserUIImpl();
|
||||
}
|
||||
|
||||
if (mInstance == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = mInstance->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
*aResult = nsnull;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Init(nsIDOMWindow *window, nsIDOMElement *button)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
|
||||
if (sgo)
|
||||
{
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
if (docShell)
|
||||
{
|
||||
nsSecureBrowserObserver *sbo = new nsSecureBrowserObserver();
|
||||
if (sbo)
|
||||
{
|
||||
NS_ADDREF(sbo);
|
||||
return sbo->Init(button, docShell); // does the window delete us when it close?
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsSecureBrowserObserver::nsSecureBrowserObserver()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mIsSecureDocument = mMixContentAlertShown = mIsDocumentBroken = PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
nsSecureBrowserObserver::~nsSecureBrowserObserver()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSecureBrowserObserver, nsIDocumentLoaderObserver);
|
||||
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserObserver::Init(nsIDOMElement *button, nsIDocShell* content)
|
||||
{
|
||||
if (!button || !content)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mSecurityButton = button;
|
||||
content->GetDocLoaderObserver(getter_AddRefs(mOldWebShellObserver));
|
||||
content->SetDocLoaderObserver(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserObserver::OnStartDocumentLoad(nsIDocumentLoader* aLoader,
|
||||
nsIURI* aURL,
|
||||
const char* aCommand)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
if (mOldWebShellObserver)
|
||||
{
|
||||
mOldWebShellObserver->OnStartDocumentLoad(aLoader, aURL, aCommand);
|
||||
}
|
||||
|
||||
|
||||
if (!mSecurityButton)
|
||||
return NS_OK;
|
||||
|
||||
if (!aURL || !aLoader)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
|
||||
mIsSecureDocument = mMixContentAlertShown = mIsDocumentBroken = PR_FALSE;
|
||||
|
||||
// check to see that we are going to load the same
|
||||
// kind of URL (scheme) as we just loaded.
|
||||
|
||||
|
||||
PRBool isOldSchemeSecure;
|
||||
res = IsSecureDocumentLoad(aLoader, &isOldSchemeSecure);
|
||||
if (NS_FAILED(res))
|
||||
return NS_OK;
|
||||
|
||||
PRBool isNewSchemeSecure;
|
||||
res = IsSecureUrl(PR_FALSE, aURL, &isNewSchemeSecure);
|
||||
if (NS_FAILED(res))
|
||||
return NS_OK;
|
||||
|
||||
#if DEBUG_dougt
|
||||
printf("[StartPageLoad] isOldSchemeSecure = %d isNewSchemeSecure = %d\n", isOldSchemeSecure, isNewSchemeSecure);
|
||||
#endif
|
||||
// if we are going from a secure page to and insecure page
|
||||
if ( !isNewSchemeSecure && isOldSchemeSecure)
|
||||
{
|
||||
#if DEBUG_dougt
|
||||
printf("change lock icon to unlock - new document\n");
|
||||
#endif
|
||||
mSecurityButton->RemoveAttribute( "level" );
|
||||
|
||||
|
||||
PRBool boolpref;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
if ((prefs->GetBoolPref(LEAVE_SITE_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref)
|
||||
{
|
||||
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
dialog->Alert(nsString("You are leaving a secure document").GetUnicode()); // fix localize!
|
||||
}
|
||||
}
|
||||
// if we are going from an insecure page to a secure one.
|
||||
else if (isNewSchemeSecure && !isOldSchemeSecure)
|
||||
{
|
||||
PRBool boolpref;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
if ((prefs->GetBoolPref(ENTER_SITE_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref)
|
||||
{
|
||||
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
dialog->Alert(nsString("You are entering a secure document").GetUnicode()); // fix localize!
|
||||
}
|
||||
}
|
||||
|
||||
mIsSecureDocument = isNewSchemeSecure;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserObserver::OnEndDocumentLoad(nsIDocumentLoader* aLoader,
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (mOldWebShellObserver)
|
||||
{
|
||||
mOldWebShellObserver->OnEndDocumentLoad(aLoader, channel, aStatus);
|
||||
}
|
||||
|
||||
if (!mIsSecureDocument)
|
||||
return NS_OK;
|
||||
|
||||
if (!mSecurityButton)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
#if DEBUG_dougt
|
||||
printf("[EndPageLoad] mIsSecureDocument = %d aStatus = %d mIsDocumentBroken = %d\n", mIsSecureDocument, aStatus, mIsDocumentBroken);
|
||||
#endif
|
||||
|
||||
if ( NS_SUCCEEDED(aStatus) && !mIsDocumentBroken )
|
||||
{
|
||||
#if DEBUG_dougt
|
||||
printf("change lock icon to secure \n");
|
||||
#endif
|
||||
rv = mSecurityButton->SetAttribute( "level", nsString("high") );
|
||||
mIsSecureDocument = PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG_dougt
|
||||
printf("change lock icon to broken\n");
|
||||
#endif
|
||||
rv = mSecurityButton->SetAttribute( "level", nsString("broken") );
|
||||
mIsSecureDocument = PR_FALSE;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserObserver::OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel)
|
||||
{
|
||||
if (mOldWebShellObserver)
|
||||
{
|
||||
mOldWebShellObserver->OnStartURLLoad(loader, channel);
|
||||
}
|
||||
|
||||
#if DEBUG_dougt
|
||||
printf("[StartURLLoad] mIsSecureDocument = %d\n", mIsSecureDocument);
|
||||
#endif
|
||||
|
||||
PRBool secure;
|
||||
nsresult rv = IsSecureChannelLoad(channel, &secure);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (mIsSecureDocument && !secure)
|
||||
{
|
||||
mIsDocumentBroken = PR_TRUE;
|
||||
|
||||
// nsCOMPtr<nsIURI> uri;
|
||||
// channel->GetURI(getter_AddRefs(uri));
|
||||
|
||||
// uri->SetSpec("chrome://navigator/skin/insecureLink.gif"); //fix
|
||||
|
||||
nsresult res;
|
||||
|
||||
PRBool boolpref;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
if ((prefs->GetBoolPref(MIXEDCONTENT_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref && !mMixContentAlertShown)
|
||||
{
|
||||
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
dialog->Alert(nsString("There is mixed content on this page").GetUnicode()); // fix localize!
|
||||
mMixContentAlertShown = PR_TRUE;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserObserver::OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
PRUint32 aProgress,
|
||||
PRUint32 aProgressMax)
|
||||
{
|
||||
if (mOldWebShellObserver)
|
||||
{
|
||||
mOldWebShellObserver->OnProgressURLLoad(loader, channel, aProgress, aProgressMax);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserObserver::OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
nsString& aMsg)
|
||||
{
|
||||
if (mOldWebShellObserver)
|
||||
{
|
||||
mOldWebShellObserver->OnStatusURLLoad(loader, channel, aMsg);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserObserver::OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus)
|
||||
{
|
||||
if (mOldWebShellObserver)
|
||||
{
|
||||
mOldWebShellObserver->OnEndURLLoad(loader, channel, aStatus);
|
||||
}
|
||||
|
||||
#if DEBUG_dougt
|
||||
printf("[OnEndURLLoad] mIsSecureDocument = %d aStatus = %d\n", mIsSecureDocument, aStatus);
|
||||
#endif
|
||||
|
||||
if ( mIsSecureDocument && NS_FAILED(aStatus))
|
||||
{
|
||||
#if DEBUG_dougt
|
||||
printf("change lock icon to broken\n");
|
||||
#endif
|
||||
mSecurityButton->SetAttribute( "level", nsString("broken") );
|
||||
mIsDocumentBroken = PR_TRUE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// fileSecure flag determines if we should include file: and other local protocols.
|
||||
nsresult
|
||||
nsSecureBrowserObserver::IsSecureUrl(PRBool fileSecure, nsIURI* aURL, PRBool* value)
|
||||
{
|
||||
*value = PR_FALSE;
|
||||
|
||||
if (!aURL)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
#if DEBUG
|
||||
char* string;
|
||||
aURL->GetSpec(&string);
|
||||
printf("[ensuring channel]: %s\n", string);
|
||||
nsAllocator::Free(string);
|
||||
#endif
|
||||
|
||||
char* scheme;
|
||||
aURL->GetScheme(&scheme);
|
||||
|
||||
if (scheme == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if ( (strncmp(scheme, "https", 5) == 0) ||
|
||||
(fileSecure &&
|
||||
(strncmp(scheme, "file", 4) == 0) ))
|
||||
*value = PR_TRUE;
|
||||
|
||||
nsAllocator::Free(scheme);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
nsresult nsSecureBrowserObserver::IsSecureDocumentLoad(nsIDocumentLoader* loader, PRBool *value)
|
||||
{
|
||||
if (!loader)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = GetURIFromDocumentLoader(loader, getter_AddRefs(uri));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return IsSecureUrl(PR_FALSE, uri, value);
|
||||
}
|
||||
|
||||
nsresult nsSecureBrowserObserver::IsSecureChannelLoad(nsIChannel* channel, PRBool *value)
|
||||
{
|
||||
if (!channel)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = channel->GetURI(getter_AddRefs(uri));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return IsSecureUrl(PR_TRUE, uri, value);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserObserver::GetURIFromDocumentLoader(nsIDocumentLoader* aLoader, nsIURI** uri)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (aLoader == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsISupports> cont;
|
||||
rv = aLoader->GetContainer(getter_AddRefs(cont));
|
||||
if (NS_FAILED(rv) || (cont == nsnull))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(cont));
|
||||
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
rv = docShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if (NS_FAILED(rv) || (cv == nsnull))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(cv));
|
||||
NS_ENSURE_TRUE(docViewer, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
rv = docViewer->GetDocument(*getter_AddRefs(doc));
|
||||
if (NS_FAILED(rv) || (doc == nsnull))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*uri = doc->GetDocumentURL();
|
||||
if (!*uri)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ NS_SECURE_BROWSER_UI_CLASSNAME,
|
||||
NS_SECURE_BROWSER_UI_CID,
|
||||
NS_SECURE_BROWSER_UI_PROGID,
|
||||
nsSecureBrowserUIImpl::CreateSecureBrowserUI
|
||||
},
|
||||
|
||||
{ NS_SECURE_BROWSER_DOCOBSERVER_CLASSNAME,
|
||||
NS_SECURE_BROWSER_DOCOBSERVER_CID,
|
||||
NS_SECURE_BROWSER_DOCOBSERVER_PROGID,
|
||||
nsSecureBrowserUIImpl::CreateSecureBrowserUI
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsSecureBrowserUIImpl", components)
|
||||
|
||||
92
mozilla/netwerk/security/browser/nsSecureBrowserUIImpl.h
Normal file
92
mozilla/netwerk/security/browser/nsSecureBrowserUIImpl.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsSecureBrowserUIImpl_h_
|
||||
#define nsSecureBrowserUIImpl_h_
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsSecureBrowserUI.h"
|
||||
#include "nsIDocShell.h"
|
||||
|
||||
#define NS_SECURE_BROWSER_DOCOBSERVER_CLASSNAME "Mozilla Secure Browser Doc Observer"
|
||||
|
||||
#define NS_SECURE_BROWSER_DOCOBSERVER_CID \
|
||||
{0x97c06c30, 0xa145, 0x11d3, \
|
||||
{0x8c, 0x7c, 0x00, 0x60, 0x97, 0x92, 0x27, 0x8c}}
|
||||
|
||||
#define NS_SECURE_BROWSER_DOCOBSERVER_PROGID "component://netscape/secure_browser_docobserver"
|
||||
|
||||
|
||||
class nsSecureBrowserObserver : public nsIDocumentLoaderObserver
|
||||
{
|
||||
public:
|
||||
|
||||
nsSecureBrowserObserver();
|
||||
virtual ~nsSecureBrowserObserver();
|
||||
|
||||
nsresult Init(nsIDOMElement *button, nsIDocShell* content);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDocumentLoaderObserver
|
||||
NS_DECL_NSIDOCUMENTLOADEROBSERVER
|
||||
|
||||
static nsresult IsSecureDocumentLoad(nsIDocumentLoader* loader, PRBool *value);
|
||||
static nsresult IsSecureChannelLoad(nsIChannel* channel, PRBool *value);
|
||||
static nsresult IsSecureUrl(PRBool fileSecure, nsIURI* aURL, PRBool *value);
|
||||
static nsresult GetURIFromDocumentLoader(nsIDocumentLoader* aLoader, nsIURI** uri);
|
||||
|
||||
protected:
|
||||
|
||||
nsCOMPtr<nsIDOMElement> mSecurityButton;
|
||||
nsCOMPtr<nsIDocumentLoaderObserver> mOldWebShellObserver;
|
||||
|
||||
PRBool mIsSecureDocument; // is https loaded
|
||||
PRBool mIsDocumentBroken; //
|
||||
PRBool mMixContentAlertShown;
|
||||
|
||||
};
|
||||
|
||||
class nsSecureBrowserUIImpl : public nsSecureBrowserUI
|
||||
{
|
||||
public:
|
||||
|
||||
nsSecureBrowserUIImpl();
|
||||
virtual ~nsSecureBrowserUIImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSSECUREBROWSERUI
|
||||
|
||||
static NS_METHOD CreateSecureBrowserUI(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
protected:
|
||||
|
||||
static nsSecureBrowserUIImpl* mInstance;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsSecureBrowserUIImpl_h_ */
|
||||
BIN
mozilla/netwerk/security/browser/unlock.gif
Normal file
BIN
mozilla/netwerk/security/browser/unlock.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 67 B |
31
mozilla/netwerk/security/makefile.win
Normal file
31
mozilla/netwerk/security/makefile.win
Normal file
@@ -0,0 +1,31 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Doug Turner 7/29/99
|
||||
#
|
||||
|
||||
DEPTH = ..\..
|
||||
|
||||
DIRS= \
|
||||
browser \
|
||||
psm \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
56
mozilla/netwerk/security/psm/Makefile.in
Normal file
56
mozilla/netwerk/security/psm/Makefile.in
Normal file
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = psmcomp
|
||||
|
||||
IS_COMPONENT = 1
|
||||
LIBRARY_NAME = psmcomp
|
||||
|
||||
CPPSRCS = \
|
||||
nsPSMComponent.cpp \
|
||||
nsPSMModule.cpp \
|
||||
nsPSMUICallbacks.cpp \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
nsPSMMutex.c \
|
||||
nsPSMShimLayer.c \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIPSMComponent.idl \
|
||||
nsIPSMUIHandler.idl \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS = -L$(DIST)/lib -lcmt -lxpcom -lprotocol $(MOZ_REGISTRY_LIBS)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
INCLUDES += \
|
||||
-I$(srcdir) \
|
||||
$(NULL)
|
||||
83
mozilla/netwerk/security/psm/makefile.win
Normal file
83
mozilla/netwerk/security/psm/makefile.win
Normal file
@@ -0,0 +1,83 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
MODULE = psmcomp
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DLLNAME = psmcomp
|
||||
PDBFILE = $(DLLNAME).pdb
|
||||
MAPFILE = $(DLLNAME).map
|
||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
EXPORTS= \
|
||||
$(NULL)
|
||||
|
||||
LINCS = $(LINCS) \
|
||||
-I$(PUBLIC) \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\neckobase_s.lib \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\js3250.lib \
|
||||
$(DIST)\lib\cmt.lib \
|
||||
$(DIST)\lib\protocol.lib \
|
||||
$(DIST)\lib\mozreg.lib \
|
||||
$(NULL)
|
||||
|
||||
LIBRARY_NAME=neckopsm_s
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsPSMMutex.obj \
|
||||
.\$(OBJDIR)\nsPSMShimLayer.obj \
|
||||
.\$(OBJDIR)\nsPSMComponent.obj \
|
||||
.\$(OBJDIR)\nsPSMUICallbacks.obj \
|
||||
.\$(OBJDIR)\nsPSMModule.obj \
|
||||
$(NULL)
|
||||
|
||||
XPIDL_INCLUDES=-I$(DEPTH)\..\mozilla\dist\idl
|
||||
|
||||
XPIDLSRCS= \
|
||||
.\nsIPSMComponent.idl \
|
||||
.\nsIPSMUIHandler.idl \
|
||||
$(NULL)
|
||||
|
||||
#NO_GEN_XPT=1
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
|
||||
# temporary we need to export this static library to
|
||||
# deal with gSocketFuncs in CMT lib being global
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
-$(RM_R) $(OBJDIR) $(XPIDL_GEN_DIR)
|
||||
68
mozilla/netwerk/security/psm/nsIPSMComponent.idl
Normal file
68
mozilla/netwerk/security/psm/nsIPSMComponent.idl
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
//#include "nsIPrincipal.idl"
|
||||
interface nsIPrincipal;
|
||||
|
||||
%{C++
|
||||
#include "cmtcmn.h"
|
||||
%}
|
||||
|
||||
[ptr] native nsCMTControlStar(CMT_CONTROL);
|
||||
|
||||
[scriptable, uuid(9e482670-5412-11d3-bbc8-0000861d1237)]
|
||||
interface nsIPSMComponent : nsISupports
|
||||
{
|
||||
|
||||
[noscript] nsCMTControlStar GetControlConnection( );
|
||||
void DisplaySecurityAdvisor();
|
||||
|
||||
/* Secure Hashing functions */
|
||||
void hashBegin(in unsigned long alg, out unsigned long id);
|
||||
void hashUpdate(in unsigned long id, in string buf, in unsigned long buflen);
|
||||
void hashEnd(in unsigned long id, out string hash, out unsigned long hashlen,
|
||||
in unsigned long maxLen);
|
||||
|
||||
/* Signature Verification functions */
|
||||
void verifyRSABegin(out unsigned long id);
|
||||
void verifyRSAUpdate(in unsigned long id, in string buf,
|
||||
in unsigned long buflen);
|
||||
void verifyRSAEnd(in unsigned long id, in string plaintext,
|
||||
in unsigned long plaintextLen,
|
||||
in boolean keepCert, out nsIPrincipal principal);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define PSM_COMPONENT_PROGID "component://netscape/psm"
|
||||
#define PSM_COMPONENT_CLASSNAME "Mozilla PSM Component"
|
||||
|
||||
/* Hash Algorithms (based on cmtcmn.h) */
|
||||
#define PSM_HASH_MD2 1
|
||||
#define PSM_HASH_MD2_LENGTH 16
|
||||
#define PSM_HASH_MD5 2
|
||||
#define PSM_HASH_MD5_LENGTH 16
|
||||
#define PSM_HASH_SHA1 3
|
||||
#define PSM_HASH_SHA1_LENGTH 20
|
||||
#define PSM_HASH_MAX_LENGTH PSM_HASH_SHA1_LENGTH
|
||||
%}
|
||||
|
||||
35
mozilla/netwerk/security/psm/nsIPSMUIHandler.idl
Normal file
35
mozilla/netwerk/security/psm/nsIPSMUIHandler.idl
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(d92be9b0-601b-11d3-8c4a-000064657374)]
|
||||
interface nsIPSMUIHandler : nsISupports
|
||||
{
|
||||
void DisplayURI(in long width, in long height, in string urlStr);
|
||||
void PromptForFile(in string prompt, in string fileRegEx, in boolean shouldFileExist, out string outFile);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define PSM_UI_HANLDER_PROGID "component://netscape/psm/ui"
|
||||
#define PSM_UI_HANLDER_CLASSNAME "Mozilla PSM UI Handler"
|
||||
%}
|
||||
737
mozilla/netwerk/security/psm/nsPSMComponent.cpp
Normal file
737
mozilla/netwerk/security/psm/nsPSMComponent.cpp
Normal file
@@ -0,0 +1,737 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
#include "VerReg.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsPSMComponent.h"
|
||||
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsIPref.h"
|
||||
#include "nsIProfile.h"
|
||||
#include "nsILocalFile.h"
|
||||
#ifdef XP_MAC
|
||||
#include "nsILocalFileMac.h"
|
||||
#endif
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
#include "nsPSMMutex.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
|
||||
#include "nsSecureBrowserUI.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
#define PSM_VERSION_REG_KEY "/Netscape/Personal Security Manager"
|
||||
|
||||
#ifdef WIN32
|
||||
#define PSM_FILE_NAME "psm.exe"
|
||||
#elif XP_UNIX
|
||||
#define PSM_FILE_NAME "start-psm"
|
||||
#define PSM_FILE_LOCATION "/opt/netscape/security/start-psm"
|
||||
#else
|
||||
#define PSM_FILE_NAME "psm"
|
||||
#endif
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
|
||||
|
||||
|
||||
nsPSMComponent* nsPSMComponent::mInstance = nsnull;
|
||||
|
||||
nsPSMComponent::nsPSMComponent()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mControl = nsnull;
|
||||
}
|
||||
|
||||
nsPSMComponent::~nsPSMComponent()
|
||||
{
|
||||
if (mControl)
|
||||
{
|
||||
CMT_CloseControlConnection(mControl);
|
||||
mControl = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::CreatePSMComponent(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (!aResult) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
*aResult = nsnull;
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
|
||||
if (mInstance == nsnull)
|
||||
{
|
||||
mInstance = new nsPSMComponent();
|
||||
}
|
||||
|
||||
if (mInstance == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = mInstance->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
*aResult = nsnull;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* nsISupports Implementation for the class */
|
||||
NS_IMPL_ISUPPORTS1 (nsPSMComponent, nsIPSMComponent);
|
||||
|
||||
#define INIT_NUM_PREFS 100
|
||||
/* preference types */
|
||||
#define STRING_PREF 0
|
||||
#define BOOL_PREF 1
|
||||
#define INT_PREF 2
|
||||
|
||||
|
||||
/* resizable list struct that contains pref items */
|
||||
typedef struct CMSetPrefList {
|
||||
int n; /* number of filled items */
|
||||
int capacity; /* allocated memory */
|
||||
CMTSetPrefElement* list; /* actual list */
|
||||
} CMSetPrefList;
|
||||
|
||||
static void get_pack_bool_pref(nsIPref *prefManager, char* key, CMTSetPrefElement* list, int* n)
|
||||
{
|
||||
PRBool boolpref;
|
||||
|
||||
list[*n].key = nsCRT::strdup(key);
|
||||
list[*n].type = BOOL_PREF;
|
||||
|
||||
if ((prefManager->GetBoolPref(key, &boolpref) != 0) || boolpref)
|
||||
{
|
||||
list[*n].value = nsCRT::strdup("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
list[*n].value = nsCRT::strdup("false");
|
||||
}
|
||||
|
||||
(*n)++; /* increment the counter after done packing */
|
||||
|
||||
return;
|
||||
}
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
|
||||
static void SaveAllPrefs(int number, CMTSetPrefElement* list)
|
||||
{
|
||||
nsCOMPtr<nsIPref> prefManager;
|
||||
|
||||
nsresult res = nsServiceManager::GetService(kPrefCID,
|
||||
nsIPref::GetIID(),
|
||||
getter_AddRefs(prefManager));
|
||||
|
||||
if (NS_FAILED(res) || !prefManager)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int i;
|
||||
int intval;
|
||||
|
||||
for (i = 0; i < number; i++)
|
||||
{
|
||||
if (list[i].key == nsnull)
|
||||
{
|
||||
/* misconfigured item: next */
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (list[i].type)
|
||||
{
|
||||
case 0: /* string type */
|
||||
prefManager->SetCharPref(list[i].key, list[i].value);
|
||||
break;
|
||||
case 1: /* boolean type */
|
||||
if (strcmp(list[i].value, "true") == 0) {
|
||||
prefManager->SetBoolPref(list[i].key, (PRBool)1);
|
||||
}
|
||||
else if (strcmp(list[i].value, "false") == 0) {
|
||||
prefManager->SetBoolPref(list[i].key, (PRBool)0);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
intval = atoi(list[i].value);
|
||||
prefManager->SetIntPref(list[i].key, intval);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPSMComponent::PassAllPrefs()
|
||||
{
|
||||
int i;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
char* strpref = NULL;
|
||||
int intpref;
|
||||
PRBool boolpref;
|
||||
CMSetPrefList prefs = {0};
|
||||
CMTSetPrefElement* list = NULL;
|
||||
|
||||
char* pickAuto = "Select Automatically";
|
||||
char* alwaysAsk = "Ask Every Time";
|
||||
|
||||
nsCOMPtr<nsIPref> prefManager;
|
||||
|
||||
nsresult res = nsServiceManager::GetService(kPrefCID,
|
||||
nsIPref::GetIID(),
|
||||
getter_AddRefs(prefManager));
|
||||
|
||||
if (NS_OK != res)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/* allocate memory for list */
|
||||
prefs.n = 0; /* counter */
|
||||
prefs.capacity = INIT_NUM_PREFS;
|
||||
prefs.list = (CMTSetPrefElement*) new char[(INIT_NUM_PREFS * sizeof(CMTSetPrefElement))];
|
||||
|
||||
if (prefs.list == NULL)
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* shorthand */
|
||||
list = prefs.list;
|
||||
|
||||
/* get preferences */
|
||||
get_pack_bool_pref(prefManager, "security.enable_ssl2", (CMTSetPrefElement*)list, &(prefs.n));
|
||||
get_pack_bool_pref(prefManager, "security.enable_ssl3", (CMTSetPrefElement*)list, &(prefs.n));
|
||||
|
||||
/* this pref is a boolean pref in nature but a string pref for
|
||||
* historical reason
|
||||
*/
|
||||
|
||||
list[prefs.n].key = nsCRT::strdup("security.default_personal_cert");
|
||||
list[prefs.n].type = STRING_PREF;
|
||||
|
||||
if ((prefManager->CopyCharPref(list[prefs.n].key, &strpref) == 0) && (strcmp(strpref, pickAuto) == 0))
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup(pickAuto);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* although one could choose a specific cert for client auth in
|
||||
* Nova, that mode is deprecated with PSM and mapped to ASK
|
||||
*/
|
||||
list[prefs.n].value = nsCRT::strdup(alwaysAsk);
|
||||
}
|
||||
|
||||
prefs.n++;
|
||||
if (strpref != NULL)
|
||||
{
|
||||
nsCRT::free(strpref);
|
||||
}
|
||||
|
||||
list[prefs.n].key = nsCRT::strdup("security.default_mail_cert");
|
||||
list[prefs.n].type = STRING_PREF;
|
||||
if (prefManager->CopyCharPref(list[prefs.n].key, &list[prefs.n].value) != 0)
|
||||
{
|
||||
list[prefs.n].value = NULL;
|
||||
}
|
||||
prefs.n++;
|
||||
|
||||
list[prefs.n].key = nsCRT::strdup("security.ask_for_password");
|
||||
list[prefs.n].type = INT_PREF;
|
||||
if (prefManager->GetIntPref(list[prefs.n].key, &intpref) != 0)
|
||||
{
|
||||
intpref = 2; /* default */
|
||||
}
|
||||
|
||||
list[prefs.n].value = PR_smprintf("%d", intpref);
|
||||
prefs.n++;
|
||||
|
||||
list[prefs.n].key = nsCRT::strdup("security.password_lifetime");
|
||||
list[prefs.n].type = INT_PREF;
|
||||
if (prefManager->GetIntPref(list[prefs.n].key, &intpref) != 0)
|
||||
{
|
||||
intpref = 480; /* default */
|
||||
}
|
||||
|
||||
list[prefs.n].value = PR_smprintf("%d", intpref);
|
||||
prefs.n++;
|
||||
|
||||
/* OCSP preferences */
|
||||
/* XXX since these are the new ones added by PSM, we will be more
|
||||
* error-tolerant in fetching them
|
||||
*/
|
||||
if (prefManager->GetBoolPref("security.OCSP.enabled", &boolpref) == 0)
|
||||
{
|
||||
if (boolpref)
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup("false");
|
||||
}
|
||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.enabled");
|
||||
list[prefs.n].type = BOOL_PREF;
|
||||
prefs.n++;
|
||||
}
|
||||
|
||||
if (prefManager->GetBoolPref("security.OCSP.useDefaultResponder", &boolpref) == 0)
|
||||
{
|
||||
if (boolpref)
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup("false");
|
||||
}
|
||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.useDefaultResponder");
|
||||
list[prefs.n].type = BOOL_PREF;
|
||||
prefs.n++;
|
||||
}
|
||||
|
||||
if (prefManager->CopyCharPref("security.OCSP.URL", &strpref) == 0)
|
||||
{
|
||||
list[prefs.n].value = strpref;
|
||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.URL");
|
||||
list[prefs.n].type = STRING_PREF;
|
||||
prefs.n++;
|
||||
}
|
||||
|
||||
if (prefManager->CopyCharPref("security.OCSP.signingCA", &strpref) == 0)
|
||||
{
|
||||
list[prefs.n].value = strpref;
|
||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.signingCA");
|
||||
list[prefs.n].type = STRING_PREF;
|
||||
prefs.n++;
|
||||
}
|
||||
|
||||
/* now application-specific preferences */
|
||||
/* get navigator preferences */
|
||||
get_pack_bool_pref(prefManager, "security.warn_entering_secure", (CMTSetPrefElement*)list, &prefs.n);
|
||||
get_pack_bool_pref(prefManager, "security.warn_leaving_secure", (CMTSetPrefElement*)list, &prefs.n);
|
||||
get_pack_bool_pref(prefManager, "security.warn_viewing_mixed", (CMTSetPrefElement*)list, &prefs.n);
|
||||
get_pack_bool_pref(prefManager, "security.warn_submit_insecure", (CMTSetPrefElement*)list, &prefs.n);
|
||||
|
||||
// Add any other prefs here such as ldap or mail/news.
|
||||
|
||||
CMT_SetSavePrefsCallback(mControl, (savePrefsCallback_fn)SaveAllPrefs);
|
||||
|
||||
if (CMT_PassAllPrefs(mControl, prefs.n, (CMTSetPrefElement*)prefs.list) != CMTSuccess)
|
||||
{
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = NS_OK; /* success */
|
||||
loser:
|
||||
/* clean out memory for prefs */
|
||||
for (i = 0; i < prefs.n; i++)
|
||||
{
|
||||
if (prefs.list[i].key != NULL)
|
||||
{
|
||||
nsCRT::free(prefs.list[i].key);
|
||||
}
|
||||
|
||||
if (prefs.list[i].value != NULL)
|
||||
{
|
||||
nsCRT::free(prefs.list[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.list != NULL)
|
||||
{
|
||||
delete(prefs.list);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::GetControlConnection( CMT_CONTROL * *_retval )
|
||||
{
|
||||
nsresult rv;
|
||||
*_retval = nsnull;
|
||||
if (mControl)
|
||||
{
|
||||
*_retval = mControl;
|
||||
return NS_OK;
|
||||
}
|
||||
else /* initialize mutex, sock table, etc. */
|
||||
{
|
||||
|
||||
if (nsPSMMutexInit() != PR_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mControl = CMT_ControlConnect(&nsPSMMutexTbl, &nsPSMShimTbl);
|
||||
|
||||
if (mControl == nsnull)
|
||||
{
|
||||
//Try to find it.
|
||||
int err;
|
||||
char filepath[MAXREGPATHLEN];
|
||||
|
||||
err = VR_GetPath(PSM_VERSION_REG_KEY, sizeof(filepath), filepath);
|
||||
if ( err == REGERR_OK )
|
||||
{
|
||||
nsFileSpec psmSpec(filepath);
|
||||
psmSpec += PSM_FILE_NAME;
|
||||
|
||||
if (psmSpec.Exists())
|
||||
{
|
||||
mControl = CMT_EstablishControlConnection((char *)psmSpec.GetNativePathCString(), &nsPSMShimTbl, &nsPSMMutexTbl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef XP_MAC
|
||||
if (mControl == nsnull)
|
||||
{
|
||||
nsSpecialSystemDirectory sysDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
nsFileSpec spec = sysDir;
|
||||
|
||||
spec += "psm/";
|
||||
spec += PSM_FILE_NAME;
|
||||
|
||||
if (spec.Exists())
|
||||
{
|
||||
mControl = CMT_EstablishControlConnection((char *)spec.GetNativePathCString(), &nsPSMShimTbl, &nsPSMMutexTbl);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (mControl == nsnull)
|
||||
{
|
||||
// Attempt to locate "Personal Security Manager" in "Essential Files".
|
||||
nsCOMPtr<nsILocalFile> aPSMApp = do_CreateInstance(NS_LOCAL_FILE_PROGID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsILocalFileMac> psmAppMacFile = do_QueryInterface(aPSMApp, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = psmAppMacFile->InitFindingAppByCreatorCode('nPSM');
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = psmAppMacFile->LaunchAppWithDoc(nsnull, PR_TRUE);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
const PRUint32 kMaxWaitTicks = 180; // max 3 seconds
|
||||
PRUint32 endTicks = ::TickCount() + kMaxWaitTicks;
|
||||
|
||||
do
|
||||
{
|
||||
EventRecord theEvent;
|
||||
WaitNextEvent(0, &theEvent, 5, NULL);
|
||||
mControl = CMT_ControlConnect(&nsPSMMutexTbl, &nsPSMShimTbl);
|
||||
} while (!mControl && (::TickCount() < endTicks));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Launching Personal Security Manager failed");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
if (mControl == nsnull)
|
||||
{
|
||||
nsFileSpec psmSpec(PSM_FILE_LOCATION);
|
||||
if (psmSpec.Exists())
|
||||
{
|
||||
mControl = CMT_EstablishControlConnection(PSM_FILE_LOCATION, &nsPSMShimTbl, &nsPSMMutexTbl);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mControl == nsnull)
|
||||
{
|
||||
char* filePath = nsnull;
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
handler->PromptForFile("Please find the Personal Security Manager application", PSM_FILE_NAME, PR_TRUE, &filePath);
|
||||
if (! filePath)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mControl = CMT_EstablishControlConnection(filePath, &nsPSMShimTbl, &nsPSMMutexTbl);
|
||||
}
|
||||
|
||||
|
||||
if (!mControl || InitPSMUICallbacks(mControl) != PR_SUCCESS)
|
||||
goto failure;
|
||||
|
||||
nsFileSpec profileSpec;
|
||||
char* profileName = nsnull;
|
||||
|
||||
NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &rv);
|
||||
if (NS_FAILED(rv)) goto failure;
|
||||
|
||||
rv = profile->GetCurrentProfileDir(&profileSpec);
|
||||
if (NS_FAILED(rv)) goto failure;;
|
||||
|
||||
rv = profile->GetCurrentProfile(&profileName);
|
||||
if (NS_FAILED(rv)) goto failure;
|
||||
|
||||
CMTStatus psmStatus;
|
||||
|
||||
psmStatus = CMT_Hello( mControl,
|
||||
PROTOCOL_VERSION,
|
||||
profileName,
|
||||
(char*)profileSpec.GetNativePathCString());
|
||||
|
||||
if (psmStatus == CMTFailure)
|
||||
{
|
||||
PR_FREEIF(profileName);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (NS_FAILED(PassAllPrefs()))
|
||||
{
|
||||
PR_FREEIF(profileName);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
PR_FREEIF(profileName);
|
||||
|
||||
*_retval = mControl;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
failure:
|
||||
|
||||
printf("*** Failure setting up Cartman! \n");
|
||||
|
||||
if (mControl)
|
||||
{
|
||||
CMT_CloseControlConnection(mControl);
|
||||
mControl = NULL;
|
||||
}
|
||||
|
||||
// TODO we need to unregister our UI callback BEFORE destroying our mutex.
|
||||
// nsPSMMutexDestroy();
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::DisplaySecurityAdvisor()
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
GetControlConnection( &controlConnection );
|
||||
if (DisplayPSMUIDialog(controlConnection, nsnull) == PR_SUCCESS)
|
||||
return NS_OK;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// Secure Hash Functions
|
||||
//-----------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::HashBegin(PRUint32 alg, PRUint32* id)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if(CMT_HashCreate(controlConnection, alg, (CMUint32*)id) != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
if(CMT_HASH_Begin(controlConnection, *id) != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::HashUpdate(PRUint32 id, const char* buf, PRUint32 buflen)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
if (CMT_HASH_Update(controlConnection, id,
|
||||
(const unsigned char*)buf, buflen) != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::HashEnd(PRUint32 id, char** hash, PRUint32* hashlen,
|
||||
PRUint32 maxLen)
|
||||
{
|
||||
if (!hash)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if(CMT_HASH_End(controlConnection, id, (unsigned char*)*hash,
|
||||
(CMUint32*)hashlen, maxLen) != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
CMT_HASH_Destroy(controlConnection, id);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// Signature Verification Functions
|
||||
//-----------------------------------------
|
||||
PR_STATIC_CALLBACK(void)
|
||||
UselessPK7DataSink(void* arg, const char* buf, CMUint32 len)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::VerifyRSABegin(PRUint32* id)
|
||||
{
|
||||
if (!id)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
CMInt32* blah = nsnull;
|
||||
CMTStatus result = CMT_PKCS7DecoderStart(controlConnection, nsnull /*?*/,
|
||||
(CMUint32*)id, blah,
|
||||
UselessPK7DataSink, nsnull);
|
||||
if (result == CMTSuccess)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::VerifyRSAUpdate(PRUint32 id, const char* buf, PRUint32 buflen)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
CMTStatus result = CMT_PKCS7DecoderUpdate(controlConnection, id, buf, buflen);
|
||||
if (result == CMTSuccess)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::VerifyRSAEnd(PRUint32 id, const char* plaintext,
|
||||
PRUint32 plaintextLen,
|
||||
PRBool keepCert, nsIPrincipal** aPrincipal)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
CMUint32 contentInfo;
|
||||
CMTStatus result = CMT_PKCS7DecoderFinish(controlConnection,
|
||||
id, &contentInfo);
|
||||
if (result != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
//-- Make sure a signature is present
|
||||
CMInt32 isSigned;
|
||||
result = CMT_GetNumericAttribute(controlConnection, contentInfo,
|
||||
SSM_FID_P7CINFO_IS_SIGNED, &isSigned);
|
||||
if (result != CMTSuccess || !isSigned)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// SHA1 hash the plaintext to compare it to the signature
|
||||
CMUint32 hashId;
|
||||
CMT_HashCreate(controlConnection, PSM_HASH_SHA1, &hashId);
|
||||
CMT_HASH_Begin(controlConnection, hashId);
|
||||
result = CMT_HASH_Update(controlConnection, hashId,
|
||||
(const unsigned char*)plaintext, plaintextLen);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
|
||||
unsigned char* hash = (unsigned char*)PR_MALLOC(PSM_HASH_SHA1_LENGTH);
|
||||
if (!hash) return NS_ERROR_OUT_OF_MEMORY;
|
||||
CMUint32 hashLen;
|
||||
result = CMT_HASH_End(controlConnection, hashId, hash,
|
||||
&hashLen, PSM_HASH_SHA1_LENGTH);
|
||||
NS_ASSERTION(hashLen == PSM_HASH_SHA1_LENGTH,
|
||||
"PSMComponent: Hash too short.");
|
||||
CMT_HASH_Destroy(controlConnection, hashId);
|
||||
if (result != CMTSuccess)
|
||||
{
|
||||
PR_FREEIF(hash);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
//-- Verify signature
|
||||
CMInt32 ok;
|
||||
CMTItemStr item;
|
||||
item.data = hash;
|
||||
item.len = hashLen;
|
||||
result = CMT_PKCS7VerifyDetachedSignature(controlConnection, contentInfo,
|
||||
6 /* =Object Sining Cert */,
|
||||
3 /* =SHA1 algorithm (MD5=2)*/,
|
||||
(CMUint32)keepCert,
|
||||
&item, &ok);
|
||||
PR_FREEIF(hash);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
//-- Did it verify?
|
||||
|
||||
if (ok != 0)
|
||||
*aPrincipal = nsnull;
|
||||
else
|
||||
{
|
||||
//-- Read cert info
|
||||
CMInt32 cert;
|
||||
result = CMT_GetNumericAttribute(controlConnection, contentInfo,
|
||||
SSM_FID_P7CINFO_SIGNER_CERT, &cert);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
CMTItemStr issuer;
|
||||
result = CMT_GetStringAttribute(controlConnection, cert,
|
||||
SSM_FID_CERT_ISSUER_NAME, &issuer);
|
||||
CMTItemStr serial;
|
||||
result = CMT_GetStringAttribute(controlConnection, cert,
|
||||
SSM_FID_CERT_SERIAL_NUMBER, &serial);
|
||||
//-- Get a principal
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv)
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
rv = secMan->GetCertificatePrincipal((char*)issuer.data,
|
||||
(char*)serial.data, aPrincipal);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
result = CMT_PKCS7DestroyContentInfo(controlConnection, contentInfo);
|
||||
|
||||
if(result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
return NS_OK;
|
||||
}
|
||||
50
mozilla/netwerk/security/psm/nsPSMComponent.h
Normal file
50
mozilla/netwerk/security/psm/nsPSMComponent.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
|
||||
#define NS_PSMCOMPONENT_CID {0xddcae170, 0x5412, 0x11d3, {0xbb, 0xc8, 0x00, 0x00, 0x86, 0x1d, 0x12, 0x37}}
|
||||
|
||||
// Implementation of the PSM app shell component interface.
|
||||
class nsPSMComponent : public nsIPSMComponent
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_PSMCOMPONENT_CID );
|
||||
|
||||
nsPSMComponent();
|
||||
virtual ~nsPSMComponent();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIPSMCOMPONENT
|
||||
|
||||
static NS_METHOD CreatePSMComponent(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
private:
|
||||
|
||||
PCMT_CONTROL mControl;
|
||||
|
||||
nsCOMPtr<nsISupports> mSecureBrowserIU;
|
||||
static nsPSMComponent* mInstance;
|
||||
nsresult PassAllPrefs();
|
||||
};
|
||||
42
mozilla/netwerk/security/psm/nsPSMModule.cpp
Normal file
42
mozilla/netwerk/security/psm/nsPSMModule.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#include "nsPSMUICallbacks.h"
|
||||
#include "nsPSMComponent.h"
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ PSM_COMPONENT_CLASSNAME,
|
||||
NS_PSMCOMPONENT_CID,
|
||||
PSM_COMPONENT_PROGID,
|
||||
nsPSMComponent::CreatePSMComponent},
|
||||
|
||||
{ PSM_UI_HANLDER_CLASSNAME,
|
||||
NS_PSMUIHANDLER_CID,
|
||||
PSM_UI_HANLDER_PROGID,
|
||||
nsPSMUIHandlerImpl::CreatePSMUIHandler}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("PSMComponent", components);
|
||||
72
mozilla/netwerk/security/psm/nsPSMMutex.c
Normal file
72
mozilla/netwerk/security/psm/nsPSMMutex.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "prmon.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
#include "nsPSMMutex.h"
|
||||
|
||||
static PRMonitor *_nsPSMMutexVar;
|
||||
|
||||
PRStatus
|
||||
nsPSMMutexInit()
|
||||
{
|
||||
if (!_nsPSMMutexVar)
|
||||
_nsPSMMutexVar = PR_NewMonitor();
|
||||
else
|
||||
printf("PSMMutex warning got called twice\n");
|
||||
|
||||
return _nsPSMMutexVar ? PR_SUCCESS : PR_FAILURE;
|
||||
}
|
||||
|
||||
PRStatus
|
||||
nsPSMMutexDestroy()
|
||||
{
|
||||
if (!_nsPSMMutexVar)
|
||||
return PR_FAILURE;
|
||||
|
||||
PR_Wait(_nsPSMMutexVar, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
||||
PR_DestroyMonitor(_nsPSMMutexVar);
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
nsPSMMutexLock(CMTMutexPointer *p)
|
||||
{
|
||||
PR_EnterMonitor(*(PRMonitor **)p);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
nsPSMMutexUnlock(CMTMutexPointer *p)
|
||||
{
|
||||
PR_ExitMonitor(*(PRMonitor **)p);
|
||||
return;
|
||||
}
|
||||
|
||||
CMT_MUTEX nsPSMMutexTbl =
|
||||
{
|
||||
&_nsPSMMutexVar,
|
||||
(CMTMutexFunction)nsPSMMutexLock,
|
||||
(CMTMutexFunction)nsPSMMutexUnlock
|
||||
};
|
||||
37
mozilla/netwerk/security/psm/nsPSMMutex.h
Normal file
37
mozilla/netwerk/security/psm/nsPSMMutex.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _NSPSMMUTEX_H
|
||||
#define _NSPSMMUTEX_H
|
||||
|
||||
#include "cmtcmn.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
PR_EXTERN(CMT_MUTEX) nsPSMMutexTbl;
|
||||
|
||||
PR_EXTERN(PRStatus) nsPSMMutexInit(void);
|
||||
PR_EXTERN(PRStatus) nsPSMMutexDestroy(void);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
267
mozilla/netwerk/security/psm/nsPSMShimLayer.c
Normal file
267
mozilla/netwerk/security/psm/nsPSMShimLayer.c
Normal file
@@ -0,0 +1,267 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define NSPSMSHIMMAXFD 50
|
||||
|
||||
CMT_SocketFuncs nsPSMShimTbl =
|
||||
{
|
||||
nsPSMShimGetSocket,
|
||||
nsPSMShimConnect,
|
||||
nsPSMShimVerifyUnixSocket,
|
||||
nsPSMShimSend,
|
||||
nsPSMShimSelect,
|
||||
nsPSMShimReceive,
|
||||
nsPSMShimShutdown,
|
||||
nsPSMShimClose
|
||||
};
|
||||
|
||||
|
||||
CMTSocket
|
||||
nsPSMShimGetSocket(int unixSock)
|
||||
{
|
||||
PRStatus rv;
|
||||
PRFileDesc *fd;
|
||||
CMSocket *sock;
|
||||
|
||||
|
||||
if (unixSock)
|
||||
{
|
||||
#ifndef XP_UNIX
|
||||
return NULL;
|
||||
#else
|
||||
fd = PR_OpenTCPSocket(AF_UNIX);
|
||||
PR_ASSERT(fd);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
PRSocketOptionData sockopt;
|
||||
|
||||
fd = PR_NewTCPSocket();
|
||||
PR_ASSERT(fd);
|
||||
|
||||
/* disable Nagle algorithm delay for control sockets */
|
||||
sockopt.option = PR_SockOpt_NoDelay;
|
||||
sockopt.value.no_delay = PR_TRUE;
|
||||
|
||||
rv = PR_SetSocketOption(fd, &sockopt);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
}
|
||||
|
||||
sock = (CMSocket *)PR_Malloc(sizeof(CMSocket));
|
||||
|
||||
if (sock == NULL)
|
||||
return sock;
|
||||
|
||||
sock->fd = fd;
|
||||
sock->isUnix = unixSock;
|
||||
|
||||
memset(&sock->netAddr, 0, sizeof(PRNetAddr));
|
||||
|
||||
return (CMTSocket)sock;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
nsPSMShimConnect(CMTSocket sock, short port, char *path)
|
||||
{
|
||||
PRStatus err;
|
||||
PRErrorCode errcode;
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMSocket *cmSock = (CMSocket *)sock;
|
||||
|
||||
if (cmSock->isUnix)
|
||||
{
|
||||
#ifndef XP_UNIX
|
||||
return CMTFailure;
|
||||
#else
|
||||
int pathLen;
|
||||
if (!path)
|
||||
{
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
/* check buffer overrun */
|
||||
pathLen = strlen(path)+1;
|
||||
|
||||
pathLen = pathLen < sizeof(cmSock->netAddr.local.path)
|
||||
? pathLen : sizeof(cmSock->netAddr.local.path);
|
||||
|
||||
memcpy(&cmSock->netAddr.local.path, path, pathLen);
|
||||
cmSock->netAddr.local.family = PR_AF_LOCAL;
|
||||
#endif
|
||||
}
|
||||
else /* cmSock->isUnix */
|
||||
{
|
||||
cmSock->netAddr.inet.family = PR_AF_INET;
|
||||
cmSock->netAddr.inet.port = PR_htons(port);
|
||||
cmSock->netAddr.inet.ip = PR_htonl(PR_INADDR_LOOPBACK);
|
||||
}
|
||||
|
||||
err = PR_Connect( cmSock->fd, &cmSock->netAddr, PR_INTERVAL_MAX );
|
||||
|
||||
if (err == PR_FAILURE)
|
||||
{
|
||||
errcode = PR_GetError();
|
||||
|
||||
/* TODO: verify PR_INVALID_ARGUMENT_ERROR continue with connect */
|
||||
|
||||
switch (errcode)
|
||||
{
|
||||
case PR_IS_CONNECTED_ERROR:
|
||||
rv = CMTSuccess;
|
||||
break;
|
||||
|
||||
case PR_IN_PROGRESS_ERROR:
|
||||
case PR_IO_TIMEOUT_ERROR:
|
||||
#ifdef WIN32
|
||||
case PR_WOULD_BLOCK_ERROR:
|
||||
case PR_INVALID_ARGUMENT_ERROR:
|
||||
#endif
|
||||
default:
|
||||
rv = CMTFailure;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
nsPSMShimVerifyUnixSocket(CMTSocket sock)
|
||||
{
|
||||
#ifndef XP_UNIX
|
||||
return CMTFailure;
|
||||
#else
|
||||
|
||||
int rv;
|
||||
CMSocket *cmSock = (CMSocket *)sock;
|
||||
struct stat statbuf;
|
||||
|
||||
if (!cmSock->isUnix)
|
||||
return CMTFailure;
|
||||
|
||||
rv = stat(cmSock->netAddr.local.path, &statbuf);
|
||||
if (rv < 0 || statbuf.st_uid != geteuid() )
|
||||
{
|
||||
PR_Close(cmSock->fd);
|
||||
cmSock->fd = NULL;
|
||||
PR_Free(cmSock);
|
||||
return CMTFailure;
|
||||
}
|
||||
return CMTSuccess;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t
|
||||
nsPSMShimSend(CMTSocket sock, void *buffer, size_t length)
|
||||
{
|
||||
PRInt32 total;
|
||||
CMSocket *cmSock = (CMSocket *)sock;
|
||||
|
||||
total = PR_Send(cmSock->fd, buffer, length, 0, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
||||
/* TODO: for now, return 0 if there's an error */
|
||||
return (total < 0) ? 0 : total;
|
||||
}
|
||||
|
||||
|
||||
CMTSocket
|
||||
nsPSMShimSelect(CMTSocket *socks, int numsocks, int poll)
|
||||
{
|
||||
CMSocket **sockArr = (CMSocket **)socks;
|
||||
PRPollDesc readPDs[NSPSMSHIMMAXFD];
|
||||
PRIntervalTime timeout;
|
||||
PRInt32 cnt;
|
||||
int i;
|
||||
|
||||
memset(readPDs, 0, sizeof(readPDs));
|
||||
|
||||
PR_ASSERT(NSPSMSHIMMAXFD >= numsocks);
|
||||
|
||||
for (i=0; i<numsocks; i++)
|
||||
{
|
||||
readPDs[i].fd = sockArr[i]->fd;
|
||||
readPDs[i].in_flags = PR_POLL_READ;
|
||||
}
|
||||
|
||||
timeout = poll ? PR_INTERVAL_NO_WAIT : PR_INTERVAL_NO_TIMEOUT;
|
||||
|
||||
cnt = PR_Poll(readPDs, numsocks, timeout);
|
||||
|
||||
/* Figure out which socket was selected */
|
||||
if (cnt > 0)
|
||||
{
|
||||
for (i=0; i<numsocks; i++)
|
||||
{
|
||||
if (readPDs[i].out_flags & PR_POLL_READ)
|
||||
{
|
||||
return (CMTSocket)sockArr[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
nsPSMShimReceive(CMTSocket sock, void *buffer, size_t bufSize)
|
||||
{
|
||||
PRInt32 total;
|
||||
CMSocket *cmSock = (CMSocket *)sock;
|
||||
|
||||
total = PR_Recv(cmSock->fd, buffer, bufSize, 0, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
||||
/* TODO: for now, return 0 if there's an error */
|
||||
return (total < 0) ? 0 : total;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
nsPSMShimShutdown(CMTSocket sock)
|
||||
{
|
||||
CMSocket *cmSock = (CMSocket*)sock;
|
||||
PRStatus rv = PR_Shutdown(cmSock->fd, PR_SHUTDOWN_SEND);
|
||||
return (PR_SUCCESS == rv) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
nsPSMShimClose(CMTSocket sock)
|
||||
{
|
||||
CMSocket *cmSock = (CMSocket*)sock;
|
||||
PRStatus rv = PR_SUCCESS;
|
||||
PR_ASSERT(cmSock);
|
||||
|
||||
rv = PR_Close(cmSock->fd);
|
||||
cmSock->fd = NULL;
|
||||
|
||||
/* TODO: release ref on control connection */
|
||||
PR_Free(cmSock);
|
||||
|
||||
return (PR_SUCCESS == rv) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
65
mozilla/netwerk/security/psm/nsPSMShimLayer.h
Normal file
65
mozilla/netwerk/security/psm/nsPSMShimLayer.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _NSPSMSHIMLAYER_H_
|
||||
#define _NSPSMSHIMLAYER_H_
|
||||
|
||||
#include "cmtcmn.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/* TODO: make sure CMSocket is cleaned up */
|
||||
typedef struct CMSocket {
|
||||
PRFileDesc *fd;
|
||||
PRBool isUnix;
|
||||
PRNetAddr netAddr;
|
||||
} CMSocket;
|
||||
|
||||
PR_EXTERN(CMT_SocketFuncs) nsPSMShimTbl;
|
||||
|
||||
PR_EXTERN(CMTSocket)
|
||||
nsPSMShimGetSocket(int unixSock);
|
||||
|
||||
PR_EXTERN(CMTStatus)
|
||||
nsPSMShimConnect(CMTSocket sock, short port, char *path);
|
||||
|
||||
PR_EXTERN(CMTStatus)
|
||||
nsPSMShimVerifyUnixSocket(CMTSocket sock);
|
||||
|
||||
PR_EXTERN(size_t)
|
||||
nsPSMShimSend(CMTSocket sock, void *buffer, size_t length);
|
||||
|
||||
PR_EXTERN(CMTSocket)
|
||||
nsPSMShimSelect(CMTSocket *socks, int numsocks, int poll);
|
||||
|
||||
PR_EXTERN(size_t)
|
||||
nsPSMShimReceive(CMTSocket sock, void *buffer, size_t bufSize);
|
||||
|
||||
PR_EXTERN(CMTStatus)
|
||||
nsPSMShimShutdown(CMTSocket sock);
|
||||
|
||||
PR_EXTERN(CMTStatus)
|
||||
nsPSMShimClose(CMTSocket sock);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* _NSPSMSHIMLAYER_H_ */
|
||||
303
mozilla/netwerk/security/psm/nsPSMUICallbacks.cpp
Normal file
303
mozilla/netwerk/security/psm/nsPSMUICallbacks.cpp
Normal file
@@ -0,0 +1,303 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsIFileSpecWithUI.h"
|
||||
|
||||
|
||||
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "prprf.h"
|
||||
|
||||
// Interfaces Needed
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIXULWindow.h"
|
||||
|
||||
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
||||
|
||||
|
||||
// Happy callbacks
|
||||
static char * PromptUserCallback(void *arg, char *prompt, int isPasswd);
|
||||
static char * FilePathPromptCallback(void *arg, char *prompt, char *fileRegEx, CMUint32 shouldFileExist);
|
||||
static void ApplicationFreeCallback(char *userInput);
|
||||
static void * CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, char* urlStr, void *data);
|
||||
extern "C" void CARTMAN_UIEventLoop(void *data);
|
||||
|
||||
|
||||
/* nsISupports Implementation for the class */
|
||||
NS_IMPL_ISUPPORTS1(nsPSMUIHandlerImpl, nsIPSMUIHandler)
|
||||
|
||||
NS_METHOD
|
||||
nsPSMUIHandlerImpl::DisplayURI(PRInt32 width, PRInt32 height, const char *urlStr)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
// get a parent window for the new browser window
|
||||
nsCOMPtr<nsIXULWindow> parent;
|
||||
appShell->GetHiddenWindow(getter_AddRefs(parent));
|
||||
|
||||
// convert it to a DOMWindow
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
if (parent)
|
||||
{
|
||||
parent->GetDocShell(getter_AddRefs(docShell));
|
||||
}
|
||||
nsCOMPtr<nsIDOMWindow> domParent(do_GetInterface(docShell));
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(domParent));
|
||||
|
||||
nsCOMPtr<nsIScriptContext> context;
|
||||
if (sgo)
|
||||
{
|
||||
sgo->GetContext(getter_AddRefs(context));
|
||||
}
|
||||
if (context)
|
||||
{
|
||||
JSContext *jsContext = (JSContext*)context->GetNativeContext();
|
||||
if (jsContext)
|
||||
{
|
||||
void *stackPtr;
|
||||
|
||||
char buffer[256];
|
||||
PR_snprintf(buffer,
|
||||
sizeof(buffer),
|
||||
"menubar=no,height=%d,width=%d",
|
||||
height,
|
||||
width );
|
||||
|
||||
jsval *argv = JS_PushArguments(jsContext, &stackPtr, "sss", urlStr, "_blank", buffer);
|
||||
if (argv)
|
||||
{
|
||||
// open the window
|
||||
nsIDOMWindow *newWindow;
|
||||
domParent->Open(jsContext, argv, 3, &newWindow);
|
||||
newWindow->ResizeTo(width, height);
|
||||
JS_PopArguments(jsContext, stackPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMUIHandlerImpl::PromptForFile(const char *prompt, const char *fileRegEx, PRBool shouldFileExist, char **outFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outFile);
|
||||
nsIFileSpecWithUI* file = NS_CreateFileSpecWithUI();
|
||||
|
||||
if (file == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = file->ChooseInputFile(prompt,
|
||||
nsIFileSpecWithUI::eAllFiles | nsIFileSpecWithUI::eExtraFilter,
|
||||
fileRegEx, // FIX name?
|
||||
fileRegEx);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = file->GetNativePath(outFile);
|
||||
|
||||
NS_RELEASE(file);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsPSMUIHandlerImpl::CreatePSMUIHandler(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if ( aResult )
|
||||
{
|
||||
/* Allocate new find component object. */
|
||||
nsPSMUIHandlerImpl *component = new nsPSMUIHandlerImpl();
|
||||
if ( component )
|
||||
{
|
||||
/* Allocated OK, do query interface to get proper */
|
||||
/* pointer and increment refcount. */
|
||||
rv = component->QueryInterface( aIID, aResult );
|
||||
if ( NS_FAILED( rv ) )
|
||||
{
|
||||
/* refcount still at zero, delete it here. */
|
||||
delete component;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" void CARTMAN_UIEventLoop(void *data)
|
||||
{
|
||||
CMT_EventLoop((PCMT_CONTROL)data);
|
||||
}
|
||||
|
||||
PRStatus InitPSMUICallbacks(PCMT_CONTROL control)
|
||||
{
|
||||
if (!control)
|
||||
return PR_FAILURE;
|
||||
|
||||
CMT_SetPromptCallback(control, (promptCallback_fn)PromptUserCallback, nsnull);
|
||||
CMT_SetAppFreeCallback(control, (applicationFreeCallback_fn) ApplicationFreeCallback);
|
||||
CMT_SetFilePathPromptCallback(control, (filePathPromptCallback_fn) FilePathPromptCallback, nsnull);
|
||||
|
||||
if (CMT_SetUIHandlerCallback(control, (uiHandlerCallback_fn) CartmanUIHandler, NULL) != CMTSuccess)
|
||||
return PR_FAILURE;
|
||||
|
||||
PR_CreateThread(PR_USER_THREAD,
|
||||
CARTMAN_UIEventLoop,
|
||||
control,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
0);
|
||||
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, void *arg)
|
||||
{
|
||||
CMUint32 advRID = 0;
|
||||
CMInt32 width = 0;
|
||||
CMInt32 height = 0;
|
||||
CMTItem urlItem = {0, NULL, 0};
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTItem advisorContext = {0, NULL, 0};
|
||||
void * pwin;
|
||||
|
||||
CMTSecurityAdvisorData data;
|
||||
memset(&data, '\0', sizeof(CMTSecurityAdvisorData));
|
||||
|
||||
/* Create a Security Advisor context object. */
|
||||
rv = CMT_SecurityAdvisor(control, &data, &advRID);
|
||||
|
||||
if (rv != CMTSuccess)
|
||||
return PR_FAILURE;
|
||||
|
||||
/* Get the URL, width, height, etc. from the advisor context. */
|
||||
rv = CMT_GetStringAttribute(control,
|
||||
advRID,
|
||||
SSM_FID_SECADVISOR_URL,
|
||||
&urlItem);
|
||||
|
||||
if ((rv != CMTSuccess) || (!urlItem.data))
|
||||
return PR_FAILURE;
|
||||
|
||||
rv = CMT_GetNumericAttribute(control,
|
||||
advRID,
|
||||
SSM_FID_SECADVISOR_WIDTH,
|
||||
&width);
|
||||
if (rv != CMTSuccess)
|
||||
return PR_FAILURE;
|
||||
|
||||
rv = CMT_GetNumericAttribute(control,
|
||||
advRID,
|
||||
SSM_FID_SECADVISOR_HEIGHT,
|
||||
&height);
|
||||
if (rv != CMTSuccess)
|
||||
return PR_FAILURE;
|
||||
|
||||
/* Fire the URL up in a window of its own. */
|
||||
pwin = CartmanUIHandler(advRID, arg, width, height, (char*)urlItem.data, NULL);
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void* CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, char* urlStr, void *data)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
handler->DisplayURI(width, height, urlStr);
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char * PromptUserCallback(void *arg, char *prompt, int isPasswd)
|
||||
{
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
PRUnichar *password;
|
||||
PRInt32 value;
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, NS_UI_THREAD_EVENTQ, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = dialog->PromptPassword(nsString(prompt).GetUnicode(), nsnull /* window title */, &password, &value);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsString a(password);
|
||||
char* str = a.ToNewCString();
|
||||
Recycle(password);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void ApplicationFreeCallback(char *userInput)
|
||||
{
|
||||
nsAllocator::Free(userInput);
|
||||
}
|
||||
|
||||
char * FilePathPromptCallback(void *arg, char *prompt, char *fileRegEx, CMUint32 shouldFileExist)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
char* filePath = nsnull;
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
handler->PromptForFile(prompt, fileRegEx, (PRBool)shouldFileExist, &filePath);
|
||||
|
||||
return filePath;
|
||||
}
|
||||
57
mozilla/netwerk/security/psm/nsPSMUICallbacks.h
Normal file
57
mozilla/netwerk/security/psm/nsPSMUICallbacks.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _NSPSMUICALLBACKS_H
|
||||
#define _NSPSMUICALLBACKS_H
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsIPSMUIHandler.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
#include "cmtcmn.h" /* fix */
|
||||
#include "cmtjs.h"
|
||||
|
||||
PRStatus InitPSMUICallbacks(PCMT_CONTROL gControl);
|
||||
PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, void *arg);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#define NS_PSMUIHANDLER_CID {0x15944e30, 0x601e, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
|
||||
|
||||
class nsPSMUIHandlerImpl : public nsIPSMUIHandler
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_PSMUIHANDLER_CID );
|
||||
|
||||
/* ctor/dtor */
|
||||
nsPSMUIHandlerImpl() { NS_INIT_REFCNT(); }
|
||||
virtual ~nsPSMUIHandlerImpl() { }
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPSMUIHANDLER
|
||||
|
||||
static NS_METHOD CreatePSMUIHandler(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -26,7 +26,11 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = base
|
||||
DIRS = base ssl
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ MODULE = necko
|
||||
|
||||
DIRS= \
|
||||
base \
|
||||
ssl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
49
mozilla/netwerk/socket/ssl/Makefile.in
Normal file
49
mozilla/netwerk/socket/ssl/Makefile.in
Normal file
@@ -0,0 +1,49 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
|
||||
IS_COMPONENT = 1
|
||||
LIBRARY_NAME = nkssl
|
||||
|
||||
CPPSRCS = \
|
||||
nsSSLIOLayer.cpp \
|
||||
nsSSLSocketFactory.cpp \
|
||||
nsSSLSocketProvider.cpp \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsISSLSocketProvider.idl \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS = -L$(DIST)/lib -lcmt -lxpcom -lprotocol
|
||||
|
||||
NO_GEN_XPT=1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
INCLUDES += \
|
||||
-I$(srcdir) \
|
||||
-I$(srcdir)/../../security/psm \
|
||||
$(NULL)
|
||||
72
mozilla/netwerk/socket/ssl/makefile.win
Normal file
72
mozilla/netwerk/socket/ssl/makefile.win
Normal file
@@ -0,0 +1,72 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
MODULE = necko
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
LIBRARY_NAME=nkssl
|
||||
DLLNAME = nkssl
|
||||
PDBFILE = $(DLLNAME).pdb
|
||||
MAPFILE = $(DLLNAME).map
|
||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
LINCS = \
|
||||
-I$(PUBLIC) \
|
||||
-I$(DEPTH)\..\mozilla\netwerk\base\src \
|
||||
-I..\..\security\psm \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\neckopsm_s.lib \
|
||||
$(DIST)\lib\cmt.lib \
|
||||
$(DIST)\lib\protocol.lib \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(NULL)
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsSSLIOLayer.obj \
|
||||
.\$(OBJDIR)\nsSSLSocketFactory.obj \
|
||||
.\$(OBJDIR)\nsSSLSocketProvider.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
XPIDL_INCLUDES=-I$(DEPTH)\..\mozilla\dist\idl
|
||||
|
||||
XPIDLSRCS= \
|
||||
.\nsISSLSocketProvider.idl \
|
||||
$(NULL)
|
||||
|
||||
NO_GEN_XPT=1
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
|
||||
clobber::
|
||||
rm -rf $(OBJDIR)
|
||||
33
mozilla/netwerk/socket/ssl/nsISSLSocketProvider.idl
Normal file
33
mozilla/netwerk/socket/ssl/nsISSLSocketProvider.idl
Normal file
@@ -0,0 +1,33 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISocketProvider.idl"
|
||||
|
||||
[noscript, uuid(856a93d0-5415-11d3-bbc8-0000861d1237)]
|
||||
interface nsISSLSocketProvider : nsISocketProvider {
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_ISSLSOCKETPROVIDER_PROGID NS_NETWORK_SOCKET_PROGID_PREFIX "ssl"
|
||||
#define NS_ISSLSOCKETPROVIDER_CLASSNAME "Mozilla SSL Socket Provider Component"
|
||||
|
||||
%}
|
||||
315
mozilla/netwerk/socket/ssl/nsSSLIOLayer.cpp
Normal file
315
mozilla/netwerk/socket/ssl/nsSSLIOLayer.cpp
Normal file
@@ -0,0 +1,315 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#include "nsIPSMComponent.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
#include "nsSSLIOLayer.h"
|
||||
|
||||
/* TODO: check for failures */
|
||||
static PRDescIdentity nsSSLIOLayerIdentity;
|
||||
static PRIOMethods nsSSLIOLayerMethods;
|
||||
|
||||
typedef struct nsSSLIOLayerSecretData
|
||||
{
|
||||
PCMT_CONTROL control;
|
||||
CMSocket *cmsock;
|
||||
} nsSSLIOLayerSecretData;
|
||||
|
||||
static nsIPSMComponent* psm = nsnull;
|
||||
|
||||
static PRStatus PR_CALLBACK
|
||||
nsSSLIOLayerConnect(PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
|
||||
{
|
||||
nsSSLIOLayerSecretData *secret;
|
||||
int i=1;
|
||||
nsresult result;
|
||||
PRStatus rv = PR_SUCCESS;
|
||||
CMTStatus status;
|
||||
|
||||
const char* hostName;
|
||||
|
||||
/* Set the error in case of failure. */
|
||||
|
||||
PR_SetError(PR_UNKNOWN_ERROR, status);
|
||||
|
||||
if (!fd || !addr)
|
||||
return PR_FAILURE;
|
||||
|
||||
secret = (nsSSLIOLayerSecretData *)PR_Malloc(sizeof(nsSSLIOLayerSecretData));
|
||||
if (!secret) return PR_FAILURE;
|
||||
|
||||
memset(secret, 0, sizeof(nsSSLIOLayerSecretData));
|
||||
|
||||
/* TODO: this should be allocated from cmshim layer */
|
||||
secret->cmsock = (CMSocket *)PR_Malloc(sizeof(CMSocket));
|
||||
if (!secret->cmsock)
|
||||
{
|
||||
PR_Free(secret);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
memset(secret->cmsock, 0, sizeof(CMSocket));
|
||||
|
||||
if (psm == nsnull)
|
||||
{
|
||||
result = nsServiceManager::GetService( PSM_COMPONENT_PROGID,
|
||||
NS_GET_IID(nsIPSMComponent),
|
||||
(nsISupports**)&psm);
|
||||
if (NS_FAILED(result))
|
||||
{
|
||||
rv=PR_FAILURE;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
result = psm->GetControlConnection(&secret->control);
|
||||
|
||||
if (result != PR_SUCCESS)
|
||||
{
|
||||
rv = PR_FAILURE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
secret->cmsock->fd = fd->lower;
|
||||
secret->cmsock->isUnix = PR_FALSE;
|
||||
|
||||
/* TODO: XXX fix this RSN */
|
||||
{
|
||||
PRSocketOptionData opt;
|
||||
|
||||
// Make the socket non-blocking...
|
||||
opt.option = PR_SockOpt_Nonblocking;
|
||||
opt.value.non_blocking = PR_FALSE;
|
||||
rv = PR_SetSocketOption(fd->lower, &opt);
|
||||
if (PR_SUCCESS != rv)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
char ipBuffer[PR_NETDB_BUF_SIZE];
|
||||
rv = PR_NetAddrToString(addr, (char*)&ipBuffer, PR_NETDB_BUF_SIZE);
|
||||
|
||||
if (rv != PR_SUCCESS)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
if (fd->secret) // how do we know that this is a necko nsSocketTransportFDPrivate??
|
||||
{
|
||||
hostName = (const char*)fd->secret;
|
||||
}
|
||||
else
|
||||
{
|
||||
// no hostname, use ip address.
|
||||
hostName = ipBuffer;
|
||||
}
|
||||
|
||||
|
||||
fd->secret = (PRFilePrivate *)secret;
|
||||
|
||||
status = CMT_OpenSSLConnection(secret->control,
|
||||
secret->cmsock,
|
||||
SSM_REQUEST_SSL_DATA_SSL,
|
||||
PR_ntohs(addr->inet.port),
|
||||
ipBuffer,
|
||||
(char*)hostName,
|
||||
CM_TRUE,
|
||||
nsnull);
|
||||
if (CMTSuccess == status)
|
||||
{
|
||||
// since our stuff can block, what we want to do is return PR_FAILURE,
|
||||
// but set the nspr ERROR to BLOCK. This will put us into a select
|
||||
// q.
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, status);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
fail:
|
||||
fd->secret = nsnull;
|
||||
PR_FREEIF(secret->cmsock)
|
||||
|
||||
secret->cmsock = nsnull;
|
||||
PR_FREEIF(secret);
|
||||
|
||||
secret = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* CMT_DestroyDataConnection(ctrl, sock); */
|
||||
/* need to strip our layer, pass result to DestroyDataConnection */
|
||||
/* which will clean up the CMT accounting of sock, then call our */
|
||||
/* shim layer to translate back to NSPR */
|
||||
|
||||
static PRStatus PR_CALLBACK
|
||||
nsSSLIOLayerClose(PRFileDesc *fd)
|
||||
{
|
||||
nsSSLIOLayerSecretData *secret = (nsSSLIOLayerSecretData *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (secret && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
|
||||
if (CMT_GetSSLDataErrorCode(secret->control, secret->cmsock, &errorCode) == PR_SUCCESS)
|
||||
{
|
||||
CMT_DestroyDataConnection(secret->control, secret->cmsock);
|
||||
|
||||
PR_Free(secret);
|
||||
|
||||
fd->secret = NULL;
|
||||
fd->identity = PR_INVALID_IO_LAYER;
|
||||
}
|
||||
return (PRStatus)errorCode;
|
||||
}
|
||||
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
static PRInt32 PR_CALLBACK
|
||||
nsSSLIOLayerRead( PRFileDesc *fd, void *buf, PRInt32 amount)
|
||||
{
|
||||
if (!fd)
|
||||
return PR_FAILURE;
|
||||
|
||||
PRInt32 result = PR_Recv(fd, buf, amount, 0, PR_INTERVAL_MIN);
|
||||
|
||||
if (result > 0)
|
||||
return result;
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
PRErrorCode code = PR_GetError();
|
||||
|
||||
if (code == PR_IO_TIMEOUT_ERROR )
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
nsSSLIOLayerSecretData *secret = (nsSSLIOLayerSecretData *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (secret && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
|
||||
CMT_GetSSLDataErrorCode(secret->control, secret->cmsock, &errorCode);
|
||||
|
||||
if (errorCode == PR_IO_TIMEOUT_ERROR)
|
||||
{
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
PR_SetError(0, 0);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static PRInt32 PR_CALLBACK
|
||||
nsSSLIOLayerWrite( PRFileDesc *fd, const void *buf, PRInt32 amount)
|
||||
{
|
||||
if (!fd)
|
||||
return PR_FAILURE;
|
||||
|
||||
PRInt32 result = PR_Send(fd, buf, amount, 0, PR_INTERVAL_MIN);
|
||||
|
||||
if (result > 0)
|
||||
return result;
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
PRErrorCode code = PR_GetError();
|
||||
|
||||
if (code == PR_IO_TIMEOUT_ERROR )
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
nsSSLIOLayerSecretData *secret = (nsSSLIOLayerSecretData *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (secret && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
|
||||
CMT_GetSSLDataErrorCode(secret->control, secret->cmsock, &errorCode);
|
||||
PR_SetError(0, 0);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PRFileDesc *
|
||||
nsSSLIOLayerNewSocket(const char* hostName)
|
||||
{
|
||||
static PRBool firstTime = PR_TRUE;
|
||||
PRFileDesc * sock;
|
||||
PRFileDesc * layer;
|
||||
PRStatus rv;
|
||||
|
||||
/* Get a normal NSPR socket */
|
||||
sock = PR_NewTCPSocket(); PR_ASSERT(NULL != sock);
|
||||
|
||||
if (! sock) return NULL;
|
||||
|
||||
|
||||
if (firstTime)
|
||||
{
|
||||
nsSSLIOLayerIdentity = PR_GetUniqueIdentity("Cartman layer");
|
||||
nsSSLIOLayerMethods = *PR_GetDefaultIOMethods();
|
||||
|
||||
nsSSLIOLayerMethods.connect = nsSSLIOLayerConnect;
|
||||
nsSSLIOLayerMethods.close = nsSSLIOLayerClose;
|
||||
nsSSLIOLayerMethods.read = nsSSLIOLayerRead;
|
||||
nsSSLIOLayerMethods.write = nsSSLIOLayerWrite;
|
||||
firstTime = PR_FALSE;
|
||||
}
|
||||
|
||||
layer = PR_CreateIOLayerStub(nsSSLIOLayerIdentity, &nsSSLIOLayerMethods);
|
||||
|
||||
if (layer)
|
||||
{
|
||||
layer->secret = (PRFilePrivate*)hostName;
|
||||
rv = PR_PushIOLayer(sock, PR_GetLayersIdentity(sock), layer);
|
||||
}
|
||||
|
||||
if(PR_SUCCESS != rv)
|
||||
return NULL;
|
||||
|
||||
return sock;
|
||||
}
|
||||
37
mozilla/netwerk/socket/ssl/nsSSLIOLayer.h
Normal file
37
mozilla/netwerk/socket/ssl/nsSSLIOLayer.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _NSSSLIOLAYER_H
|
||||
#define _NSSSLIOLAYER_H
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prio.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
//typedef PRFileDesc* (PR_CALLBACK *NSPRSocketFN)(void); ??
|
||||
|
||||
PR_EXTERN(PRFileDesc *) nsSSLIOLayerNewSocket(const char* hostName);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* _NSSSLIOLAYER_H */
|
||||
39
mozilla/netwerk/socket/ssl/nsSSLSocketFactory.cpp
Normal file
39
mozilla/netwerk/socket/ssl/nsSSLSocketFactory.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIModule.h"
|
||||
|
||||
#include "nsSSLSocketProvider.h"
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ NS_ISSLSOCKETPROVIDER_CLASSNAME,
|
||||
NS_SSLSOCKETPROVIDER_CID,
|
||||
NS_ISSLSOCKETPROVIDER_PROGID,
|
||||
nsSSLSocketProvider::Create }
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("SSLSocketProviderModule", components);
|
||||
|
||||
79
mozilla/netwerk/socket/ssl/nsSSLSocketProvider.cpp
Normal file
79
mozilla/netwerk/socket/ssl/nsSSLSocketProvider.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsSSLSocketProvider.h"
|
||||
#include "nsSSLIOLayer.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsSSLSocketProvider::nsSSLSocketProvider()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSSLSocketProvider::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsSSLSocketProvider::~nsSSLSocketProvider()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSSLSocketProvider, nsISocketProvider, nsISSLSocketProvider);
|
||||
|
||||
NS_METHOD
|
||||
nsSSLSocketProvider::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsSSLSocketProvider* pSockProv = new nsSSLSocketProvider();
|
||||
|
||||
if (nsnull == pSockProv)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(pSockProv);
|
||||
|
||||
nsresult rv = pSockProv->Init();
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = pSockProv->QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
NS_RELEASE(pSockProv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSSLSocketProvider::NewSocket(const char *hostName, PRFileDesc **_result)
|
||||
{
|
||||
*_result = nsSSLIOLayerNewSocket(hostName);
|
||||
|
||||
return (nsnull == *_result) ? NS_ERROR_SOCKET_CREATE_FAILED : NS_OK;
|
||||
}
|
||||
54
mozilla/netwerk/socket/ssl/nsSSLSocketProvider.h
Normal file
54
mozilla/netwerk/socket/ssl/nsSSLSocketProvider.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _NSSSLSOCKETPROVIDER_H_
|
||||
#define _NSSSLSOCKETPROVIDER_H_
|
||||
|
||||
#include "nsISSLSocketProvider.h"
|
||||
|
||||
|
||||
/* 274418d0-5437-11d3-bbc8-0000861d1237 */
|
||||
#define NS_SSLSOCKETPROVIDER_CID { 0x274418d0, 0x5437, 0x11d3, {0xbb, 0xc8, 0x00, 0x00, 0x86, 0x1d, 0x12, 0x37}}
|
||||
|
||||
|
||||
class nsSSLSocketProvider : public nsISSLSocketProvider
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSISOCKETPROVIDER
|
||||
|
||||
NS_DECL_NSISSLSOCKETPROVIDER
|
||||
|
||||
// nsSSLSocketProvider methods:
|
||||
nsSSLSocketProvider();
|
||||
virtual ~nsSSLSocketProvider();
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif /* _NSSSLSOCKETPROVIDER_H_ */
|
||||
36
mozilla/netwerk/socket/tests/Makefile.in
Normal file
36
mozilla/netwerk/socket/tests/Makefile.in
Normal file
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
PROGRAM = TestSSL
|
||||
|
||||
CPPSRCS = \
|
||||
TestSSL.cpp \
|
||||
$(NULL)
|
||||
|
||||
LIBS = -L$(DIST)/bin \
|
||||
$(NSPR_LIBS) \
|
||||
-lxpcom \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
495
mozilla/netwerk/socket/tests/TestSSL.cpp
Normal file
495
mozilla/netwerk/socket/tests/TestSSL.cpp
Normal file
@@ -0,0 +1,495 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
#include "nsIProfile.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
#include "nsISocketProviderService.h"
|
||||
#include "nsISocketProvider.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
|
||||
static NS_DEFINE_CID(kSocketProviderService, NS_SOCKETPROVIDERSERVICE_CID);
|
||||
|
||||
|
||||
PRUint32
|
||||
TestSSL_syncprintf(const char *fmt, ...)
|
||||
{
|
||||
static PRFileDesc *logFile=0;
|
||||
va_list marker;
|
||||
|
||||
if (!logFile)
|
||||
logFile = PR_GetSpecialFD(PR_StandardError);
|
||||
|
||||
PR_ASSERT(logFile);
|
||||
|
||||
va_start(marker, fmt);
|
||||
PR_vfprintf(logFile, fmt, marker);
|
||||
va_end(marker);
|
||||
|
||||
/* PR_Sync(logFile); */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* TODO: deal with bad arg, error cases */
|
||||
PRStatus
|
||||
GetPage(PRFileDesc *sock, char *sName, PRUint16 sPort, char *path)
|
||||
{
|
||||
PRNetAddr netAddr;
|
||||
PRHostEnt hostEntry;
|
||||
char netBuf[2*PR_NETDB_BUF_SIZE];
|
||||
char outBuf[2048]; /* TODO: worry about max sizes */
|
||||
char inBuf[32768];
|
||||
PRIntn cmdSize;
|
||||
PRInt32 cnt;
|
||||
PRStatus rv;
|
||||
|
||||
memset(&netAddr, 0, sizeof(PRNetAddr));
|
||||
|
||||
rv = PR_GetHostByName(sName, netBuf, sizeof(netBuf), &hostEntry);
|
||||
|
||||
if (PR_SUCCESS == rv)
|
||||
{
|
||||
netAddr.inet.family = PR_AF_INET;
|
||||
netAddr.inet.port = PR_htons(sPort);
|
||||
netAddr.inet.ip = *((PRUint32 *)hostEntry.h_addr_list[0]);
|
||||
|
||||
rv = PR_Connect(sock, &netAddr, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
|
||||
if (PR_SUCCESS == rv)
|
||||
{
|
||||
TestSSL_syncprintf("Connected to %s on port %d\n", sName, sPort);
|
||||
cmdSize = PR_snprintf(outBuf,
|
||||
sizeof(outBuf), "GET %s HTTP/1.0\r\n\r\n", path);
|
||||
outBuf[cmdSize] = 0; /* TODO: shouldn't assume positive value */
|
||||
|
||||
cnt = PR_Send(sock, outBuf, cmdSize, 0, PR_INTERVAL_NO_TIMEOUT);
|
||||
TestSSL_syncprintf("Send command cmdSize=%d, cnt=%d\n", cmdSize, cnt);
|
||||
TestSSL_syncprintf("Send command cmd\n%s", outBuf);
|
||||
if (cnt < 0)
|
||||
rv = PR_FAILURE;
|
||||
}
|
||||
|
||||
if (PR_SUCCESS == rv)
|
||||
{
|
||||
PR_Sleep(PR_SecondsToInterval(1));
|
||||
memset(inBuf, 0, sizeof(inBuf));
|
||||
|
||||
cnt = PR_Recv(sock, inBuf, sizeof(inBuf), 0, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
||||
if (cnt < 0)
|
||||
rv = PR_FAILURE;
|
||||
}
|
||||
|
||||
if (PR_SUCCESS == rv)
|
||||
{
|
||||
inBuf[cnt] = 0;
|
||||
TestSSL_syncprintf("Receive data cnt=%d\n", cnt);
|
||||
TestSSL_syncprintf("----\n");
|
||||
TestSSL_syncprintf("%s\n", inBuf);
|
||||
TestSSL_syncprintf("----\n");
|
||||
}
|
||||
|
||||
if (PR_SUCCESS == rv)
|
||||
{
|
||||
rv = PR_Shutdown(sock, PR_SHUTDOWN_BOTH);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
#define HTTPS_SERVER "omen"
|
||||
#define HTTPS_PORT 443
|
||||
|
||||
#define HTTP_SERVER "omen"
|
||||
#define HTTP_PORT 80
|
||||
|
||||
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
|
||||
|
||||
nsresult
|
||||
StartupServices(void)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &result);
|
||||
if (NS_SUCCEEDED(result))
|
||||
result = profile->Startup(nsnull);
|
||||
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &result);
|
||||
// psm->Initialize(nsnull, nsnull);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRIntn
|
||||
main(PRIntn argc, char **argv)
|
||||
{
|
||||
PRFileDesc *sockS;
|
||||
PRFileDesc *sock;
|
||||
nsresult rv;
|
||||
|
||||
/* initialize NSPR and logFile */
|
||||
PR_STDIO_INIT();
|
||||
|
||||
StartupServices();
|
||||
|
||||
NS_WITH_SERVICE(nsISocketProviderService,
|
||||
pProviderService,
|
||||
kSocketProviderService,
|
||||
&rv);
|
||||
|
||||
nsISocketProvider *pProvider;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = pProviderService->GetSocketProvider("ssl", &pProvider);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = pProvider->NewSocket( HTTP_SERVER, &sockS );
|
||||
sock = PR_NewTCPSocket();
|
||||
|
||||
/* grab pages using the PRFileDesc's */
|
||||
GetPage(sockS, HTTPS_SERVER, HTTPS_PORT, "/index.html");
|
||||
GetPage(sock, HTTP_SERVER, HTTP_PORT, "/index.html");
|
||||
PR_Close(sockS);
|
||||
PR_Close(sock);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = pProvider->NewSocket( HTTPS_SERVER, &sockS );
|
||||
GetPage(sockS, HTTPS_SERVER, HTTPS_PORT, "/index.html");
|
||||
PR_Close(sockS);
|
||||
NS_RELEASE(pProvider);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef TESTIOLAYER
|
||||
|
||||
static PRDescIdentity identity;
|
||||
|
||||
static PRIOMethods myMethods;
|
||||
|
||||
static PRUint16 default_port = 12273;
|
||||
static PRNetAddr server_address;
|
||||
|
||||
static PRIntn minor_iterations = 5;
|
||||
static PRIntn major_iterations = 1;
|
||||
|
||||
|
||||
static PRInt32 PR_CALLBACK
|
||||
MyRecv(PRFileDesc *fd, void *buf, PRInt32 amount,
|
||||
PRIntn flags, PRIntervalTime timeout)
|
||||
{
|
||||
char *b = (char*)buf;
|
||||
PRFileDesc *lo = fd->lower;
|
||||
PRInt32 rv, readin = 0, request;
|
||||
|
||||
TestSSL_syncprintf(
|
||||
"MyRecv start\n");
|
||||
|
||||
TestSSL_syncprintf(
|
||||
"MyRecv waiting for permission request\n");
|
||||
rv = lo->methods->recv(lo, &request, sizeof(request), flags, timeout);
|
||||
|
||||
if (0 < rv)
|
||||
{
|
||||
TestSSL_syncprintf(
|
||||
"MyRecv received permission request for %d bytes\n", request);
|
||||
|
||||
|
||||
TestSSL_syncprintf(
|
||||
"MyRecv sending permission for %d bytes\n", request);
|
||||
rv = lo->methods->send(
|
||||
lo, &request, sizeof(request), flags, timeout);
|
||||
|
||||
if (0 < rv)
|
||||
{
|
||||
TestSSL_syncprintf(
|
||||
"MyRecv waiting for data\n");
|
||||
while (readin < request)
|
||||
{
|
||||
rv = lo->methods->recv(
|
||||
lo, b + readin, amount - readin, flags, timeout);
|
||||
if (rv <= 0) break;
|
||||
TestSSL_syncprintf(
|
||||
"MyRecv received %d bytes\n", rv);
|
||||
readin += rv;
|
||||
}
|
||||
rv = readin;
|
||||
}
|
||||
}
|
||||
|
||||
TestSSL_syncprintf(
|
||||
"MyRecv end\n");
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static PRInt32 PR_CALLBACK
|
||||
MySend(PRFileDesc *fd, const void *buf, PRInt32 amount,
|
||||
PRIntn flags, PRIntervalTime timeout)
|
||||
{
|
||||
PRFileDesc *lo = fd->lower;
|
||||
const char *b = (const char*)buf;
|
||||
PRInt32 rv, wroteout = 0, request;
|
||||
|
||||
TestSSL_syncprintf(
|
||||
"MySend start\n");
|
||||
TestSSL_syncprintf(
|
||||
"MySend asking permission to send %d bytes\n", amount);
|
||||
|
||||
rv = lo->methods->send(lo, &amount, sizeof(amount), flags, timeout);
|
||||
if (0 < rv)
|
||||
{
|
||||
TestSSL_syncprintf(
|
||||
"MySend waiting for permission to send %d bytes\n", amount);
|
||||
rv = lo->methods->recv(
|
||||
lo, &request, sizeof(request), flags, timeout);
|
||||
if (0 < rv)
|
||||
{
|
||||
PR_ASSERT(request == amount);
|
||||
TestSSL_syncprintf(
|
||||
"MySend got permission to send %d bytes\n", request);
|
||||
while (wroteout < request)
|
||||
{
|
||||
TestSSL_syncprintf("MySend writing %d bytes\n", request-wroteout);
|
||||
rv = lo->methods->send(
|
||||
lo, b + wroteout, request - wroteout, flags, timeout);
|
||||
if (rv <= 0)
|
||||
{
|
||||
TestSSL_syncprintf("MySend send error %d\n", rv);
|
||||
break;
|
||||
}
|
||||
TestSSL_syncprintf("MySend wrote %d bytes\n", rv);
|
||||
wroteout += rv;
|
||||
}
|
||||
rv = amount;
|
||||
}
|
||||
}
|
||||
|
||||
TestSSL_syncprintf(
|
||||
"MySend end\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
static void PR_CALLBACK ServerCallback(void *arg)
|
||||
{
|
||||
PRStatus rv;
|
||||
PRUint8 buffer[100];
|
||||
PRFileDesc *service;
|
||||
PRUintn empty_flags = 0;
|
||||
PRIntn bytes_read, bytes_sent;
|
||||
PRFileDesc *stack = (PRFileDesc*)arg;
|
||||
PRNetAddr any_address, client_address;
|
||||
|
||||
TestSSL_syncprintf("Begin ServerCallback\n");
|
||||
|
||||
rv = PR_InitializeNetAddr(PR_IpAddrAny, default_port, &any_address);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
rv = PR_Bind(stack, &any_address); PR_ASSERT(PR_SUCCESS == rv);
|
||||
rv = PR_Listen(stack, 10); PR_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
TestSSL_syncprintf("Server in accept(), waiting for connection\n");
|
||||
service = PR_Accept(stack, &client_address, PR_INTERVAL_NO_TIMEOUT);
|
||||
TestSSL_syncprintf("Server connection accepted\n");
|
||||
|
||||
do
|
||||
{
|
||||
TestSSL_syncprintf("Server starting to receive\n");
|
||||
bytes_read = PR_Recv(
|
||||
service, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (0 != bytes_read)
|
||||
{
|
||||
TestSSL_syncprintf("Server received %d bytes\n", bytes_read);
|
||||
PR_ASSERT(bytes_read > 0);
|
||||
|
||||
TestSSL_syncprintf("Server sending %d bytes\n", bytes_read);
|
||||
bytes_sent = PR_Send(
|
||||
service, buffer, bytes_read, empty_flags, PR_INTERVAL_NO_TIMEOUT);
|
||||
PR_ASSERT(bytes_read == bytes_sent);
|
||||
}
|
||||
|
||||
} while (0 != bytes_read);
|
||||
|
||||
TestSSL_syncprintf("Server shutting down and closing stack\n");
|
||||
|
||||
rv = PR_Shutdown(service, PR_SHUTDOWN_BOTH); PR_ASSERT(PR_SUCCESS == rv);
|
||||
rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
TestSSL_syncprintf("End ServerCallback\n");
|
||||
return;
|
||||
}
|
||||
|
||||
static void PR_CALLBACK ClientCallback(void *arg)
|
||||
{
|
||||
PRStatus rv;
|
||||
PRUint8 buffer[100];
|
||||
PRIntn empty_flags = 0;
|
||||
PRIntn bytes_read, bytes_sent;
|
||||
PRFileDesc *stack = (PRFileDesc*)arg;
|
||||
|
||||
TestSSL_syncprintf("Begin ClientCallback\n");
|
||||
|
||||
TestSSL_syncprintf("Client connecting to server\n");
|
||||
rv = PR_Connect(stack, &server_address, PR_INTERVAL_NO_TIMEOUT);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
TestSSL_syncprintf("Client connected to server\n");
|
||||
|
||||
while (minor_iterations-- > 0)
|
||||
{
|
||||
TestSSL_syncprintf("Client sending %d bytes\n", sizeof(buffer));
|
||||
bytes_sent = PR_Send(
|
||||
stack, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
|
||||
TestSSL_syncprintf("Client ended up sending %d bytes\n", bytes_sent);
|
||||
|
||||
TestSSL_syncprintf("Client expecting to receive %d bytes\n", bytes_sent);
|
||||
PR_ASSERT(sizeof(buffer) == bytes_sent);
|
||||
bytes_read = PR_Recv(
|
||||
stack, buffer, bytes_sent, empty_flags, PR_INTERVAL_NO_TIMEOUT);
|
||||
TestSSL_syncprintf("Client ended up reveiving %d bytes\n", bytes_read);
|
||||
PR_ASSERT(bytes_read == bytes_sent);
|
||||
}
|
||||
|
||||
TestSSL_syncprintf("Client shutting down stack\n");
|
||||
|
||||
rv = PR_Shutdown(stack, PR_SHUTDOWN_BOTH); PR_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
TestSSL_syncprintf("End ClientCallback\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static PRFileDesc *PushLayer(PRFileDesc *stack)
|
||||
{
|
||||
PRFileDesc *layer = PR_CreateIOLayerStub(identity, &myMethods);
|
||||
PRStatus rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), layer);
|
||||
TestSSL_syncprintf("Pushed layer(0x%x) onto stack(0x%x)\n", layer, stack);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
return stack;
|
||||
} /* PushLayer */
|
||||
|
||||
|
||||
static PRFileDesc *PopLayer(PRFileDesc *stack)
|
||||
{
|
||||
PRFileDesc *popped = PR_PopIOLayer(stack, identity);
|
||||
TestSSL_syncprintf("Popped layer(0x%x) from stack(0x%x)\n", popped, stack);
|
||||
popped->dtor(popped);
|
||||
|
||||
return stack;
|
||||
} /* PopLayer */
|
||||
|
||||
|
||||
PRIntn
|
||||
main(PRIntn argc, char **argv)
|
||||
{
|
||||
PRStatus rv;
|
||||
PRFileDesc *client, *service;
|
||||
const PRIOMethods *stubMethods;
|
||||
PRThreadScope thread_scope = PR_GLOBAL_THREAD;
|
||||
PRThread *client_thread, *server_thread;
|
||||
|
||||
PR_STDIO_INIT(); /* call this to init NSPR stdin/out/err */
|
||||
|
||||
identity = PR_GetUniqueIdentity("Dummy protocol");
|
||||
stubMethods = PR_GetDefaultIOMethods();
|
||||
/* are there any differences between file/socket methods? */
|
||||
|
||||
myMethods = *stubMethods; /* first get the entire batch */
|
||||
|
||||
myMethods.recv = MyRecv; /* then override the ones we care about */
|
||||
myMethods.send = MySend; /* then override the ones we care about */
|
||||
|
||||
rv = PR_InitializeNetAddr(PR_IpAddrLoopback, default_port, &server_address);
|
||||
|
||||
|
||||
{
|
||||
TestSSL_syncprintf("Beginning non-layered test\n");
|
||||
client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);
|
||||
service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);
|
||||
|
||||
server_thread = PR_CreateThread(
|
||||
PR_USER_THREAD, ServerCallback, service,
|
||||
PR_PRIORITY_HIGH, thread_scope,
|
||||
PR_JOINABLE_THREAD, 16 * 1024);
|
||||
PR_ASSERT(NULL != server_thread);
|
||||
|
||||
client_thread = PR_CreateThread(
|
||||
PR_USER_THREAD, ClientCallback, client,
|
||||
PR_PRIORITY_NORMAL, thread_scope,
|
||||
PR_JOINABLE_THREAD, 16 * 1024);
|
||||
PR_ASSERT(NULL != client_thread);
|
||||
|
||||
rv = PR_JoinThread(client_thread);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
rv = PR_JoinThread(server_thread);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
rv = PR_Close(client); PR_ASSERT(PR_SUCCESS == rv);
|
||||
rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);
|
||||
TestSSL_syncprintf("Ending non-layered test\n");
|
||||
}
|
||||
|
||||
TestSSL_syncprintf("----\n");
|
||||
|
||||
{
|
||||
/* with layering */
|
||||
minor_iterations = 5;
|
||||
TestSSL_syncprintf("Beginning layered test\n");
|
||||
client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);
|
||||
service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);
|
||||
|
||||
server_thread = PR_CreateThread(
|
||||
PR_USER_THREAD, ServerCallback, PushLayer(service),
|
||||
PR_PRIORITY_HIGH, thread_scope,
|
||||
PR_JOINABLE_THREAD, 16 * 1024);
|
||||
PR_ASSERT(NULL != server_thread);
|
||||
|
||||
client_thread = PR_CreateThread(
|
||||
PR_USER_THREAD, ClientCallback, PushLayer(client),
|
||||
PR_PRIORITY_NORMAL, thread_scope,
|
||||
PR_JOINABLE_THREAD, 16 * 1024);
|
||||
PR_ASSERT(NULL != client_thread);
|
||||
|
||||
rv = PR_JoinThread(client_thread);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
rv = PR_JoinThread(server_thread);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
rv = PR_Close(client); PR_ASSERT(PR_SUCCESS == rv);
|
||||
rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);
|
||||
TestSSL_syncprintf("Ending layered test\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
53
mozilla/netwerk/socket/tests/makefile.win
Normal file
53
mozilla/netwerk/socket/tests/makefile.win
Normal file
@@ -0,0 +1,53 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
MODULE = necko
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
MAKE_OBJ_TYPE = EXE
|
||||
PROGRAM = .\$(OBJDIR)\TestSSL.exe
|
||||
|
||||
LINCS = \
|
||||
-I$(PUBLIC) \
|
||||
-I..\ssl \
|
||||
$(NULL)
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\TestSSL.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\nspr3.lib \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(PROGRAM)
|
||||
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
|
||||
|
||||
clobber::
|
||||
rm -rf $(OBJDIR)
|
||||
@@ -25,6 +25,7 @@ Contributor(s): ______________________________________. -->
|
||||
<?xul-overlay href="chrome://navigator/content/navigatorOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://global/content/tasksOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://sidebar/content/sidebarOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://navigator/content/NavSecurityOverlay.xul"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://navigator/locale/navigator.dtd" >
|
||||
|
||||
|
||||
@@ -120,7 +120,9 @@ PRBool isDoingHistory=PR_FALSE;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifndef DEBUG_pavlov
|
||||
#define FORCE_CHECKIN_GUIDELINES
|
||||
#endif /* DEBUG_pavlov */
|
||||
#endif /* DEBUG */
|
||||
|
||||
|
||||
|
||||
@@ -30,3 +30,4 @@ wizardOverlay.js
|
||||
wizardOverlay.xul
|
||||
treePopups.js
|
||||
mozilla.html
|
||||
PSMTaskMenu.xul
|
||||
|
||||
@@ -61,6 +61,7 @@ EXPORT_RESOURCE_CONTENT = \
|
||||
$(srcdir)/wizardOverlay.js \
|
||||
$(srcdir)/wizardOverlay.xul \
|
||||
$(srcdir)/treePopups.js \
|
||||
$(srcdir)/PSMTaskMenu.xul \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
15
mozilla/xpfe/global/resources/content/PSMTaskMenu.xul
Normal file
15
mozilla/xpfe/global/resources/content/PSMTaskMenu.xul
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://global/locale/PSMTaskMenu.dtd" >
|
||||
|
||||
<overlay id="psmTaskMenuID"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<html:script language="JavaScript" src="chrome://netwerk/content/https/psm.js" />
|
||||
|
||||
<menupopup id="taskPopup">
|
||||
<menuitem id="PSMMentItem" position="4" value="&PSMCmd.label;" oncommand="displaySecurityAdvisor()"/>
|
||||
</menupopup>
|
||||
|
||||
</overlay>
|
||||
@@ -61,6 +61,7 @@ install::
|
||||
$(MAKE_INSTALL) wizardOverlay.js $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) wizardOverlay.xul $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) treePopups.js $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) PSMTaskMenu.xul $(DISTBROWSER)
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\chrome\global\content\default\*.*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/tasksOverlay.css" type="text/css"?>
|
||||
<?xul-overlay href="chrome://global/content/PSMTaskMenu.xul"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://global/locale/tasksOverlay.dtd">
|
||||
|
||||
|
||||
@@ -9,3 +9,4 @@ wizardManager.properties
|
||||
wizardOverlay.dtd
|
||||
about.dtd
|
||||
brand.properties
|
||||
PSMTaskMenu.dtd
|
||||
|
||||
@@ -40,6 +40,7 @@ EXPORT_RESOURCE_CONTENT = \
|
||||
$(srcdir)/wizardManager.properties \
|
||||
$(srcdir)/wizardOverlay.dtd \
|
||||
$(srcdir)/about.dtd \
|
||||
$(srcdir)/PSMTaskMenu.dtd \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<!ENTITY PSMCmd.label "Security Advisor">
|
||||
@@ -40,6 +40,7 @@ install::
|
||||
$(MAKE_INSTALL) wizardManager.properties $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) wizardOverlay.dtd $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) about.dtd $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) PSMTaskMenu.dtd $(DISTBROWSER)
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\chrome\global\locale\en-US\*.*
|
||||
|
||||
Reference in New Issue
Block a user