Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/DHKeyExchange/LegacyDHEKeyExchange.java
41152 views
1
/*
2
* Copyright (c) 2016, 2021, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
// SunJSSE does not support dynamic system properties, no way to re-use
25
// system properties in samevm/agentvm mode.
26
27
/*
28
* @test
29
* @bug 8148108
30
* @summary Disable Diffie-Hellman keys less than 1024 bits
31
* @library /javax/net/ssl/templates
32
* @run main/othervm -Djdk.tls.ephemeralDHKeySize=legacy LegacyDHEKeyExchange
33
*/
34
35
import javax.net.ssl.SSLHandshakeException;
36
import javax.net.ssl.SSLSocket;
37
import java.util.concurrent.CountDownLatch;
38
39
public class LegacyDHEKeyExchange extends SSLSocketTemplate{
40
41
private final CountDownLatch connDoneLatch = new CountDownLatch(2);
42
43
private static final int LINGER_TIMEOUT = 30; // in seconds
44
45
@Override
46
protected void runServerApplication(SSLSocket socket) throws Exception {
47
try {
48
super.runServerApplication(socket);
49
throw new Exception("Legacy DH keys (< 1024) should be restricted");
50
} catch (SSLHandshakeException she) {
51
String expectedExMsg = "Received fatal alert: insufficient_security";
52
if (!expectedExMsg.equals(she.getMessage())) {
53
throw she;
54
}
55
System.out.println("Expected exception thrown in server");
56
} finally {
57
connDoneLatch.countDown();
58
connDoneLatch.await();
59
}
60
}
61
62
@Override
63
protected void runClientApplication(SSLSocket socket) throws Exception {
64
String[] suites = new String [] {"TLS_DHE_RSA_WITH_AES_128_CBC_SHA"};
65
socket.setEnabledCipherSuites(suites);
66
socket.setSoLinger(true, LINGER_TIMEOUT);
67
68
try {
69
super.runClientApplication(socket);
70
throw new Exception("Legacy DH keys (< 1024) should be restricted");
71
} catch (SSLHandshakeException she) {
72
String expectedExMsg = "DH ServerKeyExchange does not comply to" +
73
" algorithm constraints";
74
if (!expectedExMsg.equals(she.getMessage())) {
75
throw she;
76
}
77
System.out.println("Expected exception thrown in client");
78
} finally {
79
connDoneLatch.countDown();
80
connDoneLatch.await();
81
}
82
}
83
84
public static void main(String[] args) throws Exception {
85
new LegacyDHEKeyExchange().run();
86
}
87
}
88
89