Line data Source code
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 0 : nsNSSErrors::getDefaultErrorStringName(PRErrorCode err)
13 : {
14 0 : return PR_ErrorToName(err);
15 : }
16 :
17 : const char *
18 0 : nsNSSErrors::getOverrideErrorStringName(PRErrorCode aErrorCode)
19 : {
20 0 : const char *id_str = nullptr;
21 :
22 0 : switch (aErrorCode) {
23 : case SSL_ERROR_SSL_DISABLED:
24 0 : id_str = "PSMERR_SSL_Disabled";
25 0 : break;
26 :
27 : case SSL_ERROR_SSL2_DISABLED:
28 0 : id_str = "PSMERR_SSL2_Disabled";
29 0 : break;
30 :
31 : case SEC_ERROR_REUSED_ISSUER_AND_SERIAL:
32 0 : id_str = "PSMERR_HostReusedIssuerSerial";
33 0 : break;
34 : }
35 :
36 0 : return id_str;
37 : }
38 :
39 : nsresult
40 0 : nsNSSErrors::getErrorMessageFromCode(PRErrorCode err,
41 : nsINSSComponent *component,
42 : nsString &returnedMessage)
43 : {
44 0 : NS_ENSURE_ARG_POINTER(component);
45 0 : returnedMessage.Truncate();
46 :
47 0 : const char *nss_error_id_str = getDefaultErrorStringName(err);
48 0 : const char *id_str = getOverrideErrorStringName(err);
49 :
50 0 : if (id_str || nss_error_id_str)
51 : {
52 0 : nsString defMsg;
53 : nsresult rv;
54 0 : if (id_str)
55 : {
56 0 : rv = component->GetPIPNSSBundleString(id_str, defMsg);
57 : }
58 : else
59 : {
60 0 : rv = component->GetNSSBundleString(nss_error_id_str, defMsg);
61 : }
62 :
63 0 : if (NS_SUCCEEDED(rv))
64 : {
65 0 : returnedMessage.Append(defMsg);
66 0 : returnedMessage.Append('\n');
67 : }
68 : }
69 :
70 0 : if (returnedMessage.IsEmpty())
71 : {
72 : // no localized string available, use NSS' internal
73 0 : returnedMessage.AppendASCII(PR_ErrorToString(err, PR_LANGUAGE_EN));
74 0 : returnedMessage.Append('\n');
75 : }
76 :
77 0 : if (nss_error_id_str)
78 : {
79 : nsresult rv;
80 0 : nsCString error_id(nss_error_id_str);
81 0 : NS_ConvertASCIItoUTF16 idU(error_id);
82 :
83 : const char16_t *params[1];
84 0 : params[0] = idU.get();
85 :
86 0 : nsString formattedString;
87 : rv = component->PIPBundleFormatStringFromName("certErrorCodePrefix2",
88 : params, 1,
89 0 : formattedString);
90 0 : if (NS_SUCCEEDED(rv)) {
91 0 : returnedMessage.Append('\n');
92 0 : returnedMessage.Append(formattedString);
93 0 : returnedMessage.Append('\n');
94 : }
95 : else {
96 0 : returnedMessage.Append('(');
97 0 : returnedMessage.Append(idU);
98 0 : returnedMessage.Append(')');
99 : }
100 : }
101 :
102 0 : return NS_OK;
103 : }
|