|
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/. */ |
|
6 |
|
7 #include "nsNSSComponent.h" |
|
8 #include "secerr.h" |
|
9 #include "sslerr.h" |
|
10 |
|
11 const char * |
|
12 nsNSSErrors::getDefaultErrorStringName(PRErrorCode err) |
|
13 { |
|
14 return PR_ErrorToName(err); |
|
15 } |
|
16 |
|
17 const char * |
|
18 nsNSSErrors::getOverrideErrorStringName(PRErrorCode aErrorCode) |
|
19 { |
|
20 const char *id_str = nullptr; |
|
21 |
|
22 switch (aErrorCode) { |
|
23 case SSL_ERROR_SSL_DISABLED: |
|
24 id_str = "PSMERR_SSL_Disabled"; |
|
25 break; |
|
26 |
|
27 case SSL_ERROR_SSL2_DISABLED: |
|
28 id_str = "PSMERR_SSL2_Disabled"; |
|
29 break; |
|
30 |
|
31 case SEC_ERROR_REUSED_ISSUER_AND_SERIAL: |
|
32 id_str = "PSMERR_HostReusedIssuerSerial"; |
|
33 break; |
|
34 } |
|
35 |
|
36 return id_str; |
|
37 } |
|
38 |
|
39 nsresult |
|
40 nsNSSErrors::getErrorMessageFromCode(PRErrorCode err, |
|
41 nsINSSComponent *component, |
|
42 nsString &returnedMessage) |
|
43 { |
|
44 NS_ENSURE_ARG_POINTER(component); |
|
45 returnedMessage.Truncate(); |
|
46 |
|
47 const char *nss_error_id_str = getDefaultErrorStringName(err); |
|
48 const char *id_str = getOverrideErrorStringName(err); |
|
49 |
|
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 } |
|
62 |
|
63 if (NS_SUCCEEDED(rv)) |
|
64 { |
|
65 returnedMessage.Append(defMsg); |
|
66 returnedMessage.Append(NS_LITERAL_STRING("\n")); |
|
67 } |
|
68 } |
|
69 |
|
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 } |
|
76 |
|
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); |
|
83 |
|
84 const char16_t *params[1]; |
|
85 params[0] = idU.get(); |
|
86 |
|
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 } |
|
102 |
|
103 return NS_OK; |
|
104 } |