Skip to content

Commit f8e81d2

Browse files
author
Jamil Nimeh
committed
8347506: Compatible OCSP readtimeout property with OCSP timeout
Reviewed-by: mullan, hchao
1 parent 907350e commit f8e81d2

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

src/java.base/share/classes/sun/security/provider/certpath/OCSP.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -67,7 +67,6 @@ public final class OCSP {
6767
private static final Debug debug = Debug.getInstance("certpath");
6868

6969
private static final int DEFAULT_CONNECT_TIMEOUT = 15000;
70-
private static final int DEFAULT_READ_TIMEOUT = 15000;
7170

7271
/**
7372
* Integer value indicating the timeout length, in milliseconds, to be
@@ -83,7 +82,7 @@ public final class OCSP {
8382
* zero is interpreted as an infinite timeout.
8483
*/
8584
private static final int READ_TIMEOUT = initializeTimeout(
86-
"com.sun.security.ocsp.readtimeout", DEFAULT_READ_TIMEOUT);
85+
"com.sun.security.ocsp.readtimeout", CONNECT_TIMEOUT);
8786

8887
/**
8988
* Boolean value indicating whether OCSP client can use GET for OCSP
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2025, 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+
/*
25+
* @test
26+
* @bug 8347506
27+
* @summary Compatible OCSP readtimeout property with OCSP timeout
28+
* @modules java.base/sun.security.provider.certpath
29+
* @run main/othervm
30+
* --add-opens java.base/sun.security.provider.certpath=ALL-UNNAMED
31+
* OCSPReadTimeoutDefault 15000
32+
* @run main/othervm
33+
* --add-opens java.base/sun.security.provider.certpath=ALL-UNNAMED
34+
* -Dcom.sun.security.ocsp.timeout=6
35+
* OCSPReadTimeoutDefault 6000
36+
* @run main/othervm
37+
* --add-opens java.base/sun.security.provider.certpath=ALL-UNNAMED
38+
* -Dcom.sun.security.ocsp.timeout=6 -Dcom.sun.security.ocsp.readtimeout=1
39+
* OCSPReadTimeoutDefault 1000
40+
*/
41+
42+
import java.lang.reflect.*;
43+
44+
public class OCSPReadTimeoutDefault {
45+
46+
public static void main(String[] args) throws Exception {
47+
if (args == null || args.length < 1) {
48+
throw new RuntimeException("Missing mandatory readtimeout value");
49+
}
50+
51+
int expectedReadTimeout = Integer.parseInt(args[0]);
52+
53+
Class<?> ocspClazz = sun.security.provider.certpath.OCSP.class;
54+
System.out.println("OCSP Class: " + ocspClazz);
55+
56+
Field cto = ocspClazz.getDeclaredField("CONNECT_TIMEOUT");
57+
Field rto = ocspClazz.getDeclaredField("READ_TIMEOUT");
58+
cto.setAccessible(true);
59+
rto.setAccessible(true);
60+
int ctoVal = cto.getInt(null);
61+
int rtoVal = rto.getInt(null);
62+
63+
System.out.println("Expected read timeout: " + expectedReadTimeout);
64+
System.out.println("CTOVal: " + ctoVal + ", RTOVal: " + rtoVal);
65+
if (rtoVal != expectedReadTimeout) {
66+
throw new RuntimeException("Expected read timeout value of " +
67+
expectedReadTimeout + ", found " + rtoVal);
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)