|
1 /* |
|
2 * Copyright (c) 1996, 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 * SSL/TLS record |
|
30 * |
|
31 * @author David Brownell |
|
32 */ |
|
33 interface SSLRecord extends Record { |
|
34 |
|
35 static final int headerSize = 5; // SSLv3 record header |
|
36 |
|
37 /* |
|
38 * The size of the header plus the max IV length |
|
39 */ |
|
40 static final int headerPlusMaxIVSize = |
|
41 headerSize // header |
|
42 + maxIVLength; // iv |
|
43 |
|
44 /* |
|
45 * The maximum size that may be increased when translating plaintext to |
|
46 * ciphertext fragment. |
|
47 */ |
|
48 static final int maxPlaintextPlusSize = |
|
49 headerSize // header |
|
50 + maxIVLength // iv |
|
51 + maxMacSize // MAC or AEAD tag |
|
52 + maxPadding; // block cipher padding |
|
53 |
|
54 /* |
|
55 * SSL has a maximum record size. It's header, (compressed) data, |
|
56 * padding, and a trailer for the message authentication information (MAC |
|
57 * for block and stream ciphers, and message authentication tag for AEAD |
|
58 * ciphers). |
|
59 * |
|
60 * Some compression algorithms have rare cases where they expand the data. |
|
61 * As we don't support compression at this time, leave that out. |
|
62 */ |
|
63 static final int maxRecordSize = |
|
64 headerPlusMaxIVSize // header + iv |
|
65 + maxDataSize // data |
|
66 + maxPadding // padding |
|
67 + maxMacSize; // MAC or AEAD tag |
|
68 |
|
69 /* |
|
70 * For CBC protection in SSL3/TLS1, we break some plaintext into two |
|
71 * packets. Max application data size for the second packet. |
|
72 */ |
|
73 static final int maxDataSizeMinusOneByteRecord = |
|
74 maxDataSize // max data size |
|
75 - ( // max one byte record size |
|
76 headerPlusMaxIVSize // header + iv |
|
77 + 1 // one byte data |
|
78 + maxPadding // padding |
|
79 + maxMacSize // MAC |
|
80 ); |
|
81 |
|
82 /* |
|
83 * The maximum large record size. |
|
84 * |
|
85 * Some SSL/TLS implementations support large fragment upto 2^15 bytes, |
|
86 * such as Microsoft. We support large incoming fragments. |
|
87 * |
|
88 * The maximum large record size is defined as maxRecordSize plus 2^14, |
|
89 * this is the amount OpenSSL is using. |
|
90 */ |
|
91 static final int maxLargeRecordSize = |
|
92 maxRecordSize // Max size with a conforming implementation |
|
93 + maxDataSize; // extra 2^14 bytes for large data packets. |
|
94 |
|
95 |
|
96 /* |
|
97 * Maximum record size for alert and change cipher spec records. |
|
98 * They only contain 2 and 1 bytes of data, respectively. |
|
99 * Allocate a smaller array. |
|
100 */ |
|
101 static final int maxAlertRecordSize = |
|
102 headerPlusMaxIVSize // header + iv |
|
103 + 2 // alert |
|
104 + maxPadding // padding |
|
105 + maxMacSize; // MAC |
|
106 |
|
107 /* |
|
108 * We may need to send this SSL v2 "No Cipher" message back, if we |
|
109 * are faced with an SSLv2 "hello" that's not saying "I talk v3". |
|
110 * It's the only one documented in the V2 spec as a fatal error. |
|
111 */ |
|
112 static final byte[] v2NoCipher = { |
|
113 (byte)0x80, (byte)0x03, // unpadded 3 byte record |
|
114 (byte)0x00, // ... error message |
|
115 (byte)0x00, (byte)0x01 // ... NO_CIPHER error |
|
116 }; |
|
117 } |