diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /security/manager/ssl/nsCrypto.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'security/manager/ssl/nsCrypto.cpp')
-rw-r--r-- | security/manager/ssl/nsCrypto.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/security/manager/ssl/nsCrypto.cpp b/security/manager/ssl/nsCrypto.cpp new file mode 100644 index 000000000..361257968 --- /dev/null +++ b/security/manager/ssl/nsCrypto.cpp @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsCrypto.h" + +#include "nsNSSComponent.h" +#include "nsNativeCharsetUtils.h" +#include "nsServiceManagerUtils.h" +#include "ScopedNSSTypes.h" + +// QueryInterface implementation for nsPkcs11 +NS_INTERFACE_MAP_BEGIN(nsPkcs11) + NS_INTERFACE_MAP_ENTRY(nsIPKCS11) + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +NS_IMPL_ADDREF(nsPkcs11) +NS_IMPL_RELEASE(nsPkcs11) + +nsPkcs11::nsPkcs11() +{ +} + +nsPkcs11::~nsPkcs11() +{ + nsNSSShutDownPreventionLock locker; + if (isAlreadyShutDown()) { + return; + } + shutdown(ShutdownCalledFrom::Object); +} + +// Delete a PKCS11 module from the user's profile. +NS_IMETHODIMP +nsPkcs11::DeleteModule(const nsAString& aModuleName) +{ + nsNSSShutDownPreventionLock locker; + if (isAlreadyShutDown()) { + return NS_ERROR_NOT_AVAILABLE; + } + + if (aModuleName.IsEmpty()) { + return NS_ERROR_INVALID_ARG; + } + + NS_ConvertUTF16toUTF8 moduleName(aModuleName); + // Introduce additional scope for module so all references to it are released + // before we call SECMOD_DeleteModule, below. +#ifndef MOZ_NO_SMART_CARDS + { + mozilla::UniqueSECMODModule module(SECMOD_FindModule(moduleName.get())); + if (!module) { + return NS_ERROR_FAILURE; + } + nsCOMPtr<nsINSSComponent> nssComponent( + do_GetService(PSM_COMPONENT_CONTRACTID)); + nssComponent->ShutdownSmartCardThread(module.get()); + } +#endif + + // modType is an output variable. We ignore it. + int32_t modType; + SECStatus srv = SECMOD_DeleteModule(moduleName.get(), &modType); + if (srv != SECSuccess) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +// Add a new PKCS11 module to the user's profile. +NS_IMETHODIMP +nsPkcs11::AddModule(const nsAString& aModuleName, + const nsAString& aLibraryFullPath, + int32_t aCryptoMechanismFlags, + int32_t aCipherFlags) +{ + nsNSSShutDownPreventionLock locker; + if (isAlreadyShutDown()) { + return NS_ERROR_NOT_AVAILABLE; + } + + if (aModuleName.IsEmpty()) { + return NS_ERROR_INVALID_ARG; + } + + NS_ConvertUTF16toUTF8 moduleName(aModuleName); + nsCString fullPath; + // NSS doesn't support Unicode path. Use native charset + NS_CopyUnicodeToNative(aLibraryFullPath, fullPath); + uint32_t mechFlags = SECMOD_PubMechFlagstoInternal(aCryptoMechanismFlags); + uint32_t cipherFlags = SECMOD_PubCipherFlagstoInternal(aCipherFlags); + SECStatus srv = SECMOD_AddNewModule(moduleName.get(), fullPath.get(), + mechFlags, cipherFlags); + if (srv != SECSuccess) { + return NS_ERROR_FAILURE; + } + +#ifndef MOZ_NO_SMART_CARDS + mozilla::UniqueSECMODModule module(SECMOD_FindModule(moduleName.get())); + if (!module) { + return NS_ERROR_FAILURE; + } + nsCOMPtr<nsINSSComponent> nssComponent( + do_GetService(PSM_COMPONENT_CONTRACTID)); + nssComponent->LaunchSmartCardThread(module.get()); +#endif + + return NS_OK; +} |