2
|
1 |
/*
|
56542
|
2 |
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.security.ssl;
|
|
27 |
|
|
28 |
import java.io.*;
|
56542
|
29 |
import java.nio.ByteBuffer;
|
2
|
30 |
import java.security.SecureRandom;
|
56542
|
31 |
import java.util.Arrays;
|
2
|
32 |
|
|
33 |
/*
|
|
34 |
* RandomCookie ... SSL hands standard format random cookies (nonces)
|
|
35 |
* around. These know how to encode/decode themselves on SSL streams,
|
|
36 |
* and can be created and printed.
|
|
37 |
*
|
|
38 |
* @author David Brownell
|
|
39 |
*/
|
|
40 |
final class RandomCookie {
|
56542
|
41 |
final byte[] randomBytes = new byte[32]; // exactly 32 bytes
|
2
|
42 |
|
56542
|
43 |
private static final byte[] hrrRandomBytes = new byte[] {
|
|
44 |
(byte)0xCF, (byte)0x21, (byte)0xAD, (byte)0x74,
|
|
45 |
(byte)0xE5, (byte)0x9A, (byte)0x61, (byte)0x11,
|
|
46 |
(byte)0xBE, (byte)0x1D, (byte)0x8C, (byte)0x02,
|
|
47 |
(byte)0x1E, (byte)0x65, (byte)0xB8, (byte)0x91,
|
|
48 |
(byte)0xC2, (byte)0xA2, (byte)0x11, (byte)0x16,
|
|
49 |
(byte)0x7A, (byte)0xBB, (byte)0x8C, (byte)0x5E,
|
|
50 |
(byte)0x07, (byte)0x9E, (byte)0x09, (byte)0xE2,
|
|
51 |
(byte)0xC8, (byte)0xA8, (byte)0x33, (byte)0x9C
|
|
52 |
};
|
|
53 |
|
|
54 |
private static final byte[] t12Protection = new byte[] {
|
|
55 |
(byte)0x44, (byte)0x4F, (byte)0x57, (byte)0x4E,
|
|
56 |
(byte)0x47, (byte)0x52, (byte)0x44, (byte)0x01
|
|
57 |
};
|
|
58 |
|
|
59 |
private static final byte[] t11Protection = new byte[] {
|
|
60 |
(byte)0x44, (byte)0x4F, (byte)0x57, (byte)0x4E,
|
|
61 |
(byte)0x47, (byte)0x52, (byte)0x44, (byte)0x01
|
|
62 |
};
|
|
63 |
|
|
64 |
static final RandomCookie hrrRandom = new RandomCookie(hrrRandomBytes);
|
2
|
65 |
|
|
66 |
RandomCookie(SecureRandom generator) {
|
56542
|
67 |
generator.nextBytes(randomBytes);
|
2
|
68 |
}
|
|
69 |
|
56542
|
70 |
RandomCookie(ByteBuffer m) throws IOException {
|
|
71 |
m.get(randomBytes);
|
|
72 |
}
|
|
73 |
|
|
74 |
private RandomCookie(byte[] randomBytes) {
|
|
75 |
System.arraycopy(randomBytes, 0, this.randomBytes, 0, 32);
|
|
76 |
}
|
|
77 |
|
|
78 |
@Override
|
|
79 |
public String toString() {
|
|
80 |
return "random_bytes = {" + Utilities.toHexString(randomBytes) + "}";
|
2
|
81 |
}
|
|
82 |
|
56542
|
83 |
boolean isHelloRetryRequest() {
|
|
84 |
return Arrays.equals(hrrRandomBytes, randomBytes);
|
|
85 |
}
|
|
86 |
|
|
87 |
boolean isT12Downgrade() {
|
|
88 |
return Arrays.equals(hrrRandomBytes, 24, 31, t12Protection, 0, 7);
|
|
89 |
}
|
|
90 |
|
|
91 |
boolean isT11Downgrade() {
|
|
92 |
return Arrays.equals(hrrRandomBytes, 24, 31, t11Protection, 0, 7);
|
2
|
93 |
}
|
|
94 |
}
|