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