summaryrefslogtreecommitdiffstats
path: root/security/manager/ssl/nsNSSErrors.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /security/manager/ssl/nsNSSErrors.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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/nsNSSErrors.cpp')
-rw-r--r--security/manager/ssl/nsNSSErrors.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/security/manager/ssl/nsNSSErrors.cpp b/security/manager/ssl/nsNSSErrors.cpp
new file mode 100644
index 000000000..fc8bd3e31
--- /dev/null
+++ b/security/manager/ssl/nsNSSErrors.cpp
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * 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 "nsNSSComponent.h"
+#include "secerr.h"
+#include "sslerr.h"
+
+const char *
+nsNSSErrors::getDefaultErrorStringName(PRErrorCode err)
+{
+ return PR_ErrorToName(err);
+}
+
+const char *
+nsNSSErrors::getOverrideErrorStringName(PRErrorCode aErrorCode)
+{
+ const char *id_str = nullptr;
+
+ switch (aErrorCode) {
+ case SSL_ERROR_SSL_DISABLED:
+ id_str = "PSMERR_SSL_Disabled";
+ break;
+
+ case SSL_ERROR_SSL2_DISABLED:
+ id_str = "PSMERR_SSL2_Disabled";
+ break;
+
+ case SEC_ERROR_REUSED_ISSUER_AND_SERIAL:
+ id_str = "PSMERR_HostReusedIssuerSerial";
+ break;
+ }
+
+ return id_str;
+}
+
+nsresult
+nsNSSErrors::getErrorMessageFromCode(PRErrorCode err,
+ nsINSSComponent *component,
+ nsString &returnedMessage)
+{
+ NS_ENSURE_ARG_POINTER(component);
+ returnedMessage.Truncate();
+
+ const char *nss_error_id_str = getDefaultErrorStringName(err);
+ const char *id_str = getOverrideErrorStringName(err);
+
+ if (id_str || nss_error_id_str)
+ {
+ nsString defMsg;
+ nsresult rv;
+ if (id_str)
+ {
+ rv = component->GetPIPNSSBundleString(id_str, defMsg);
+ }
+ else
+ {
+ rv = component->GetNSSBundleString(nss_error_id_str, defMsg);
+ }
+
+ if (NS_SUCCEEDED(rv))
+ {
+ returnedMessage.Append(defMsg);
+ returnedMessage.Append('\n');
+ }
+ }
+
+ if (returnedMessage.IsEmpty())
+ {
+ // no localized string available, use NSS' internal
+ returnedMessage.AppendASCII(PR_ErrorToString(err, PR_LANGUAGE_EN));
+ returnedMessage.Append('\n');
+ }
+
+ if (nss_error_id_str)
+ {
+ nsresult rv;
+ nsCString error_id(nss_error_id_str);
+ NS_ConvertASCIItoUTF16 idU(error_id);
+
+ const char16_t *params[1];
+ params[0] = idU.get();
+
+ nsString formattedString;
+ rv = component->PIPBundleFormatStringFromName("certErrorCodePrefix2",
+ params, 1,
+ formattedString);
+ if (NS_SUCCEEDED(rv)) {
+ returnedMessage.Append('\n');
+ returnedMessage.Append(formattedString);
+ returnedMessage.Append('\n');
+ }
+ else {
+ returnedMessage.Append('(');
+ returnedMessage.Append(idU);
+ returnedMessage.Append(')');
+ }
+ }
+
+ return NS_OK;
+}