blob: fc8bd3e31899bf922da9fbc72e15d9ffbb93e7ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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;
}
|