comphelper/source/misc/hash.cxx | 13 ++++++++++--- desktop/source/lib/init.cxx | 14 ++++++++++++++ onlineupdate/source/update/updater/updater.cxx | 13 ++++++++----- oox/source/crypto/CryptTools.cxx | 12 +++++++++++- 4 files changed, 43 insertions(+), 9 deletions(-)
New commits: commit 4a9cc6938b5abe59303b15cb826204035b910df3 Author: Andras Timar <andras.ti...@collabora.com> AuthorDate: Mon Nov 7 14:29:09 2022 +0100 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Jan 16 17:31:45 2023 +0100 NSS initialization guard Change-Id: I61a5886d0d13eaef6a61479e35d52a85937075ed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142385 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Henry Castro <hcas...@collabora.com> diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx index 9fab6028a659..0fb2ef28c461 100644 --- a/comphelper/source/misc/hash.cxx +++ b/comphelper/source/misc/hash.cxx @@ -77,11 +77,15 @@ struct HashImpl { #if USE_TLS_NSS - auto const e = NSS_NoDB_Init(nullptr); - if (e != SECSuccess) { - PRErrorCode error = PR_GetError(); - const char* errorText = PR_ErrorToName(error); - throw css::uno::RuntimeException("NSS_NoDB_Init failed with " + OUString(errorText, strlen(errorText), RTL_TEXTENCODING_UTF8) + " (" + OUString::number((int) error) + ")"); + if (!NSS_IsInitialized()) + { + auto const e = NSS_NoDB_Init(nullptr); + if (e != SECSuccess) + { + PRErrorCode error = PR_GetError(); + const char* errorText = PR_ErrorToName(error); + throw css::uno::RuntimeException("NSS_NoDB_Init failed with " + OUString(errorText, strlen(errorText), RTL_TEXTENCODING_UTF8) + " (" + OUString::number((int) error) + ")"); + } } mpContext = HASH_Create(getNSSType()); HASH_Begin(mpContext); diff --git a/onlineupdate/source/update/updater/updater.cxx b/onlineupdate/source/update/updater/updater.cxx index 54750afb4218..467f0b67cd1f 100644 --- a/onlineupdate/source/update/updater/updater.cxx +++ b/onlineupdate/source/update/updater/updater.cxx @@ -2919,12 +2919,15 @@ int NS_main(int argc, NS_tchar **argv) // need to initialize NSS at all there. // Otherwise, minimize the amount of NSS we depend on by avoiding all the NSS // databases. - if (NSS_NoDB_Init(NULL) != SECSuccess) + if (!NSS_IsInitialized()) { - PRErrorCode error = PR_GetError(); - fprintf(stderr, "Could not initialize NSS: %s (%d)", - PR_ErrorToName(error), (int) error); - _exit(1); + if (NSS_NoDB_Init(NULL) != SECSuccess) + { + PRErrorCode error = PR_GetError(); + fprintf(stderr, "Could not initialize NSS: %s (%d)", + PR_ErrorToName(error), (int) error); + _exit(1); + } } #endif diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx index ee68a8a50815..c66a04084c87 100644 --- a/oox/source/crypto/CryptTools.cxx +++ b/oox/source/crypto/CryptTools.cxx @@ -21,6 +21,7 @@ #if USE_TLS_NSS #include <nss.h> +#include <nspr.h> #include <pk11pub.h> #endif // USE_TLS_NSS @@ -167,7 +168,16 @@ struct CryptoImpl , mWrapKey(nullptr) { // Initialize NSS, database functions are not needed - NSS_NoDB_Init(nullptr); + if (!NSS_IsInitialized()) + { + auto const e = NSS_NoDB_Init(nullptr); + if (e != SECSuccess) + { + PRErrorCode error = PR_GetError(); + const char* errorText = PR_ErrorToName(error); + throw css::uno::RuntimeException("NSS_NoDB_Init failed with " + OUString(errorText, strlen(errorText), RTL_TEXTENCODING_UTF8) + " (" + OUString::number((int) error) + ")"); + } + } } ~CryptoImpl() commit a53581f09b7df2b9e639318d10dd5a0aec7eb600 Author: Andras Timar <andras.ti...@collabora.com> AuthorDate: Fri Nov 4 17:44:10 2022 +0100 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Jan 16 17:31:25 2023 +0100 more detailed NSS error report Change-Id: I1b005a331aeed1c00d6bf18a6dff0ffa844ba6f5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142286 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Aron Budea <aron.bu...@collabora.com> diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx index 50fd8cd0f961..9fab6028a659 100644 --- a/comphelper/source/misc/hash.cxx +++ b/comphelper/source/misc/hash.cxx @@ -18,6 +18,7 @@ #if USE_TLS_NSS #include <nss.h> +#include <nspr.h> #include <sechash.h> #elif USE_TLS_OPENSSL #include <openssl/evp.h> @@ -78,7 +79,9 @@ struct HashImpl #if USE_TLS_NSS auto const e = NSS_NoDB_Init(nullptr); if (e != SECSuccess) { - throw css::uno::RuntimeException("NSS_NoDB_Init failed with " + OUString::number(e)); + PRErrorCode error = PR_GetError(); + const char* errorText = PR_ErrorToName(error); + throw css::uno::RuntimeException("NSS_NoDB_Init failed with " + OUString(errorText, strlen(errorText), RTL_TEXTENCODING_UTF8) + " (" + OUString::number((int) error) + ")"); } mpContext = HASH_Create(getNSSType()); HASH_Begin(mpContext); commit 8c23a0ca44ef86c4bcfd62033a63fb2715f68ef9 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Fri Nov 4 14:00:26 2022 -0400 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Jan 16 17:30:20 2023 +0100 lok: ensure to initialize the security context if the backend NSS is used, before load the document ensure the NSS is initialized otherwise NSS next functions calls will fail. Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: I7ac1d7eeee681995e6c284e2dd4595a33d044af4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142213 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Aron Budea <aron.bu...@collabora.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 0567c12edca4..039458f69e22 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -3432,6 +3432,20 @@ static void doc_iniUnoCommands () return; } + uno::Reference<xml::crypto::XSEInitializer> xSEInitializer = xml::crypto::SEInitializer::create(xContext); + if (!xSEInitializer.is()) + { + SAL_WARN("lok", "iniUnoCommands: XSEInitializer is not available"); + return; + } + + uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext = + xSEInitializer->createSecurityContext(OUString()); + if (!xSecurityContext.is()) + { + SAL_WARN("lok", "iniUnoCommands: failed to create security context"); + } + SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool(pViewFrame); uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(xContext));