1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/manager/ssl/src/nsNSSErrors.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "nsNSSComponent.h" 1.11 +#include "secerr.h" 1.12 +#include "sslerr.h" 1.13 + 1.14 +const char * 1.15 +nsNSSErrors::getDefaultErrorStringName(PRErrorCode err) 1.16 +{ 1.17 + return PR_ErrorToName(err); 1.18 +} 1.19 + 1.20 +const char * 1.21 +nsNSSErrors::getOverrideErrorStringName(PRErrorCode aErrorCode) 1.22 +{ 1.23 + const char *id_str = nullptr; 1.24 + 1.25 + switch (aErrorCode) { 1.26 + case SSL_ERROR_SSL_DISABLED: 1.27 + id_str = "PSMERR_SSL_Disabled"; 1.28 + break; 1.29 + 1.30 + case SSL_ERROR_SSL2_DISABLED: 1.31 + id_str = "PSMERR_SSL2_Disabled"; 1.32 + break; 1.33 + 1.34 + case SEC_ERROR_REUSED_ISSUER_AND_SERIAL: 1.35 + id_str = "PSMERR_HostReusedIssuerSerial"; 1.36 + break; 1.37 + } 1.38 + 1.39 + return id_str; 1.40 +} 1.41 + 1.42 +nsresult 1.43 +nsNSSErrors::getErrorMessageFromCode(PRErrorCode err, 1.44 + nsINSSComponent *component, 1.45 + nsString &returnedMessage) 1.46 +{ 1.47 + NS_ENSURE_ARG_POINTER(component); 1.48 + returnedMessage.Truncate(); 1.49 + 1.50 + const char *nss_error_id_str = getDefaultErrorStringName(err); 1.51 + const char *id_str = getOverrideErrorStringName(err); 1.52 + 1.53 + if (id_str || nss_error_id_str) 1.54 + { 1.55 + nsString defMsg; 1.56 + nsresult rv; 1.57 + if (id_str) 1.58 + { 1.59 + rv = component->GetPIPNSSBundleString(id_str, defMsg); 1.60 + } 1.61 + else 1.62 + { 1.63 + rv = component->GetNSSBundleString(nss_error_id_str, defMsg); 1.64 + } 1.65 + 1.66 + if (NS_SUCCEEDED(rv)) 1.67 + { 1.68 + returnedMessage.Append(defMsg); 1.69 + returnedMessage.Append(NS_LITERAL_STRING("\n")); 1.70 + } 1.71 + } 1.72 + 1.73 + if (returnedMessage.IsEmpty()) 1.74 + { 1.75 + // no localized string available, use NSS' internal 1.76 + returnedMessage.AppendASCII(PR_ErrorToString(err, PR_LANGUAGE_EN)); 1.77 + returnedMessage.Append(NS_LITERAL_STRING("\n")); 1.78 + } 1.79 + 1.80 + if (nss_error_id_str) 1.81 + { 1.82 + nsresult rv; 1.83 + nsCString error_id(nss_error_id_str); 1.84 + ToLowerCase(error_id); 1.85 + NS_ConvertASCIItoUTF16 idU(error_id); 1.86 + 1.87 + const char16_t *params[1]; 1.88 + params[0] = idU.get(); 1.89 + 1.90 + nsString formattedString; 1.91 + rv = component->PIPBundleFormatStringFromName("certErrorCodePrefix", 1.92 + params, 1, 1.93 + formattedString); 1.94 + if (NS_SUCCEEDED(rv)) { 1.95 + returnedMessage.Append(NS_LITERAL_STRING("\n")); 1.96 + returnedMessage.Append(formattedString); 1.97 + returnedMessage.Append(NS_LITERAL_STRING("\n")); 1.98 + } 1.99 + else { 1.100 + returnedMessage.Append(NS_LITERAL_STRING("(")); 1.101 + returnedMessage.Append(idU); 1.102 + returnedMessage.Append(NS_LITERAL_STRING(")")); 1.103 + } 1.104 + } 1.105 + 1.106 + return NS_OK; 1.107 +}