jdk/src/share/classes/sun/security/ssl/Record.java
author xuelei
Thu, 29 Sep 2011 17:31:30 -0700
changeset 10915 1e20964cebf3
parent 7039 6464c8e62a18
child 14004 611031f93e76
permissions -rw-r--r--
7064341: jsse/runtime security problem Reviewed-by: wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10915
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
     2
 * Copyright (c) 1996, 2011, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * SSL/TLS records, as pulled off (and put onto) a TCP stream.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * the base interface, which defines common information and interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * used by both Input and Output records.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
interface Record {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * There are four SSL record types, which are part of the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * to this level (along with the maximum record size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * enum { change_cipher_spec(20), alert(21), handshake(22),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     *      application_data(23), (255) } ContentType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static final byte   ct_change_cipher_spec = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final byte   ct_alert = 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final byte   ct_handshake = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static final byte   ct_application_data = 23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    50
    static final int    headerSize = 5;         // SSLv3 record header
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    51
    static final int    maxExpansion = 1024;    // for bad compression
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    52
    static final int    trailerSize = 20;       // SHA1 hash size
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    53
    static final int    maxDataSize = 16384;    // 2^14 bytes of data
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    54
    static final int    maxPadding = 256;       // block cipher padding
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    55
    static final int    maxIVLength = 256;      // block length
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * SSL has a maximum record size.  It's header, (compressed) data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * padding, and a trailer for the MAC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Some compression algorithms have rare cases where they expand the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * As we don't support compression at this time, leave that out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    63
    static final int    maxRecordSize =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                      headerSize        // header
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    65
                                    + maxIVLength       // iv
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                    + maxDataSize       // data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                    + maxPadding        // padding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                    + trailerSize;      // MAC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
10915
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    70
    static final boolean enableCBCProtection =
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    71
            Debug.getBooleanProperty("jsse.enableCBCProtection", true);
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    72
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    73
    /*
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    74
     * For CBC protection in SSL3/TLS1, we break some plaintext into two
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    75
     * packets.  Max application data size for the second packet.
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    76
     */
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    77
    static final int    maxDataSizeMinusOneByteRecord =
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    78
                                  maxDataSize       // max data size
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    79
                                - (                 // max one byte record size
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    80
                                      headerSize    // header
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    81
                                    + maxIVLength   // iv
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    82
                                    + 1             // one byte data
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    83
                                    + maxPadding    // padding
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    84
                                    + trailerSize   // MAC
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    85
                                  );
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7039
diff changeset
    86
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * The maximum large record size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Some SSL/TLS implementations support large fragment upto 2^15 bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * such as Microsoft. We support large incoming fragments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * The maximum large record size is defined as maxRecordSize plus 2^14,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * this is the amount OpenSSL is using.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    96
    static final int    maxLargeRecordSize =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                maxRecordSize   // Max size with a conforming implemenation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
              + maxDataSize;    // extra 2^14 bytes for large data packets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Maximum record size for alert and change cipher spec records.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * They only contain 2 and 1 bytes of data, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Allocate a smaller array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   106
    static final int    maxAlertRecordSize =
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   107
                                      headerSize        // header
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   108
                                    + maxIVLength       // iv
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   109
                                    + 2                 // alert
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   110
                                    + maxPadding        // padding
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   111
                                    + trailerSize;      // MAC
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}