diff --git a/mozilla/caps/Makefile b/mozilla/caps/Makefile index d2c6c2961af..7aebbfd4728 100644 --- a/mozilla/caps/Makefile +++ b/mozilla/caps/Makefile @@ -16,6 +16,6 @@ DEPTH = .. -DIRS = include src +DIRS = public include src include $(DEPTH)/config/rules.mk diff --git a/mozilla/caps/include/Makefile b/mozilla/caps/include/Makefile index 2284e30b5f9..6e4b2672042 100755 --- a/mozilla/caps/include/Makefile +++ b/mozilla/caps/include/Makefile @@ -18,7 +18,13 @@ MODULE = caps DEPTH = ../.. -EXPORTS = nsZip.h nsZig.h nsLoadZig.h nsPrincipal.h nsPrivilege.h nsPrivilegeManager.h nsPrivilegeTable.h nsSystemPrivilegeTable.h nsTarget.h nsUserTarget.h jpermission.h nsUserDialogHelper.h admin.h nsCaps.h nsCapsEnums.h +EXPORTS = nsZip.h nsZig.h nsLoadZig.h nsPrincipal.h nsPrivilege.h nsPrivilegeManager.h nsPrivilegeTable.h nsSystemPrivilegeTable.h nsTarget.h nsUserTarget.h jpermission.h nsUserDialogHelper.h admin.h nsCaps.h nsCapsEnums.h \ + nsCCapsManager.h \ + nsCCertPrincipal.h \ + nsCCodebasePrincipal.h \ + nsCCapsManagerFactory.h + + include $(DEPTH)/config/rules.mk diff --git a/mozilla/caps/include/makefile.win b/mozilla/caps/include/makefile.win index f1da9c7f48f..eec456b132c 100755 --- a/mozilla/caps/include/makefile.win +++ b/mozilla/caps/include/makefile.win @@ -28,7 +28,13 @@ IGNORE_MANIFEST=1 MODULE=caps DEPTH=..\.. -EXPORTS=nsZip.h nsZig.h nsLoadZig.h nsPrincipal.h nsPrivilege.h nsPrivilegeManager.h nsPrivilegeTable.h nsSystemPrivilegeTable.h nsTarget.h nsUserTarget.h jpermission.h nsUserDialogHelper.h admin.h nsCaps.h nsCapsEnums.h +EXPORTS=nsZip.h nsZig.h nsLoadZig.h nsPrincipal.h nsPrivilege.h nsPrivilegeManager.h nsPrivilegeTable.h nsSystemPrivilegeTable.h nsTarget.h nsUserTarget.h jpermission.h nsUserDialogHelper.h admin.h nsCaps.h nsCapsEnums.h \ + nsCCapsManager.h \ + nsCCertPrincipal.h \ + nsCCodebasePrincipal.h \ + nsCCapsManagerFactory.h \ + nsCCodeSourcePrincipal.h + include <$(DEPTH)/config/rules.mak> diff --git a/mozilla/caps/include/nsCCapsManager.h b/mozilla/caps/include/nsCCapsManager.h new file mode 100644 index 00000000000..4976940a298 --- /dev/null +++ b/mozilla/caps/include/nsCCapsManager.h @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsCCapsManager_h___ +#define nsCCapsManager_h___ + +#include "nsIPrincipal.h" +#include "nsISupports.h" +#include "nsICapsManager.h" +#include "nsAgg.h" + +#include "nsPrincipal.h" +#include "nsPrivilegeManager.h" + +/** + * nsCCapsManager implements the nsICapsManager + * interface for navigator. This is used to create new principals and get and + * set permissions for each of the principals created. + * nsCCapsManager registers itself as the factory object and it will always return + * a pointer to itself as in the createInstance. This is because there should be only + * one nsCCapsManager in navigator. + */ +class nsCCapsManager : public nsICapsManager { +public: + //////////////////////////////////////////////////////////////////////////// + // from nsISupports and AggregatedQueryInterface: + + NS_DECL_AGGREGATED + + //////////////////////////////////////////////////////////////////////////// + // from nsICapsManager: + + NS_IMETHOD + CreateCodebasePrincipal(const char *codebaseURL, nsIPrincipal** prin); + + NS_IMETHOD + CreateCertPrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, nsIPrincipal** prin); + + /** + * Creates a CodeSourcePrincipal, which has both nsICodebasePrincipal + * and nsICertPrincipal + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + * @param codebaseURL - the codebase URL + */ + NS_IMETHOD + CreateCodeSourcePrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, const char *codebaseURL, nsIPrincipal** prin); + + /** + * Returns the permission for given principal and target + * + * @param prin - is either certificate principal or codebase principal + * @param target - is NS_ALL_PRIVILEGES. + * @param state - the return value is passed in this parameter. + */ + NS_IMETHOD + GetPermission(nsIPrincipal* prin, nsITarget* target, nsPermission *state); + + /** + * Set the permission state for given principal and target. This wouldn't + * prompt the end user with UI. + * + * @param prin - is either certificate principal or codebase principal + * @param target - is NS_ALL_PRIVILEGES. + * @param state - is permisson state that should be set for the given prin + * and target parameters. + */ + NS_IMETHOD + SetPermission(nsIPrincipal* prin, nsITarget* target, nsPermission state); + + /** + * Prompts the user if they want to grant permission for the given principal and + * for the given target. + * + * @param prin - is either certificate principal or codebase principal + * @param target - is NS_ALL_PRIVILEGES. + * @param result - is the permission user has given for the given principal and + * target + */ + NS_IMETHOD + AskPermission(nsIPrincipal* prin, nsITarget* target, nsPermission *result); + + //////////////////////////////////////////////////////////////////////////// + // from nsCCapsManager: + + nsCCapsManager(nsISupports *aOuter); + virtual ~nsCCapsManager(void); + NS_METHOD + GetNSPrincipal(nsIPrincipal* pNSIPrincipal, nsPrincipal **ppNSPRincipal); + + nsPermission + ConvertPrivilegeToPermission(nsPrivilege *pNSPrivilege); + void + SetSystemPrivilegeManager(); + + +protected: + nsPrivilegeManager *m_pNSPrivilegeManager; +}; + +#endif // nsCCapsManager_h___ diff --git a/mozilla/caps/include/nsCCapsManagerFactory.h b/mozilla/caps/include/nsCCapsManagerFactory.h new file mode 100644 index 00000000000..e5369f5f8be --- /dev/null +++ b/mozilla/caps/include/nsCCapsManagerFactory.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsCCapsManagerFactory_h___ +#define nsCCapsManagerFactory_h___ + +#include "nsISupports.h" +#include "nsIFactory.h" + +class nsCCapsManagerFactory : public nsIFactory { +public: + //////////////////////////////////////////////////////////////////////////// + // from nsISupports and AggregatedQueryInterface: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIFactory: + + NS_IMETHOD + CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult); + + NS_IMETHOD + LockFactory(PRBool aLock); + + + //////////////////////////////////////////////////////////////////////////// + // from nsCCapsManagerFactory: + + nsCCapsManagerFactory(void); + virtual ~nsCCapsManagerFactory(void); + +protected: + static nsIFactory *m_pNSIFactory; +}; + +#endif // nsCCapsManagerFactory_h___ diff --git a/mozilla/caps/include/nsCCertPrincipal.h b/mozilla/caps/include/nsCCertPrincipal.h new file mode 100644 index 00000000000..73bd8cf25cb --- /dev/null +++ b/mozilla/caps/include/nsCCertPrincipal.h @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsCCertPrincipal_h___ +#define nsCCertPrincipal_h___ + +#include "nsICertPrincipal.h" +#include "nsPrincipal.h" + +class nsCCertPrincipal : public nsICertPrincipal { +public: + //////////////////////////////////////////////////////////////////////////// + // from nsISupports: + + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIPrincipal: + + NS_IMETHOD + IsTrusted(char* scope, PRBool *pbIsTrusted); + + //////////////////////////////////////////////////////////////////////////// + // from nsICertPrincipal: + + /** + * returns the certificate's data that is passes in via Initialize method. + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + */ + NS_IMETHOD + GetCertData(unsigned char **certByteData, PRUint32 *certByteDataSize); + + /** + * Returns the public key of the certificate. + * + * @param publicKey - the Public Key data will be returned in this field. + * @param publicKeySize - the length of public key data is returned in this + * parameter. + */ + NS_IMETHOD + GetPublicKey(unsigned char **publicKey, PRUint32 *publicKeySize); + + /** + * Returns the company name of the ceritificate (OU etc parameters of certificate) + * + * @param result - the certificate details about the signer. + */ + NS_IMETHOD + GetCompanyName(const char **ppCompanyName); + + /** + * Returns the certificate issuer's data (OU etc parameters of certificate) + * + * @param result - the details about the issuer + */ + NS_IMETHOD + GetCertificateAuthority(const char **ppCertAuthority); + + /** + * Returns the serial number of certificate + * + * @param result - Returns the serial number of certificate + */ + NS_IMETHOD + GetSerialNumber(const char **ppSerialNumber); + + /** + * Returns the expiration date of certificate + * + * @param result - Returns the expiration date of certificate + */ + NS_IMETHOD + GetExpirationDate(const char **ppExpDate); + + /** + * Returns the finger print of certificate + * + * @param result - Returns the finger print of certificate + */ + NS_IMETHOD + GetFingerPrint(const char **ppFingerPrint); + + //////////////////////////////////////////////////////////////////////////// + // from nsCCertPrincipal: + nsCCertPrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, nsresult *result); + virtual ~nsCCertPrincipal(void); + nsPrincipal *GetPeer(void); + +protected: + nsPrincipal *m_pNSPrincipal; +}; + +#endif // nsCCertPrincipal_h___ diff --git a/mozilla/caps/include/nsCCodeSourcePrincipal.h b/mozilla/caps/include/nsCCodeSourcePrincipal.h new file mode 100644 index 00000000000..5de015f664a --- /dev/null +++ b/mozilla/caps/include/nsCCodeSourcePrincipal.h @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsCCodeSourcePrincipal_h___ +#define nsCCodeSourcePrincipal_h___ + +#include "nsICodeSourcePrincipal.h" +#include "nsPrincipal.h" + +class nsCCodeSourcePrincipal : public nsICodeSourcePrincipal { +public: + //////////////////////////////////////////////////////////////////////////// + // from nsISupports: + + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIPrincipal: + + NS_IMETHOD + IsTrusted(char* scope, PRBool *pbIsTrusted); + + //////////////////////////////////////////////////////////////////////////// + // from nsICodeSourcePrincipal: + + /** + * returns the certificate's data that is passes in via Initialize method. + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + */ + NS_IMETHOD + GetCertData(unsigned char **certByteData, PRUint32 *certByteDataSize); + + /** + * Returns the public key of the certificate. + * + * @param publicKey - the Public Key data will be returned in this field. + * @param publicKeySize - the length of public key data is returned in this + * parameter. + */ + NS_IMETHOD + GetPublicKey(unsigned char **publicKey, PRUint32 *publicKeySize); + + /** + * Returns the company name of the ceritificate (OU etc parameters of certificate) + * + * @param result - the certificate details about the signer. + */ + NS_IMETHOD + GetCompanyName(const char **ppCompanyName); + + /** + * Returns the certificate issuer's data (OU etc parameters of certificate) + * + * @param result - the details about the issuer + */ + NS_IMETHOD + GetCertificateAuthority(const char **ppCertAuthority); + + /** + * Returns the serial number of certificate + * + * @param result - Returns the serial number of certificate + */ + NS_IMETHOD + GetSerialNumber(const char **ppSerialNumber); + + /** + * Returns the expiration date of certificate + * + * @param result - Returns the expiration date of certificate + */ + NS_IMETHOD + GetExpirationDate(const char **ppExpDate); + + /** + * Returns the finger print of certificate + * + * @param result - Returns the finger print of certificate + */ + NS_IMETHOD + GetFingerPrint(const char **ppFingerPrint); + + /** + * Returns the codebase URL of the principal. + * + * @param result - the resulting codebase URL + */ + NS_IMETHOD + GetURL(const char **ppCodeBaseURL); + + //////////////////////////////////////////////////////////////////////////// + // from nsCCodeSourcePrincipal: + nsCCodeSourcePrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, const char *codebaseURL, nsresult *result); + virtual ~nsCCodeSourcePrincipal(void); + +protected: + nsICertPrincipal *m_pNSICertPrincipal; + nsICodebasePrincipal *m_pNSICodebasePrincipal; +}; + +#endif // nsCCodeSourcePrincipal_h___ diff --git a/mozilla/caps/include/nsCCodebasePrincipal.h b/mozilla/caps/include/nsCCodebasePrincipal.h new file mode 100644 index 00000000000..78871f2d602 --- /dev/null +++ b/mozilla/caps/include/nsCCodebasePrincipal.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsCCodebasePrincipal_h___ +#define nsCCodebasePrincipal_h___ + +#include "nsICodebasePrincipal.h" +#include "nsPrincipal.h" + +class nsCCodebasePrincipal : public nsICodebasePrincipal { +public: + //////////////////////////////////////////////////////////////////////////// + // from nsISupports: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIPrincipal: + + NS_IMETHOD + IsTrusted(char* scope, PRBool *pbIsTrusted); + + + /////////////////////////////////////////////////////////////////////////// + // from nsICodebasePrincipal: + + /** + * Returns the codebase URL of the principal. + * + * @param result - the resulting codebase URL + */ + NS_IMETHOD + GetURL(const char **ppCodeBaseURL); + + //////////////////////////////////////////////////////////////////////////// + // from nsCCodebasePrincipal: + + nsCCodebasePrincipal(const char *codebaseURL, nsresult *result); + virtual ~nsCCodebasePrincipal(void); + nsPrincipal *GetPeer(void); + +protected: + nsPrincipal *m_pNSPrincipal; +}; + +#endif // nsCCodebasePrincipal_h___ diff --git a/mozilla/caps/makefile.win b/mozilla/caps/makefile.win index 71fe0d715b8..7bb5c53142e 100644 --- a/mozilla/caps/makefile.win +++ b/mozilla/caps/makefile.win @@ -37,7 +37,7 @@ DEPTH=.. #// DIRS - There are subdirectories to process #// #//------------------------------------------------------------------------ -DIRS=include src +DIRS= public include src #//------------------------------------------------------------------------ #// diff --git a/mozilla/caps/public/Makefile b/mozilla/caps/public/Makefile new file mode 100644 index 00000000000..30c2f1ebedb --- /dev/null +++ b/mozilla/caps/public/Makefile @@ -0,0 +1,30 @@ +#!gmake +# 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. + +MODULE = caps + +DEPTH = ../.. + +EXPORTS = nsIPrincipal.h \ + nsICodebasePrincipal.h \ + nsICertPrincipal.h \ + nsICapsManager.h \ + nsICodeSourcePrincipal.h + + + +include $(DEPTH)/config/rules.mk + diff --git a/mozilla/caps/public/Makefile.in b/mozilla/caps/public/Makefile.in new file mode 100644 index 00000000000..6d1912fe4ba --- /dev/null +++ b/mozilla/caps/public/Makefile.in @@ -0,0 +1,35 @@ +#!gmake +# 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. + +MODULE = caps + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +EXPORTS = nsIPrincipal.h \ + nsICodebasePrincipal.h \ + nsICertPrincipal.h \ + nsICapsManager.h \ + nsICodeSourcePrincipal.h + +EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/caps/public/makefile.win b/mozilla/caps/public/makefile.win new file mode 100644 index 00000000000..06241458316 --- /dev/null +++ b/mozilla/caps/public/makefile.win @@ -0,0 +1,40 @@ +#!nmake +# +# 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. + + +IGNORE_MANIFEST=1 + +#//------------------------------------------------------------------------ +#// +#// Makefile to install CAPS/INCLUDE header files into the distribution +#// directory. +#// +#//------------------------------------------------------------------------ + + +MODULE=caps +DEPTH=..\.. +EXPORTS= \ + nsIPrincipal.h \ + nsICodebasePrincipal.h \ + nsICertPrincipal.h \ + nsICapsManager.h \ + nsICodeSourcePrincipal.h + + +include <$(DEPTH)/config/rules.mak> + diff --git a/mozilla/caps/public/nsICapsManager.h b/mozilla/caps/public/nsICapsManager.h new file mode 100644 index 00000000000..c1062794c7e --- /dev/null +++ b/mozilla/caps/public/nsICapsManager.h @@ -0,0 +1,131 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsICapsManager_h___ +#define nsICapsManager_h___ + +#include "nsISupports.h" +#include "nsIFactory.h" +#include "nsIPrincipal.h" + +class nsITarget; + +#define NS_ALL_PRIVILEGES ((nsITarget*)NULL) + +enum nsPermission { + nsPermission_Unknown, + nsPermission_AllowedSession, + nsPermission_DeniedSession, + nsPermission_AllowedForever, + nsPermission_DeniedForever +}; + +/** + * The nsICapsManager interface is used to construct and manage principals. + * Principals are either certificates, or codebase principals. To construct + * a principal, QueryInterface on nsIPluginManager and then call CreateCertPrincipal + * or CreateCodebasePrincipal on the returned nsICapsManager. + * Once a principal is obtained, it can be passed to the nsICapsManager's + * SetPermission operations. + */ +class nsICapsManager : public nsISupports { +public: + /** + * Intializes the principal object with the codebase URL. + * + * @param codebaseURL - the codebase URL + */ + NS_IMETHOD + CreateCodebasePrincipal(const char *codebaseURL, nsIPrincipal** prin) = 0; + + /** + * Initializes the Certificate principal with the certificate data. I am thinking + * Certificate data should contain all the data about the certificate, + * ie. the signer and the certificate chain. + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + */ + NS_IMETHOD + CreateCertPrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, nsIPrincipal** prin) = 0; + + + /** + * Creates a CodeSourcePrincipal, which has both nsICodebasePrincipal + * and nsICertPrincipal + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + * @param codebaseURL - the codebase URL + */ + NS_IMETHOD + CreateCodeSourcePrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, const char *codebaseURL, nsIPrincipal** prin) = 0; + + + /** + * Returns the permission for given principal and target + * + * @param prin - is either certificate principal or codebase principal + * @param target - is NS_ALL_PRIVILEGES. + * @param state - the return value is passed in this parameter. + */ + NS_IMETHOD + GetPermission(nsIPrincipal* prin, nsITarget* target, nsPermission *state) = 0; + + /** + * Set the permission state for given principal and target. This wouldn't + * prompt the end user with UI. + * + * @param prin - is either certificate principal or codebase principal + * @param target - is NS_ALL_PRIVILEGES. + * @param state - is permisson state that should be set for the given prin + * and target parameters. + */ + NS_IMETHOD + SetPermission(nsIPrincipal* prin, nsITarget* target, nsPermission state) = 0; + + /** + * Prompts the user if they want to grant permission for the given principal and + * for the given target. + * + * @param prin - is either certificate principal or codebase principal + * @param target - is NS_ALL_PRIVILEGES. + * @param result - is the permission user has given for the given principal and + * target + */ + NS_IMETHOD + AskPermission(nsIPrincipal* prin, nsITarget* target, nsPermission *result) = 0; + +}; + +#define NS_ICAPSMANAGER_IID \ +{ /* dc7d0bb0-25e1-11d2-8160-006008119d7a */ \ + 0xdc7d0bb0, \ + 0x25e1, \ + 0x11d2, \ + {0x81, 0x60, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +#define NS_CCAPSMANAGER_CID \ +{ /* fd347500-307f-11d2-97f0-00805f8a28d0 */ \ + 0xfd347500, \ + 0x307f, \ + 0x11d2, \ + {0x97, 0xf0, 0x00, 0x80, 0x5f, 0x8a, 0x28, 0xd0} \ +}; +#endif // nsICapsManager_h___ diff --git a/mozilla/caps/public/nsICertPrincipal.h b/mozilla/caps/public/nsICertPrincipal.h new file mode 100644 index 00000000000..75683f7586d --- /dev/null +++ b/mozilla/caps/public/nsICertPrincipal.h @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsICertPrincipal_h___ +#define nsICertPrincipal_h___ + +#include "nsIPrincipal.h" + +enum { nsFingerPrint_Size = 16 }; +typedef unsigned char nsFingerPrint[nsFingerPrint_Size]; + +class nsICertPrincipal : public nsIPrincipal { +public: + + /** + * returns the certificate's data that is passes in via Initialize method. + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + */ + NS_IMETHOD + GetCertData(unsigned char **certByteData, PRUint32 *certByteDataSize) = 0; + + /** + * Returns the public key of the certificate. + * + * @param publicKey - the Public Key data will be returned in this field. + * @param publicKeySize - the length of public key data is returned in this + * parameter. + */ + NS_IMETHOD + GetPublicKey(unsigned char **publicKey, PRUint32 *publicKeySize) = 0; + + /** + * Returns the company name of the ceritificate (OU etc parameters of certificate) + * + * @param result - the certificate details about the signer. + */ + NS_IMETHOD + GetCompanyName(const char **ppCompanyName) = 0; + + /** + * Returns the certificate issuer's data (OU etc parameters of certificate) + * + * @param result - the details about the issuer + */ + NS_IMETHOD + GetCertificateAuthority(const char **ppCertAuthority) = 0; + + /** + * Returns the serial number of certificate + * + * @param result - Returns the serial number of certificate + */ + NS_IMETHOD + GetSerialNumber(const char **ppSerialNumber) = 0; + + /** + * Returns the expiration date of certificate + * + * @param result - Returns the expiration date of certificate + */ + NS_IMETHOD + GetExpirationDate(const char **ppExpDate) = 0; + + /** + * Returns the finger print of certificate + * + * @param result - Returns the finger print of certificate + */ + NS_IMETHOD + GetFingerPrint(const char **ppFingerPrint) = 0; + +}; + +#define NS_ICERTPRINCIPAL_IID \ +{ /* ebfefcd0-25e1-11d2-8160-006008119d7a */ \ + 0xebfefcd0, \ + 0x25e1, \ + 0x11d2, \ + {0x81, 0x60, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +#endif // nsICertPrincipal_h___ diff --git a/mozilla/caps/public/nsICodeSourcePrincipal.h b/mozilla/caps/public/nsICodeSourcePrincipal.h new file mode 100644 index 00000000000..8f237e557ae --- /dev/null +++ b/mozilla/caps/public/nsICodeSourcePrincipal.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsICodeSourcePrincipal_h___ +#define nsICodeSourcePrincipal_h___ + +#include "nsIPrincipal.h" +#include "nsICertPrincipal.h" +#include "nsICodebasePrincipal.h" + +class nsICodeSourcePrincipal : public nsIPrincipal { + + /** + * returns the certificate's data that is passes in via Initialize method. + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + */ + NS_IMETHOD + GetCertData(unsigned char **certByteData, PRUint32 *certByteDataSize) = 0; + + /** + * Returns the public key of the certificate. + * + * @param publicKey - the Public Key data will be returned in this field. + * @param publicKeySize - the length of public key data is returned in this + * parameter. + */ + NS_IMETHOD + GetPublicKey(unsigned char **publicKey, PRUint32 *publicKeySize) = 0; + + /** + * Returns the company name of the ceritificate (OU etc parameters of certificate) + * + * @param result - the certificate details about the signer. + */ + NS_IMETHOD + GetCompanyName(const char **ppCompanyName) = 0; + + /** + * Returns the certificate issuer's data (OU etc parameters of certificate) + * + * @param result - the details about the issuer + */ + NS_IMETHOD + GetCertificateAuthority(const char **ppCertAuthority) = 0; + + /** + * Returns the serial number of certificate + * + * @param result - Returns the serial number of certificate + */ + NS_IMETHOD + GetSerialNumber(const char **ppSerialNumber) = 0; + + /** + * Returns the expiration date of certificate + * + * @param result - Returns the expiration date of certificate + */ + NS_IMETHOD + GetExpirationDate(const char **ppExpDate) = 0; + + /** + * Returns the finger print of certificate + * + * @param result - Returns the finger print of certificate + */ + NS_IMETHOD + GetFingerPrint(const char **ppFingerPrint) = 0; + + + /** + * Returns the codebase URL of the principal. + * + * @param result - the resulting codebase URL + */ + NS_IMETHOD + GetURL(const char **ppCodeBaseURL) = 0; +}; + +#define NS_ICCODESOURCEPRINCIPAL_IID \ +{ /* 68cb0890-436a-11d2-b940-00805f52351a */ \ + 0x68cb0890, \ + 0x436a, \ + 0x11d2, \ + {0xb9, 0x40, 0x00, 0x80, 0x5f, 0x52, 0x35, 0x1a} \ +} + +#endif // nsICodeSourcePrincipal_h___ diff --git a/mozilla/caps/public/nsICodebasePrincipal.h b/mozilla/caps/public/nsICodebasePrincipal.h new file mode 100644 index 00000000000..4750b9beffd --- /dev/null +++ b/mozilla/caps/public/nsICodebasePrincipal.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsICodebasePrincipal_h___ +#define nsICodebasePrincipal_h___ + +#include "nsIPrincipal.h" + +class nsICodebasePrincipal : public nsIPrincipal { +public: + + /** + * Returns the codebase URL of the principal. + * + * @param result - the resulting codebase URL + */ + NS_IMETHOD + GetURL(const char **ppCodeBaseURL) = 0; + +}; + +#define NS_ICODEBASEPRINCIPAL_IID \ +{ /* c29fe440-25e1-11d2-8160-006008119d7a */ \ + 0xc29fe440, \ + 0x25e1, \ + 0x11d2, \ + {0x81, 0x60, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +#endif // nsICodebasePrincipal_h___ diff --git a/mozilla/caps/public/nsIPrincipal.h b/mozilla/caps/public/nsIPrincipal.h new file mode 100644 index 00000000000..06d45886815 --- /dev/null +++ b/mozilla/caps/public/nsIPrincipal.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#ifndef nsIPrincipal_h___ +#define nsIPrincipal_h___ + +#include "nsISupports.h" + +class nsIPrincipal : public nsISupports { +public: + + /** + * Determines whether or not the Principal is trusted or not. + * + * If it is a Certificate Principal, then it will validate + * by checking whether the given certificate chain can be + * successfully validated using trusted certificate information + * in Netscape's certificate database. + * + * If it is a codebase Principal, this function will return FALSE, + * unless the following preference is set. The following + * preference would allow developers to test their applets without + * signing. + * + * user_pref("signed.applets.codebase_principal_support", true); + * + * + * @param scope - the individual parameter of the certificate that + * needs to be verified. If NULL is passed, it will + * verify the whole certificate chain. + * @param result - is PR_TRUE if the given certificate chain is trusted, + * otherwise PR_FALSE. + */ + NS_IMETHOD + IsTrusted(char* scope, PRBool *pbIsTrusted) = 0; + +}; + +#define NS_IPRINCIPAL_IID \ +{ /* ff9313d0-25e1-11d2-8160-006008119d7a */ \ + 0xff9313d0, \ + 0x25e1, \ + 0x11d2, \ + {0x81, 0x60, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +#endif // nsIPrincipal_h___ diff --git a/mozilla/caps/src/Makefile b/mozilla/caps/src/Makefile index 5316a0d7469..84c599667dc 100755 --- a/mozilla/caps/src/Makefile +++ b/mozilla/caps/src/Makefile @@ -34,6 +34,11 @@ CPPSRCS = \ nsUserTarget.cpp \ admin.cpp \ nsCaps.cpp \ + nsCCapsManager.cpp \ + nsCCertPrincipal.cpp \ + nsCCodebasePrincipal.cpp \ + nsCCapsManagerFactory.cpp \ + nsCCodeSourcePrincipal.cpp \ $(NULL) REQUIRES = nspr xpcom security layer js jar zlib pref img util rdf caps @@ -46,5 +51,6 @@ CSRCS = \ include $(DEPTH)/config/rules.mk -INCLUDES += -I$(DEPTH)/include +INCLUDES += -I$(DEPTH)/include \ + -I$(PUBLIC)/public \ diff --git a/mozilla/caps/src/makefile.win b/mozilla/caps/src/makefile.win index e8f81f7f8e9..45d77dcc6f0 100755 --- a/mozilla/caps/src/makefile.win +++ b/mozilla/caps/src/makefile.win @@ -64,6 +64,11 @@ OBJS= \ .\$(OBJDIR)\nsUserTarget.obj \ .\$(OBJDIR)\admin.obj \ .\$(OBJDIR)\nsCaps.obj \ + .\$(OBJDIR)\nsCCapsManager.obj \ + .\$(OBJDIR)\nsCCertPrincipal.obj \ + .\$(OBJDIR)\nsCCodebasePrincipal.obj \ + .\$(OBJDIR)\nsCCapsManagerFactory.obj \ + .\$(OBJDIR)\nsCCodeSourcePrincipal.obj \ $(NULL) @@ -101,6 +106,7 @@ LINCS= $(LINCS) \ -I$(DEPTH)\lib\libstyle \ -I$(PUBLIC)\rdf \ -I$(PUBLIC)\caps \ + -I$(PUBLIC)\public \ $(NULL) #//------------------------------------------------------------------------ diff --git a/mozilla/caps/src/nsCCapsManager.cpp b/mozilla/caps/src/nsCCapsManager.cpp new file mode 100644 index 00000000000..d4c9abae9e5 --- /dev/null +++ b/mozilla/caps/src/nsCCapsManager.cpp @@ -0,0 +1,257 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ +#include "nsRepository.h" +#include "nsCapsEnums.h" +#include "nsCCapsManager.h" +#include "nsICodebasePrincipal.h" +#include "nsICertPrincipal.h" +#include "nsCCodebasePrincipal.h" +#include "nsCCertPrincipal.h" +#include "nsCCodeSourcePrincipal.h" + +static NS_DEFINE_CID(kCCapsManagerCID, NS_CCAPSMANAGER_CID); +static NS_DEFINE_IID(kICapsManagerIID, NS_ICAPSMANAGER_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + + +//////////////////////////////////////////////////////////////////////////// +// from nsISupports and AggregatedQueryInterface: + +// Thes macro expands to the aggregated query interface scheme. + +NS_IMPL_AGGREGATED(nsCCapsManager); + +NS_METHOD +nsCCapsManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (aIID.Equals(kISupportsIID)) { + *aInstancePtr = GetInner(); + AddRef(); + return NS_OK; + } + if (aIID.Equals(kICapsManagerIID)) { + *aInstancePtr = this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + + + +//////////////////////////////////////////////////////////////////////////// +// from nsICapsManager: + +NS_METHOD +nsCCapsManager::CreateCodebasePrincipal(const char *codebaseURL, nsIPrincipal** prin) +{ + nsresult result = NS_OK; + nsCCodebasePrincipal *pNSCCodebasePrincipal = new nsCCodebasePrincipal(codebaseURL, &result); + if (pNSCCodebasePrincipal == NULL) + { + return NS_ERROR_OUT_OF_MEMORY; + } + pNSCCodebasePrincipal->AddRef(); + *prin = (nsIPrincipal *)pNSCCodebasePrincipal; + return result; +} + +NS_METHOD +nsCCapsManager::CreateCertPrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, nsIPrincipal** prin) +{ + nsresult result = NS_OK; + nsCCertPrincipal *pNSCCertPrincipal = new nsCCertPrincipal(certByteData, certByteDataSize, &result); + if (pNSCCertPrincipal == NULL) + { + return NS_ERROR_OUT_OF_MEMORY; + } + pNSCCertPrincipal->AddRef(); + *prin = (nsIPrincipal *)pNSCCertPrincipal; + return NS_OK; +} + +NS_METHOD +nsCCapsManager::CreateCodeSourcePrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, const char *codebaseURL, nsIPrincipal** prin) +{ + nsresult result = NS_OK; + nsCCodeSourcePrincipal *pNSCCodeSourcePrincipal = new nsCCodeSourcePrincipal(certByteData, certByteDataSize, codebaseURL, &result); + if (pNSCCodeSourcePrincipal == NULL) + { + return NS_ERROR_OUT_OF_MEMORY; + } + pNSCCodeSourcePrincipal->AddRef(); + *prin = (nsIPrincipal *)pNSCCodeSourcePrincipal; + return NS_OK; +} + + + +/** +* Returns the permission for given principal and target +* +* @param prin - is either certificate principal or codebase principal +* @param target - is NS_ALL_PRIVILEGES. +* @param state - the return value is passed in this parameter. +*/ +NS_METHOD +nsCCapsManager::GetPermission(nsIPrincipal* pNSIPrincipal, nsITarget* ignoreTarget, nsPermission *state) +{ + nsTarget *target = nsTarget::findTarget("AllPermission"); + nsresult result = NS_OK; + if( target == NULL ) + { + *state = nsPermission_Unknown; + return NS_OK; + } + if (m_pNSPrivilegeManager != NULL) + { + nsPrincipal *pNSPrinicipal = NULL; + result = GetNSPrincipal(pNSIPrincipal, &pNSPrinicipal); + if( result != NS_OK) + { + return result; + } + + *state = ConvertPrivilegeToPermission(m_pNSPrivilegeManager->getPrincipalPrivilege(target, pNSPrinicipal, NULL)); + } + return NS_OK; +} + +/** +* Set the permission state for given principal and target. This wouldn't +* prompt the end user with UI. +* +* @param prin - is either certificate principal or codebase principal +* @param target - is NS_ALL_PRIVILEGES. +* @param state - is permisson state that should be set for the given prin +* and target parameters. +*/ +NS_METHOD +nsCCapsManager::SetPermission(nsIPrincipal* prin, nsITarget* target, nsPermission state) +{ + // XXX sudu/raman: fix it. + PR_ASSERT(PR_FALSE); + return NS_OK; +} + +/** +* Prompts the user if they want to grant permission for the given principal and +* for the given target. +* +* @param prin - is either certificate principal or codebase principal +* @param target - is NS_ALL_PRIVILEGES. +* @param result - is the permission user has given for the given principal and +* target +*/ +NS_METHOD +nsCCapsManager::AskPermission(nsIPrincipal* pNSIPrincipal, nsITarget* ignoreTarget, nsPermission *state) +{ + nsTarget *target = nsTarget::findTarget("AllPermission"); + nsresult result = NS_OK; + if( target == NULL ) + { + *state = nsPermission_Unknown; + return NS_OK; + } + if (m_pNSPrivilegeManager != NULL) + { + nsPrincipal *pNSPrinicipal = NULL; + result = GetNSPrincipal(pNSIPrincipal, &pNSPrinicipal); + if( result != NS_OK) + { + return result; + } + // XXX raman: Create AskPermission method. + m_pNSPrivilegeManager->enablePrivilege(pNSPrinicipal,target, 0); + *state = ConvertPrivilegeToPermission(m_pNSPrivilegeManager->getPrincipalPrivilege(target, pNSPrinicipal, NULL)); + } + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////// +// from nsCCapsManager: + +nsCCapsManager::nsCCapsManager(nsISupports *aOuter) +{ + NS_INIT_AGGREGATED(aOuter); + m_pNSPrivilegeManager = new nsPrivilegeManager(); +} + +nsCCapsManager::~nsCCapsManager() +{ +} + +NS_METHOD +nsCCapsManager::GetNSPrincipal(nsIPrincipal* pNSIPrincipal, nsPrincipal **ppNSPRincipal) +{ + nsISupports *pNSISupports = NULL; + nsPrincipal *pNSPrinicipal = NULL; + + NS_DEFINE_IID(kICertPrincipalIID, NS_ICERTPRINCIPAL_IID); + NS_DEFINE_IID(kICodebasePrincipalIID, NS_ICODEBASEPRINCIPAL_IID); + if (pNSIPrincipal->QueryInterface(kICertPrincipalIID, + (void**)&pNSISupports) == NS_OK) + { + nsCCertPrincipal *pNSCCertPrincipal = (nsCCertPrincipal *)pNSIPrincipal; + pNSPrinicipal = pNSCCertPrincipal->GetPeer(); + pNSCCertPrincipal->Release(); + } + else + if (pNSIPrincipal->QueryInterface(kICodebasePrincipalIID, + (void**)&pNSISupports) == NS_OK) + { + nsCCodebasePrincipal *pNSCCodebasePrincipal = (nsCCodebasePrincipal *)pNSIPrincipal; + pNSPrinicipal = pNSCCodebasePrincipal->GetPeer(); + pNSCCodebasePrincipal->Release(); + } + else + { + return NS_ERROR_NO_INTERFACE; + } + *ppNSPRincipal = pNSPrinicipal; + return NS_OK; +} + + +nsPermission +nsCCapsManager::ConvertPrivilegeToPermission(nsPrivilege *pNSPrivilege) +{ + if(pNSPrivilege->isAllowedForever()) + return nsPermission_AllowedForever; + if(pNSPrivilege->isForbiddenForever()) + return nsPermission_AllowedForever; + if(pNSPrivilege->isAllowed()) + return nsPermission_AllowedSession; + if(pNSPrivilege->isForbidden()) + return nsPermission_DeniedSession; + + return nsPermission_Unknown; +} + +void +nsCCapsManager::SetSystemPrivilegeManager() +{ + nsPrivilegeManager *pNSPrivilegeManager = nsPrivilegeManager::getPrivilegeManager(); + if ( (m_pNSPrivilegeManager != NULL ) + && (m_pNSPrivilegeManager != pNSPrivilegeManager) + ) + { + delete m_pNSPrivilegeManager; + m_pNSPrivilegeManager = pNSPrivilegeManager; + } +} diff --git a/mozilla/caps/src/nsCCapsManagerFactory.cpp b/mozilla/caps/src/nsCCapsManagerFactory.cpp new file mode 100644 index 00000000000..1bc75e56a66 --- /dev/null +++ b/mozilla/caps/src/nsCCapsManagerFactory.cpp @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ +#include "prtypes.h" +#include "nspr.h" +#include "prmem.h" +#include "prmon.h" +#include "prlog.h" + +#include "nsCCapsManager.h" +#include "nsCCapsManagerFactory.h" +#include "nsRepository.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + +nsIFactory *nsCCapsManagerFactory::m_pNSIFactory = NULL; + +//////////////////////////////////////////////////////////////////////////// +// from nsISupports + +NS_METHOD +nsCCapsManagerFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + PR_ASSERT(NULL != aInstancePtr); + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIFactoryIID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*) this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +NS_IMPL_ADDREF(nsCCapsManagerFactory) +NS_IMPL_RELEASE(nsCCapsManagerFactory) + + +//////////////////////////////////////////////////////////////////////////// +// from nsIFactory: + +NS_METHOD +nsCCapsManagerFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + nsCCapsManager *pNSCCapsManager = NULL; + *aResult = NULL; + + if (aOuter && !aIID.Equals(kISupportsIID)) + return NS_NOINTERFACE; // XXX right error? + pNSCCapsManager = new nsCCapsManager(aOuter); + if (pNSCCapsManager->QueryInterface(aIID, + (void**)aResult) != NS_OK) { + // then we're trying get a interface other than nsISupports and + // nsICapsManager + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_METHOD +nsCCapsManagerFactory::LockFactory(PRBool aLock) +{ + return NS_OK; +} + + + +//////////////////////////////////////////////////////////////////////////// +// from nsCCapsManagerFactory: + +nsCCapsManagerFactory::nsCCapsManagerFactory(void) +{ + if( m_pNSIFactory != NULL) + { + return; + } + + NS_INIT_REFCNT(); + nsresult err = NS_OK; + NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + + err = this->QueryInterface(kIFactoryIID, (void**)&m_pNSIFactory); + if ( (err == NS_OK) && (m_pNSIFactory != NULL) ) + { + NS_DEFINE_CID(kCCapsManagerCID, NS_CCAPSMANAGER_CID); + nsRepository::RegisterFactory(kCCapsManagerCID, m_pNSIFactory, + PR_FALSE); + } +} + +nsCCapsManagerFactory::~nsCCapsManagerFactory() +{ + if(mRefCnt == 0) + { + NS_DEFINE_CID(kCCapsManagerCID, NS_CCAPSMANAGER_CID); + nsRepository::UnregisterFactory(kCCapsManagerCID, (nsIFactory *)m_pNSIFactory); + + } +} + + diff --git a/mozilla/caps/src/nsCCertPrincipal.cpp b/mozilla/caps/src/nsCCertPrincipal.cpp new file mode 100644 index 00000000000..93b4666d550 --- /dev/null +++ b/mozilla/caps/src/nsCCertPrincipal.cpp @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#include "nsCCertPrincipal.h" +#include "nsPrincipal.h" + +NS_DEFINE_IID(kICertPrincipalIID, NS_ICERTPRINCIPAL_IID); + +//////////////////////////////////////////////////////////////////////////// +// from nsISupports: + +// These macros produce simple version of QueryInterface and AddRef. +// See the nsISupports.h header file for DETAILS. + +NS_IMPL_ADDREF(nsCCertPrincipal) +NS_IMPL_RELEASE(nsCCertPrincipal) +NS_IMPL_QUERY_INTERFACE(nsCCertPrincipal, kICertPrincipalIID); + +//////////////////////////////////////////////////////////////////////////// +// from nsIPrincipal: + +NS_METHOD +nsCCertPrincipal::IsTrusted(char* scope, PRBool *pbIsTrusted) +{ + if(m_pNSPrincipal == NULL) + { + *pbIsTrusted = PR_FALSE; + return NS_ERROR_ILLEGAL_VALUE; + } + *pbIsTrusted = m_pNSPrincipal->isSecurePrincipal(); + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////// +// from nsICertPrincipal: + +/** + * returns the certificate's data that is passes in via Initialize method. + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + */ +NS_METHOD +nsCCertPrincipal::GetCertData(unsigned char **certByteData, PRUint32 *certByteDataSize) +{ + if(m_pNSPrincipal == NULL) + { + *certByteData = NULL; + *certByteDataSize = 0; + return NS_ERROR_ILLEGAL_VALUE; + } + *certByteData = (unsigned char *)m_pNSPrincipal->getKey(); + *certByteDataSize = m_pNSPrincipal->getKeyLength(); + + return NS_OK; +} + +/** + * Returns the public key of the certificate. + * + * @param publicKey - the Public Key data will be returned in this field. + * @param publicKeySize - the length of public key data is returned in this + * parameter. + */ +NS_METHOD +nsCCertPrincipal::GetPublicKey(unsigned char **publicKey, PRUint32 *publicKeySize) +{ + // =-= sudu/raman: fix it. + PR_ASSERT(PR_FALSE); + return NS_OK; +} + +/** + * Returns the company name of the ceritificate (OU etc parameters of certificate) + * + * @param result - the certificate details about the signer. + */ +NS_METHOD +nsCCertPrincipal::GetCompanyName(const char **ppCompanyName) +{ + if(m_pNSPrincipal == NULL) + { + *ppCompanyName = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + *ppCompanyName = m_pNSPrincipal->getCompanyName(); + return NS_OK; +} + +/** + * Returns the certificate issuer's data (OU etc parameters of certificate) + * + * @param result - the details about the issuer + */ +NS_METHOD +nsCCertPrincipal::GetCertificateAuthority(const char **ppCertAuthority) +{ + if(m_pNSPrincipal == NULL) + { + *ppCertAuthority = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + *ppCertAuthority = m_pNSPrincipal->getSecAuth(); + return NS_OK; +} + +/** + * Returns the serial number of certificate + * + * @param result - Returns the serial number of certificate + */ +NS_METHOD +nsCCertPrincipal::GetSerialNumber(const char **ppSerialNumber) +{ + if(m_pNSPrincipal == NULL) + { + *ppSerialNumber = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + *ppSerialNumber = m_pNSPrincipal->getSerialNo(); + return NS_OK; +} + +/** + * Returns the expiration date of certificate + * + * @param result - Returns the expiration date of certificate + */ +NS_METHOD +nsCCertPrincipal::GetExpirationDate(const char **ppExpDate) +{ + if(m_pNSPrincipal == NULL) + { + *ppExpDate = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + *ppExpDate = m_pNSPrincipal->getExpDate(); + return NS_OK; +} + +/** + * Returns the finger print of certificate + * + * @param result - Returns the finger print of certificate + */ +NS_METHOD +nsCCertPrincipal::GetFingerPrint(const char **ppFingerPrint) +{ + if(m_pNSPrincipal == NULL) + { + *ppFingerPrint = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + *ppFingerPrint = m_pNSPrincipal->getFingerPrint(); + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////// +// from nsCCertPrincipal: + +nsCCertPrincipal::nsCCertPrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, nsresult *result) +{ + // XXX raman fix the error condition. + m_pNSPrincipal = new nsPrincipal(nsPrincipalType_Cert, (void *)certByteData, certByteDataSize); + if(m_pNSPrincipal == NULL) + { + *result = NS_ERROR_OUT_OF_MEMORY; + return; + } + *result = NS_OK; +} + +nsCCertPrincipal::~nsCCertPrincipal(void) +{ + delete m_pNSPrincipal; +} + +nsPrincipal* +nsCCertPrincipal::GetPeer(void) +{ + return m_pNSPrincipal; +} + + diff --git a/mozilla/caps/src/nsCCodeSourcePrincipal.cpp b/mozilla/caps/src/nsCCodeSourcePrincipal.cpp new file mode 100644 index 00000000000..d7c09951759 --- /dev/null +++ b/mozilla/caps/src/nsCCodeSourcePrincipal.cpp @@ -0,0 +1,222 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#include "nsCCodeSourcePrincipal.h" +#include "nsCCodebasePrincipal.h" +#include "nsCCertPrincipal.h" +#include "nsPrincipal.h" + +NS_DEFINE_IID(kICodeSourcePrincipalIID, NS_ICCODESOURCEPRINCIPAL_IID); + +//////////////////////////////////////////////////////////////////////////// +// from nsISupports: + +// These macros produce simple version of QueryInterface and AddRef. +// See the nsISupports.h header file for DETAILS. + +NS_IMPL_ADDREF(nsCCodeSourcePrincipal) +NS_IMPL_RELEASE(nsCCodeSourcePrincipal) +NS_IMPL_QUERY_INTERFACE(nsCCodeSourcePrincipal, kICodeSourcePrincipalIID); + +//////////////////////////////////////////////////////////////////////////// +// from nsIPrincipal: + +NS_METHOD +nsCCodeSourcePrincipal::IsTrusted(char* scope, PRBool *pbIsTrusted) +{ + if(m_pNSICertPrincipal == NULL) + { + *pbIsTrusted = PR_FALSE; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICertPrincipal->IsTrusted(scope, pbIsTrusted); +} + +//////////////////////////////////////////////////////////////////////////// +// from nsICodeSourcePrincipal: + +/** + * returns the certificate's data that is passes in via Initialize method. + * + * @param certByteData - The ceritificate's byte array data including the chain. + * @param certByteDataSize - the length of certificate byte array. + */ +NS_METHOD +nsCCodeSourcePrincipal::GetCertData(unsigned char **certByteData, PRUint32 *certByteDataSize) +{ + if(m_pNSICertPrincipal == NULL) + { + *certByteData = NULL; + *certByteDataSize = 0; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICertPrincipal->GetCertData(certByteData, certByteDataSize); +} + +/** + * Returns the public key of the certificate. + * + * @param publicKey - the Public Key data will be returned in this field. + * @param publicKeySize - the length of public key data is returned in this + * parameter. + */ +NS_METHOD +nsCCodeSourcePrincipal::GetPublicKey(unsigned char **publicKey, PRUint32 *publicKeySize) +{ + if(m_pNSICertPrincipal == NULL) + { + *publicKey = NULL; + *publicKeySize = 0; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICertPrincipal->GetPublicKey(publicKey, publicKeySize); +} + +/** + * Returns the company name of the ceritificate (OU etc parameters of certificate) + * + * @param result - the certificate details about the signer. + */ +NS_METHOD +nsCCodeSourcePrincipal::GetCompanyName(const char **ppCompanyName) +{ + if(m_pNSICertPrincipal == NULL) + { + *ppCompanyName = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICertPrincipal->GetCompanyName(ppCompanyName); +} + +/** + * Returns the certificate issuer's data (OU etc parameters of certificate) + * + * @param result - the details about the issuer + */ +NS_METHOD +nsCCodeSourcePrincipal::GetCertificateAuthority(const char **ppCertAuthority) +{ + if(m_pNSICertPrincipal == NULL) + { + *ppCertAuthority = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICertPrincipal->GetCertificateAuthority(ppCertAuthority); +} + +/** + * Returns the serial number of certificate + * + * @param result - Returns the serial number of certificate + */ +NS_METHOD +nsCCodeSourcePrincipal::GetSerialNumber(const char **ppSerialNumber) +{ + if(m_pNSICertPrincipal == NULL) + { + *ppSerialNumber = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICertPrincipal->GetSerialNumber(ppSerialNumber); +} + +/** + * Returns the expiration date of certificate + * + * @param result - Returns the expiration date of certificate + */ +NS_METHOD +nsCCodeSourcePrincipal::GetExpirationDate(const char **ppExpDate) +{ + if(m_pNSICertPrincipal == NULL) + { + *ppExpDate = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICertPrincipal->GetExpirationDate(ppExpDate); +} + +/** + * Returns the finger print of certificate + * + * @param result - Returns the finger print of certificate + */ +NS_METHOD +nsCCodeSourcePrincipal::GetFingerPrint(const char **ppFingerPrint) +{ + if(m_pNSICertPrincipal == NULL) + { + *ppFingerPrint = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICertPrincipal->GetFingerPrint(ppFingerPrint); +} + + +/** + * Returns the codebase URL of the principal. + * + * @param result - the resulting codebase URL + */ +NS_METHOD +nsCCodeSourcePrincipal::GetURL(const char **ppCodeBaseURL) +{ + if(m_pNSICodebasePrincipal == NULL) + { + *ppCodeBaseURL = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + return m_pNSICodebasePrincipal->GetURL(ppCodeBaseURL); +} + + +//////////////////////////////////////////////////////////////////////////// +// from nsCCodeSourcePrincipal: + +nsCCodeSourcePrincipal::nsCCodeSourcePrincipal(const unsigned char *certByteData, PRUint32 certByteDataSize, const char *codebaseURL, nsresult *result) +{ + *result = NS_OK; + // XXX raman fix the error condition. + nsCCertPrincipal *pNSCCertPrincipal = new nsCCertPrincipal(certByteData, certByteDataSize, result); + if (pNSCCertPrincipal == NULL) + { + return; + } + m_pNSICertPrincipal = (nsICertPrincipal *)pNSCCertPrincipal; + m_pNSICertPrincipal->AddRef(); + + + // XXX raman fix the error condition. + nsCCodebasePrincipal *pNSCCodebasePrincipal = new nsCCodebasePrincipal(codebaseURL, result); + if (pNSCCodebasePrincipal == NULL) + { + return; + } + m_pNSICodebasePrincipal = (nsICodebasePrincipal *)pNSCCodebasePrincipal; + m_pNSICodebasePrincipal->AddRef(); + +} + +nsCCodeSourcePrincipal::~nsCCodeSourcePrincipal(void) +{ + m_pNSICertPrincipal->Release(); + m_pNSICodebasePrincipal->Release(); +} + + + diff --git a/mozilla/caps/src/nsCCodebasePrincipal.cpp b/mozilla/caps/src/nsCCodebasePrincipal.cpp new file mode 100644 index 00000000000..852140954f1 --- /dev/null +++ b/mozilla/caps/src/nsCCodebasePrincipal.cpp @@ -0,0 +1,92 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + */ + +#include "nsCCodebasePrincipal.h" +#include "nsPrincipal.h" +#include "xp.h" + +NS_DEFINE_IID(kICodebasePrincipalIID, NS_ICODEBASEPRINCIPAL_IID); +//////////////////////////////////////////////////////////////////////////// +// from nsISupports: + +// These macros produce simple version of QueryInterface and AddRef. +// See the nsISupports.h header file for DETAILS. + +NS_IMPL_ADDREF(nsCCodebasePrincipal) +NS_IMPL_RELEASE(nsCCodebasePrincipal) +NS_IMPL_QUERY_INTERFACE(nsCCodebasePrincipal, kICodebasePrincipalIID); + +//////////////////////////////////////////////////////////////////////////// +// from nsIPrincipal: + +NS_METHOD +nsCCodebasePrincipal::IsTrusted(char* scope, PRBool *pbIsTrusted) +{ + if(m_pNSPrincipal == NULL) + { + *pbIsTrusted = PR_FALSE; + return NS_ERROR_ILLEGAL_VALUE; + } + *pbIsTrusted = m_pNSPrincipal->isSecurePrincipal(); + return NS_OK; +} + + + +/** + * Returns the codebase URL of the principal. + * + * @param result - the resulting codebase URL + */ +NS_METHOD +nsCCodebasePrincipal::GetURL(const char **ppCodeBaseURL) +{ + if(m_pNSPrincipal == NULL) + { + *ppCodeBaseURL = NULL; + return NS_ERROR_ILLEGAL_VALUE; + } + *ppCodeBaseURL = m_pNSPrincipal->getKey(); + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////// +// from nsCCodebasePrincipal: + +nsCCodebasePrincipal::nsCCodebasePrincipal(const char *codebaseURL, nsresult *result) +{ + // XXX raman fix the error condition. + m_pNSPrincipal = new nsPrincipal(nsPrincipalType_CodebaseExact, (void *)codebaseURL, XP_STRLEN(codebaseURL)); + if(m_pNSPrincipal == NULL) + { + *result = NS_ERROR_OUT_OF_MEMORY; + return; + } + *result = NS_OK; +} + +nsCCodebasePrincipal::~nsCCodebasePrincipal(void) +{ + delete m_pNSPrincipal; +} + +nsPrincipal* +nsCCodebasePrincipal::GetPeer(void) +{ + return m_pNSPrincipal; +} diff --git a/mozilla/caps/src/nsCaps.cpp b/mozilla/caps/src/nsCaps.cpp index 2cc3c39fb88..8bae46471c9 100644 --- a/mozilla/caps/src/nsCaps.cpp +++ b/mozilla/caps/src/nsCaps.cpp @@ -29,9 +29,12 @@ #include "nsPrivilegeTable.h" #include "nsPrincipal.h" #include "nsTarget.h" +#include "nsCCapsManager.h" +#include "nsCCapsManagerFactory.h" PR_BEGIN_EXTERN_C +static PRBool bNSCapsInitialized_g = PR_FALSE; /* * C API FOR JS @@ -44,6 +47,11 @@ PR_BEGIN_EXTERN_C PR_IMPLEMENT(PRBool) nsCapsInitialize() { + if(bNSCapsInitialized_g == PR_TRUE) + { + return PR_TRUE; + } + bNSCapsInitialized_g = PR_TRUE; #if defined(_WIN32) nsPrincipal *sysPrin = CreateSystemPrincipal("java/classes/java40.jar", "java/lang/Object.class"); #else @@ -53,7 +61,7 @@ nsCapsInitialize() sysPrin = new nsPrincipal(nsPrincipalType_Cert, "52:54:45:4e:4e:45:54:49", strlen("52:54:45:4e:4e:45:54:49")); } - + nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); if (nsPrivManager == NULL) { nsPrivilegeManagerInitialize(); @@ -62,6 +70,15 @@ nsCapsInitialize() } PR_ASSERT(nsPrivManager != NULL); nsPrivManager->registerSystemPrincipal(sysPrin); + // New a class factory object and the constructor will register itself + // as the factory object in the repository. All other modules should + // FindFactory and use createInstance to create a instance of nsCCapsManager + // and ask for nsICapsManager interface. + nsCCapsManagerFactory *pNSCCapsManagerFactory = new nsCCapsManagerFactory(); + if ( pNSCCapsManagerFactory == NULL ) + { + return PR_FALSE; + } return PR_TRUE; } @@ -71,6 +88,8 @@ PR_IMPLEMENT(PRBool) nsCapsRegisterPrincipal(struct nsPrincipal *principal) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return PR_FALSE; nsPrivManager->registerPrincipal(principal); return PR_TRUE; } @@ -79,6 +98,8 @@ PR_IMPLEMENT(PRBool) nsCapsEnablePrivilege(void* context, struct nsTarget *target, PRInt32 callerDepth) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return PR_FALSE; return nsPrivManager->enablePrivilege(context, target, callerDepth); } @@ -86,6 +107,8 @@ PR_IMPLEMENT(PRBool) nsCapsIsPrivilegeEnabled(void* context, struct nsTarget *target, PRInt32 callerDepth) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return PR_FALSE; return nsPrivManager->isPrivilegeEnabled(context, target, callerDepth); } @@ -93,6 +116,8 @@ PR_IMPLEMENT(PRBool) nsCapsRevertPrivilege(void* context, struct nsTarget *target, PRInt32 callerDepth) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return PR_FALSE; return nsPrivManager->revertPrivilege(context, target, callerDepth); } @@ -100,6 +125,8 @@ PR_IMPLEMENT(PRBool) nsCapsDisablePrivilege(void* context, struct nsTarget *target, PRInt32 callerDepth) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return PR_FALSE; return nsPrivManager->disablePrivilege(context, target, callerDepth); } @@ -107,6 +134,8 @@ PR_IMPLEMENT(void*) nsCapsGetClassPrincipalsFromStack(void* context, PRInt32 callerDepth) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return NULL; return (void *)nsPrivManager->getClassPrincipalsFromStack(context, callerDepth); } @@ -114,6 +143,8 @@ PR_IMPLEMENT(nsSetComparisonType) nsCapsComparePrincipalArray(void* prin1Array, void* prin2Array) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return nsSetComparisonType_NoSubset; return nsPrivManager->comparePrincipalArray((nsPrincipalArray*)prin1Array, (nsPrincipalArray*)prin2Array); } @@ -122,6 +153,8 @@ PR_IMPLEMENT(void*) nsCapsIntersectPrincipalArray(void* prin1Array, void* prin2Array) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return NULL; return nsPrivManager->intersectPrincipalArray((nsPrincipalArray*)prin1Array, (nsPrincipalArray*)prin2Array); } @@ -130,6 +163,8 @@ PR_IMPLEMENT(PRBool) nsCapsCanExtendTrust(void* from, void* to) { nsPrivilegeManager *nsPrivManager = nsPrivilegeManager::getPrivilegeManager(); + if( nsPrivManager == NULL ) + return PR_FALSE; return nsPrivManager->canExtendTrust((nsPrincipalArray*)from, (nsPrincipalArray*)to); } diff --git a/mozilla/caps/src/nsPrivilegeManager.cpp b/mozilla/caps/src/nsPrivilegeManager.cpp index c42373614b4..a5ed05532e1 100755 --- a/mozilla/caps/src/nsPrivilegeManager.cpp +++ b/mozilla/caps/src/nsPrivilegeManager.cpp @@ -1029,9 +1029,14 @@ nsPrivilege *nsPrivilegeManager::getPrincipalPrivilege(nsTarget *target, nsPrincipal *prin, void *data) { + if ( (prin == NULL) || (target == NULL) ) + { + return nsPrivilege::findPrivilege(nsPermissionState_Blank, + nsDurationState_Session); + } if (getSystemPrincipal() == prin) { return nsPrivilege::findPrivilege(nsPermissionState_Allowed, - nsDurationState_Forever); + nsDurationState_Session); } PrincipalKey prinKey(prin); @@ -1039,13 +1044,15 @@ nsPrivilege *nsPrivilegeManager::getPrincipalPrivilege(nsTarget *target, (nsPrivilegeTable *) itsPrinToPrivTable->Get(&prinKey); if (privTable == NULL) { // the principal isn't registered, so ignore it - return NULL; + return nsPrivilege::findPrivilege(nsPermissionState_Blank, + nsDurationState_Session); } nsTarget *tempTarget = nsTarget::findTarget(target); if (tempTarget != target) { // Target is not registered, so ignore it - return NULL; + return nsPrivilege::findPrivilege(nsPermissionState_Blank, + nsDurationState_Session); } return privTable->get(target);