Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsNSSComponent.h"
8 #include "secerr.h"
9 #include "sslerr.h"
11 const char *
12 nsNSSErrors::getDefaultErrorStringName(PRErrorCode err)
13 {
14 return PR_ErrorToName(err);
15 }
17 const char *
18 nsNSSErrors::getOverrideErrorStringName(PRErrorCode aErrorCode)
19 {
20 const char *id_str = nullptr;
22 switch (aErrorCode) {
23 case SSL_ERROR_SSL_DISABLED:
24 id_str = "PSMERR_SSL_Disabled";
25 break;
27 case SSL_ERROR_SSL2_DISABLED:
28 id_str = "PSMERR_SSL2_Disabled";
29 break;
31 case SEC_ERROR_REUSED_ISSUER_AND_SERIAL:
32 id_str = "PSMERR_HostReusedIssuerSerial";
33 break;
34 }
36 return id_str;
37 }
39 nsresult
40 nsNSSErrors::getErrorMessageFromCode(PRErrorCode err,
41 nsINSSComponent *component,
42 nsString &returnedMessage)
43 {
44 NS_ENSURE_ARG_POINTER(component);
45 returnedMessage.Truncate();
47 const char *nss_error_id_str = getDefaultErrorStringName(err);
48 const char *id_str = getOverrideErrorStringName(err);
50 if (id_str || nss_error_id_str)
51 {
52 nsString defMsg;
53 nsresult rv;
54 if (id_str)
55 {
56 rv = component->GetPIPNSSBundleString(id_str, defMsg);
57 }
58 else
59 {
60 rv = component->GetNSSBundleString(nss_error_id_str, defMsg);
61 }
63 if (NS_SUCCEEDED(rv))
64 {
65 returnedMessage.Append(defMsg);
66 returnedMessage.Append(NS_LITERAL_STRING("\n"));
67 }
68 }
70 if (returnedMessage.IsEmpty())
71 {
72 // no localized string available, use NSS' internal
73 returnedMessage.AppendASCII(PR_ErrorToString(err, PR_LANGUAGE_EN));
74 returnedMessage.Append(NS_LITERAL_STRING("\n"));
75 }
77 if (nss_error_id_str)
78 {
79 nsresult rv;
80 nsCString error_id(nss_error_id_str);
81 ToLowerCase(error_id);
82 NS_ConvertASCIItoUTF16 idU(error_id);
84 const char16_t *params[1];
85 params[0] = idU.get();
87 nsString formattedString;
88 rv = component->PIPBundleFormatStringFromName("certErrorCodePrefix",
89 params, 1,
90 formattedString);
91 if (NS_SUCCEEDED(rv)) {
92 returnedMessage.Append(NS_LITERAL_STRING("\n"));
93 returnedMessage.Append(formattedString);
94 returnedMessage.Append(NS_LITERAL_STRING("\n"));
95 }
96 else {
97 returnedMessage.Append(NS_LITERAL_STRING("("));
98 returnedMessage.Append(idU);
99 returnedMessage.Append(NS_LITERAL_STRING(")"));
100 }
101 }
103 return NS_OK;
104 }