jdk/src/java.base/share/classes/sun/security/ssl/Record.java
author ascarpino
Wed, 08 Feb 2017 12:08:28 -0800
changeset 43701 fe8c324ba97c
parent 30904 ec0224270f90
permissions -rw-r--r--
8160655: Fix denyAfter and usage types for security properties Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
     2
 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    29
 * SSL/TLS/DTLS records, as pulled off (and put onto) a TCP stream.  This is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * the base interface, which defines common information and interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * used by both Input and Output records.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
interface Record {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    36
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /*
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    38
     * There are four record types, which are part of the interface
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    39
     * to this level (along with the maximum record size).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * enum { change_cipher_spec(20), alert(21), handshake(22),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     *      application_data(23), (255) } ContentType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static final byte   ct_change_cipher_spec = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static final byte   ct_alert = 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final byte   ct_handshake = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final byte   ct_application_data = 23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    49
    static final int    maxMacSize = 48;        // the max supported MAC or
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    50
                                                // AEAD tag size
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    51
    static final int    maxDataSize = 16384;    // 2^14 bytes of data
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    52
    static final int    maxPadding = 256;       // block cipher padding
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    53
    static final int    maxIVLength = 16;       // the max supported IV length
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    55
    static final int    maxFragmentSize = 18432;    // the max fragment size
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    56
                                                    // 2^14 + 2048
10915
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    57
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    58
    /*
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    59
     * System property to enable/disable CBC protection in SSL3/TLS1.
10915
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    60
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    61
    static final boolean enableCBCProtection =
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    62
            Debug.getBooleanProperty("jsse.enableCBCProtection", true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
14004
611031f93e76 7200295: CertificateRequest message is wrapping when using large numbers of Certs
xuelei
parents: 10915
diff changeset
    64
    /*
611031f93e76 7200295: CertificateRequest message is wrapping when using large numbers of Certs
xuelei
parents: 10915
diff changeset
    65
     * The overflow values of integers of 8, 16 and 24 bits.
611031f93e76 7200295: CertificateRequest message is wrapping when using large numbers of Certs
xuelei
parents: 10915
diff changeset
    66
     */
611031f93e76 7200295: CertificateRequest message is wrapping when using large numbers of Certs
xuelei
parents: 10915
diff changeset
    67
    static final int OVERFLOW_OF_INT08 = (1 << 8);
611031f93e76 7200295: CertificateRequest message is wrapping when using large numbers of Certs
xuelei
parents: 10915
diff changeset
    68
    static final int OVERFLOW_OF_INT16 = (1 << 16);
611031f93e76 7200295: CertificateRequest message is wrapping when using large numbers of Certs
xuelei
parents: 10915
diff changeset
    69
    static final int OVERFLOW_OF_INT24 = (1 << 24);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    70
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    71
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    72
     * Return a description for the given content type.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    73
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    74
    static String contentName(byte contentType) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    75
        switch (contentType) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    76
        case ct_change_cipher_spec:
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    77
            return "Change Cipher Spec";
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    78
        case ct_alert:
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    79
            return "Alert";
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    80
        case ct_handshake:
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    81
            return "Handshake";
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    82
        case ct_application_data:
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    83
            return "Application Data";
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    84
        default:
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    85
            return "contentType = " + contentType;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    86
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    87
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    88
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    89
    static boolean isValidContentType(byte contentType) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    90
        return (contentType == 20) || (contentType == 21) ||
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    91
               (contentType == 22) || (contentType == 23);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    92
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}