Bug 326628 - user content can pop up pkcs11 dialogs, which is annoying and entirely unnecessary r+sr=jst,r=kaie

This commit is contained in:
Benjamin Smedberg 2009-04-08 10:27:45 -04:00
Родитель 1cd43cc746
Коммит 7fd586cb4d
8 изменённых файлов: 27 добавлений и 113 удалений

Просмотреть файл

@ -340,7 +340,6 @@
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIDOMCrypto.h"
#include "nsIDOMCRMFObject.h"
#include "nsIDOMPkcs11.h"
#include "nsIControllers.h"
#include "nsISelection.h"
#include "nsIBoxObject.h"
@ -867,8 +866,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CRMFObject, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(Pkcs11, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
// DOM Traversal classes
NS_DEFINE_CLASSINFO_DATA(TreeWalker, nsDOMGenericSH,
@ -2672,10 +2669,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCRMFObject)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Pkcs11, nsIDOMPkcs11)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMPkcs11)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XMLStylesheetProcessingInstruction, nsIDOMProcessingInstruction)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMProcessingInstruction)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMLinkStyle)

Просмотреть файл

@ -110,7 +110,6 @@
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMessageEvent.h"
#include "nsIDOMPopupBlockedEvent.h"
#include "nsIDOMPkcs11.h"
#include "nsIDOMOfflineResourceList.h"
#include "nsIDOMGeoGeolocation.h"
#include "nsDOMString.h"
@ -2940,14 +2939,7 @@ nsGlobalWindow::GetCrypto(nsIDOMCrypto** aCrypto)
NS_IMETHODIMP
nsGlobalWindow::GetPkcs11(nsIDOMPkcs11** aPkcs11)
{
FORWARD_TO_OUTER(GetPkcs11, (aPkcs11), NS_ERROR_NOT_INITIALIZED);
if (!mPkcs11) {
mPkcs11 = do_CreateInstance(kPkcs11ContractID);
}
NS_IF_ADDREF(*aPkcs11 = mPkcs11);
*aPkcs11 = nsnull;
return NS_OK;
}

Просмотреть файл

@ -84,7 +84,6 @@
#include "nsIEventListenerManager.h"
#include "nsIDOMDocument.h"
#include "nsIDOMCrypto.h"
#include "nsIDOMPkcs11.h"
#include "nsIPrincipal.h"
#include "nsPluginArray.h"
#include "nsMimeTypeArray.h"
@ -708,7 +707,6 @@ protected:
nsGlobalWindowObserver* mObserver;
nsCOMPtr<nsIDOMCrypto> mCrypto;
nsCOMPtr<nsIDOMPkcs11> mPkcs11;
nsCOMPtr<nsIDOMStorage2> mLocalStorage;

Просмотреть файл

@ -66,7 +66,6 @@ XPIDLSRCS = \
nsIDOMMimeType.idl \
nsIDOMMimeTypeArray.idl \
nsIDOMNavigator.idl \
nsIDOMPkcs11.idl \
nsIDOMPlugin.idl \
nsIDOMPluginArray.idl \
nsIDOMScreen.idl \

Просмотреть файл

@ -71,6 +71,7 @@ XPIDLSRCS = \
nsIX509Cert3.idl \
nsIX509CertDB2.idl \
nsIX509CertList.idl \
nsIPKCS11.idl \
nsIPKCS11Slot.idl \
nsIPK11TokenDB.idl \
nsICertPickDialogs.idl \

Просмотреть файл

@ -38,12 +38,12 @@
#include "domstubs.idl"
[scriptable, uuid(9fd42950-25e7-11d4-8a7d-006008c844c3)]
interface nsIDOMPkcs11 : nsISupports
[scriptable, uuid(bd6dbe50-b902-435e-90a4-4a10b1122440)]
interface nsIPKCS11 : nsISupports
{
long deletemodule(in DOMString moduleName);
long addmodule(in DOMString moduleName,
in DOMString libraryFullPath,
in long cryptoMechanismFlags,
in long cipherFlags);
void deleteModule(in DOMString moduleName);
void addModule(in DOMString moduleName,
in DOMString libraryFullPath,
in long cryptoMechanismFlags,
in long cipherFlags);
};

Просмотреть файл

@ -251,7 +251,7 @@ NS_IMPL_RELEASE(nsCRMFObject)
// QueryInterface implementation for nsPkcs11
NS_INTERFACE_MAP_BEGIN(nsPkcs11)
NS_INTERFACE_MAP_ENTRY(nsIDOMPkcs11)
NS_INTERFACE_MAP_ENTRY(nsIPKCS11)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Pkcs11)
NS_INTERFACE_MAP_END
@ -2945,33 +2945,18 @@ confirm_user(const PRUnichar *message)
//Delete a PKCS11 module from the user's profile.
NS_IMETHODIMP
nsPkcs11::Deletemodule(const nsAString& aModuleName, PRInt32* aReturn)
nsPkcs11::DeleteModule(const nsAString& aModuleName)
{
nsNSSShutDownPreventionLock locker;
nsresult rv;
nsString errorMessage;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
if (NS_FAILED(rv))
return rv;
if (aModuleName.IsEmpty()) {
*aReturn = JS_ERR_BAD_MODULE_NAME;
nssComponent->GetPIPNSSBundleString("DelModuleBadName", errorMessage);
alertUser(errorMessage.get());
return NS_OK;
}
nsString final;
nsAutoString temp;
//Make sure the user knows we're trying to do this.
nssComponent->GetPIPNSSBundleString("DelModuleWarning", final);
final.Append(NS_LITERAL_STRING("\n").get());
PRUnichar *tempUni = ToNewUnicode(aModuleName);
const PRUnichar *formatStrings[1] = { tempUni };
rv = nssComponent->PIPBundleFormatStringFromName("AddModuleName",
formatStrings, 1, temp);
nsMemory::Free(tempUni);
final.Append(temp);
if (!confirm_user(final.get())) {
*aReturn = JS_ERR_USER_CANCEL_ACTION;
return NS_OK;
return NS_ERROR_ILLEGAL_VALUE;
}
char *modName = ToNewCString(aModuleName);
@ -2983,69 +2968,25 @@ nsPkcs11::Deletemodule(const nsAString& aModuleName, PRInt32* aReturn)
nssComponent->ShutdownSmartCardThread(module);
SECMOD_DestroyModule(module);
}
if (modType == SECMOD_EXTERNAL) {
nssComponent->GetPIPNSSBundleString("DelModuleExtSuccess", errorMessage);
*aReturn = JS_OK_DEL_EXTERNAL_MOD;
} else {
nssComponent->GetPIPNSSBundleString("DelModuleIntSuccess", errorMessage);
*aReturn = JS_OK_DEL_INTERNAL_MOD;
}
rv = NS_OK;
} else {
*aReturn = JS_ERR_DEL_MOD;
nssComponent->GetPIPNSSBundleString("DelModuleError", errorMessage);
rv = NS_ERROR_FAILURE;
}
alertUser(errorMessage.get());
return NS_OK;
NS_Free(modName);
return rv;
}
//Add a new PKCS11 module to the user's profile.
NS_IMETHODIMP
nsPkcs11::Addmodule(const nsAString& aModuleName,
nsPkcs11::AddModule(const nsAString& aModuleName,
const nsAString& aLibraryFullPath,
PRInt32 aCryptoMechanismFlags,
PRInt32 aCipherFlags, PRInt32* aReturn)
PRInt32 aCipherFlags)
{
nsNSSShutDownPreventionLock locker;
nsresult rv;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
nsString final;
nsAutoString temp;
rv = nssComponent->GetPIPNSSBundleString("AddModulePrompt", final);
if (NS_FAILED(rv))
return rv;
final.Append(NS_LITERAL_STRING("\n").get());
PRUnichar *tempUni = ToNewUnicode(aModuleName);
const PRUnichar *formatStrings[1] = { tempUni };
rv = nssComponent->PIPBundleFormatStringFromName("AddModuleName",
formatStrings, 1, temp);
nsMemory::Free(tempUni);
if (NS_FAILED(rv))
return rv;
final.Append(temp);
final.Append(NS_LITERAL_STRING("\n").get());
tempUni = ToNewUnicode(aLibraryFullPath);
formatStrings[0] = tempUni;
rv = nssComponent->PIPBundleFormatStringFromName("AddModulePath",
formatStrings, 1, temp);
nsMemory::Free(tempUni);
if (NS_FAILED(rv))
return rv;
final.Append(temp);
final.Append(NS_LITERAL_STRING("\n").get());
if (!confirm_user(final.get())) {
// The user has canceled. So let's return now.
*aReturn = JS_ERR_USER_CANCEL_ACTION;
return NS_OK;
}
char *moduleName = ToNewCString(aModuleName);
char *fullPath = ToNewCString(aLibraryFullPath);
PRUint32 mechFlags = SECMOD_PubMechFlagstoInternal(aCryptoMechanismFlags);
@ -3067,22 +3008,12 @@ nsPkcs11::Addmodule(const nsAString& aModuleName,
// what the return value for SEDMOD_AddNewModule is
switch (srv) {
case SECSuccess:
nssComponent->GetPIPNSSBundleString("AddModuleSuccess", final);
*aReturn = JS_OK_ADD_MOD;
break;
return NS_OK;
case SECFailure:
nssComponent->GetPIPNSSBundleString("AddModuleFailure", final);
*aReturn = JS_ERR_ADD_MOD;
break;
case -2:
nssComponent->GetPIPNSSBundleString("AddModuleDup", final);
*aReturn = JS_ERR_ADD_DUPLICATE_MOD;
break;
default:
NS_ASSERTION(0,"Bogus return value, this should never happen");
return NS_ERROR_FAILURE;
}
alertUser(final.get());
return NS_OK;
NS_ASSERTION(0,"Bogus return value, this should never happen");
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -41,7 +41,7 @@
#include "nsCOMPtr.h"
#include "nsIDOMCRMFObject.h"
#include "nsIDOMCrypto.h"
#include "nsIDOMPkcs11.h"
#include "nsIPKCS11.h"
#include "nsIRunnable.h"
#include "nsString.h"
#include "jsapi.h"
@ -95,14 +95,14 @@ private:
PRBool mEnableSmartCardEvents;
};
class nsPkcs11 : public nsIDOMPkcs11
class nsPkcs11 : public nsIPKCS11
{
public:
nsPkcs11();
virtual ~nsPkcs11();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMPKCS11
NS_DECL_NSIPKCS11
};