Bug 326628 try #2 - remove window.pkcs11 and fix the device manager not to use that API, r=kaie

This commit is contained in:
Benjamin Smedberg 2009-05-28 19:36:21 -07:00
parent 761090a98f
commit 3a0ef1193a
9 changed files with 119 additions and 115 deletions

View File

@ -332,7 +332,6 @@
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIDOMCrypto.h"
#include "nsIDOMCRMFObject.h"
#include "nsIDOMPkcs11.h"
#include "nsIControllers.h"
#include "nsISelection.h"
#include "nsIBoxObject.h"
@ -857,8 +856,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,
@ -2646,10 +2643,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)

View File

@ -189,7 +189,6 @@ enum nsDOMClassInfoID {
// Crypto classes
eDOMClassInfo_Crypto_id,
eDOMClassInfo_CRMFObject_id,
eDOMClassInfo_Pkcs11_id,
// DOM Traversal classes
eDOMClassInfo_TreeWalker_id,

View File

@ -107,7 +107,6 @@
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMessageEvent.h"
#include "nsIDOMPopupBlockedEvent.h"
#include "nsIDOMPkcs11.h"
#include "nsIDOMOfflineResourceList.h"
#include "nsIDOMGeoGeolocation.h"
#include "nsDOMString.h"
@ -2963,14 +2962,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;
}

View File

@ -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<nsIDOMStorage> mLocalStorage;

View File

@ -48,6 +48,8 @@ const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1";
const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB;
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
const nsDialogParamBlock = "@mozilla.org/embedcomp/dialogparam;1";
const nsIPKCS11 = Components.interfaces.nsIPKCS11;
const nsPKCS11ContractID = "@mozilla.org/security/pkcs11;1";
var bundle;
var secmoddb;
@ -65,6 +67,31 @@ function LoadModules()
RefreshDeviceList();
}
function getPKCS11()
{
return Components.classes[nsPKCS11ContractID].getService(nsIPKCS11);
}
function getNSSString(name)
{
return srGetStrBundle("chrome://pipnss/locale/pipnss.properties").
GetStringFromName(name);
}
function doPrompt(msg)
{
let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
getService(Components.interfaces.nsIPromptService);
prompts.alert(window, null, msg);
}
function doConfirm(msg)
{
let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
getService(Components.interfaces.nsIPromptService);
return prompts.confirm(window, null, msg);
}
function RefreshDeviceList()
{
var modules = secmoddb.listModules();
@ -398,13 +425,17 @@ function doLoad()
function deleteSelected()
{
getSelectedItem();
if (selected_module) {
var retval = pkcs11.deletemodule(selected_module.name);
if (retval == 1 || retval == 2) {
// successful deletion of internal or external module
selected_module = null;
return true;
if (selected_module &&
doConfirm(getNSSString("DelModuleWarning"))) {
try {
getPKCS11().deleteModule(selected_module.name);
}
catch (e) {
doPrompt(getNSSString("DelModuleError"));
return false;
}
selected_module = null;
return true;
}
return false;
}
@ -460,7 +491,17 @@ function doLoadDevice()
{
var name_box = document.getElementById("device_name");
var path_box = document.getElementById("device_path");
pkcs11.addmodule(name_box.value, path_box.value, 0,0);
try {
getPKCS11().addModule(name_box.value, path_box.value, 0,0);
}
catch (e) {
if (e.result == Components.results.NS_ERROR_ILLEGAL_VALUE)
doPrompt(getNSSString("AddModuleDup"));
else
doPrompt(getNSSString("AddModuleFailure"));
return false;
}
return true;
}

View File

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

View File

@ -0,0 +1,49 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Johnny Stenback <jst@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
[scriptable, uuid(5743f870-958e-4f02-aef2-c0afeef67f05)]
interface nsIPKCS11 : nsISupports
{
void deleteModule(in AString moduleName);
void addModule(in AString moduleName,
in AString libraryFullPath,
in long cryptoMechanismFlags,
in long cipherFlags);
};

View File

@ -251,9 +251,8 @@ 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
NS_IMPL_ADDREF(nsPkcs11)
@ -2945,33 +2944,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 +2967,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 +3007,13 @@ 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;
case -2:
return NS_ERROR_ILLEGAL_VALUE;
}
alertUser(final.get());
return NS_OK;
NS_ASSERTION(0,"Bogus return value, this should never happen");
return NS_ERROR_FAILURE;
}

View File

@ -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
};