/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* A simple class to congregate alerts, their definitions, and common
* support methods.
*/
final class Alerts {
/*
* Alerts are always a fixed two byte format (level/description).
*/
// warnings and fatal errors are package private facilities/constants
// Alert levels (enum AlertLevel)
/*
* Alert descriptions (enum AlertDescription)
*
* We may not use them all in our processing, but if someone
* sends us one, we can at least convert it to a string for the
* user.
*/
// from RFC 3546 (TLS Extensions)
switch (code) {
case alert_close_notify:
return "close_notify";
case alert_unexpected_message:
return "unexpected_message";
case alert_bad_record_mac:
return "bad_record_mac";
case alert_decryption_failed:
return "decryption_failed";
case alert_record_overflow:
return "record_overflow";
return "decompression_failure";
case alert_handshake_failure:
return "handshake_failure";
case alert_no_certificate:
return "no_certificate";
case alert_bad_certificate:
return "bad_certificate";
return "unsupported_certificate";
return "certificate_revoked";
return "certificate_expired";
return "certificate_unknown";
case alert_illegal_parameter:
return "illegal_parameter";
case alert_unknown_ca:
return "unknown_ca";
case alert_access_denied:
return "access_denied";
case alert_decode_error:
return "decode_error";
case alert_decrypt_error:
return "decrypt_error";
case alert_export_restriction:
return "export_restriction";
case alert_protocol_version:
return "protocol_version";
return "insufficient_security";
case alert_internal_error:
return "internal_error";
case alert_user_canceled:
return "user_canceled";
case alert_no_renegotiation:
return "no_renegotiation";
return "unsupported_extension";
return "certificate_unobtainable";
case alert_unrecognized_name:
return "unrecognized_name";
return "bad_certificate_status_response";
return "bad_certificate_hash_value";
default:
}
}
}
/*
* Try to be a little more specific in our choice of
* exceptions to throw.
*/
SSLException e;
// the SSLException classes do not have a no-args constructor
// make up a message if there is none
} else {
reason = "";
}
}
switch (description) {
case alert_handshake_failure:
case alert_no_certificate:
case alert_bad_certificate:
case alert_unknown_ca:
case alert_access_denied:
case alert_decrypt_error:
case alert_export_restriction:
case alert_unrecognized_name:
e = new SSLHandshakeException(reason);
break;
case alert_close_notify:
case alert_unexpected_message:
case alert_bad_record_mac:
case alert_decryption_failed:
case alert_record_overflow:
case alert_illegal_parameter:
case alert_decode_error:
case alert_protocol_version:
case alert_internal_error:
case alert_user_canceled:
case alert_no_renegotiation:
default:
e = new SSLException(reason);
break;
}
}
return e;
}
}