1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.security.ssl; 27 28 /* 29 * enumation of record type 30 */ 31 enum RecordType { 32 33 RECORD_CHANGE_CIPHER_SPEC (Record.ct_change_cipher_spec, 34 HandshakeMessage.ht_not_applicable), 35 RECORD_ALERT (Record.ct_alert, 36 HandshakeMessage.ht_not_applicable), 37 RECORD_HELLO_REQUEST (Record.ct_handshake, 38 HandshakeMessage.ht_hello_request), 39 RECORD_CLIENT_HELLO (Record.ct_handshake, 40 HandshakeMessage.ht_client_hello), 41 RECORD_SERVER_HELLO (Record.ct_handshake, 42 HandshakeMessage.ht_server_hello), 43 RECORD_HELLO_VERIFY_REQUEST (Record.ct_handshake, 44 HandshakeMessage.ht_hello_verify_request), 45 RECORD_NEW_SESSION_TICKET (Record.ct_handshake, 46 HandshakeMessage.ht_new_session_ticket), 47 RECORD_CERTIFICATE (Record.ct_handshake, 48 HandshakeMessage.ht_certificate), 49 RECORD_SERVER_KEY_EXCHANGE (Record.ct_handshake, 50 HandshakeMessage.ht_server_key_exchange), 51 RECORD_CERTIFICATE_REQUEST (Record.ct_handshake, 52 HandshakeMessage.ht_certificate_request), 53 RECORD_SERVER_HELLO_DONE (Record.ct_handshake, 54 HandshakeMessage.ht_server_hello_done), 55 RECORD_CERTIFICATE_VERIFY (Record.ct_handshake, 56 HandshakeMessage.ht_certificate_verify), 57 RECORD_CLIENT_KEY_EXCHANGE (Record.ct_handshake, 58 HandshakeMessage.ht_client_key_exchange), 59 RECORD_FINISHED (Record.ct_handshake, 60 HandshakeMessage.ht_finished), 61 RECORD_CERTIFICATE_URL (Record.ct_handshake, 62 HandshakeMessage.ht_certificate_url), 63 RECORD_CERTIFICATE_STATUS (Record.ct_handshake, 64 HandshakeMessage.ht_certificate_status), 65 RECORD_SUPPLIEMENTAL_DATA (Record.ct_handshake, 66 HandshakeMessage.ht_supplemental_data), 67 RECORD_APPLICATION_DATA (Record.ct_application_data, 68 HandshakeMessage.ht_not_applicable); 69 70 byte contentType; 71 byte handshakeType; 72 73 private RecordType(byte contentType, byte handshakeType) { 74 this.contentType = contentType; 75 this.handshakeType = handshakeType; 76 } 77 78 static RecordType valueOf(byte contentType, byte handshakeType) { 79 if (contentType == Record.ct_change_cipher_spec) { 80 return RECORD_CHANGE_CIPHER_SPEC; 81 } else if (contentType == Record.ct_alert) { 82 return RECORD_ALERT; 83 } else if (contentType == Record.ct_application_data) { 84 return RECORD_APPLICATION_DATA; 85 } else if (handshakeType == HandshakeMessage.ht_hello_request) { 86 return RECORD_HELLO_REQUEST; 87 } else if (handshakeType == HandshakeMessage.ht_client_hello) { 88 return RECORD_CLIENT_HELLO; 89 } else if (handshakeType == HandshakeMessage.ht_server_hello) { 90 return RECORD_SERVER_HELLO; 91 } else if (handshakeType == HandshakeMessage.ht_hello_verify_request) { 92 return RECORD_HELLO_VERIFY_REQUEST; 93 } else if (handshakeType == HandshakeMessage.ht_new_session_ticket) { 94 return RECORD_NEW_SESSION_TICKET; 95 } else if (handshakeType == HandshakeMessage.ht_certificate) { 96 return RECORD_CERTIFICATE; 97 } else if (handshakeType == HandshakeMessage.ht_server_key_exchange) { 98 return RECORD_SERVER_KEY_EXCHANGE; 99 } else if (handshakeType == HandshakeMessage.ht_certificate_request) { 100 return RECORD_CERTIFICATE_REQUEST; 101 } else if (handshakeType == HandshakeMessage.ht_server_hello_done) { 102 return RECORD_SERVER_HELLO_DONE; 103 } else if (handshakeType == HandshakeMessage.ht_certificate_verify) { 104 return RECORD_CERTIFICATE_VERIFY; 105 } else if (handshakeType == HandshakeMessage.ht_client_key_exchange) { 106 return RECORD_CLIENT_KEY_EXCHANGE; 107 } else if (handshakeType == HandshakeMessage.ht_finished) { 108 return RECORD_FINISHED; 109 } else if (handshakeType == HandshakeMessage.ht_certificate_url) { 110 return RECORD_CERTIFICATE_URL; 111 } else if (handshakeType == HandshakeMessage.ht_certificate_status) { 112 return RECORD_CERTIFICATE_STATUS; 113 } else if (handshakeType == HandshakeMessage.ht_supplemental_data) { 114 return RECORD_SUPPLIEMENTAL_DATA; 115 } 116 117 // otherwise, invalid record type 118 throw new IllegalArgumentException( 119 "Invalid record type (ContentType:" + contentType + 120 ", HandshakeType:" + handshakeType + ")"); 121 } 122 }