Skip to content

Commit 614db2e

Browse files
committed
8328638: Fallback option for POST-only OCSP requests
Reviewed-by: mullan, rhalade
1 parent d292aab commit 614db2e

File tree

3 files changed

+83
-4
lines changed
  • src/java.base/share/classes/sun/security/provider/certpath
  • test/jdk

3 files changed

+83
-4
lines changed

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2024, 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
@@ -85,6 +85,28 @@ public final class OCSP {
8585
private static final int READ_TIMEOUT = initializeTimeout(
8686
"com.sun.security.ocsp.readtimeout", DEFAULT_READ_TIMEOUT);
8787

88+
/**
89+
* Boolean value indicating whether OCSP client can use GET for OCSP
90+
* requests. There is an ambiguity in RFC recommendations.
91+
*
92+
* RFC 5019 says a stronger thing, "MUST":
93+
* "When sending requests that are less than or equal to 255 bytes in
94+
* total (after encoding) including the scheme and delimiters (http://),
95+
* server name and base64-encoded OCSPRequest structure, clients MUST
96+
* use the GET method (to enable OCSP response caching)."
97+
*
98+
* RFC 6960 says a weaker thing, "MAY":
99+
* "HTTP-based OCSP requests can use either the GET or the POST method to
100+
* submit their requests. To enable HTTP caching, small requests (that
101+
* after encoding are less than 255 bytes) MAY be submitted using GET."
102+
*
103+
* For performance reasons, we default to stronger behavior. But this
104+
* option also allows to fallback to weaker behavior in case of compatibility
105+
* problems.
106+
*/
107+
private static final boolean USE_GET = initializeBoolean(
108+
"com.sun.security.ocsp.useget", "true");
109+
88110
/**
89111
* Initialize the timeout length by getting the OCSP timeout
90112
* system property. If the property has not been set, or if its
@@ -99,6 +121,15 @@ private static int initializeTimeout(String prop, int def) {
99121
return timeoutVal;
100122
}
101123

124+
private static boolean initializeBoolean(String prop, String def) {
125+
String flag = GetPropertyAction.privilegedGetProperty(prop, def);
126+
boolean value = Boolean.parseBoolean(flag);
127+
if (debug != null) {
128+
debug.println(prop + " set to " + value);
129+
}
130+
return value;
131+
}
132+
102133
private OCSP() {}
103134

104135
/**
@@ -186,7 +217,7 @@ public static byte[] getOCSPBytes(List<CertId> certIds, URI responderURI,
186217
encodedGetReq.append(URLEncoder.encode(
187218
Base64.getEncoder().encodeToString(bytes), UTF_8));
188219

189-
if (encodedGetReq.length() <= 255) {
220+
if (USE_GET && encodedGetReq.length() <= 255) {
190221
url = new URI(encodedGetReq.toString()).toURL();
191222
con = (HttpURLConnection)url.openConnection();
192223
con.setConnectTimeout(CONNECT_TIMEOUT);

test/jdk/java/security/cert/CertPathValidator/OCSP/GetAndPostTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, 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
@@ -23,14 +23,15 @@
2323

2424
/**
2525
* @test
26-
* @bug 8179503
26+
* @bug 8179503 8328638
2727
* @summary Java should support GET OCSP calls
2828
* @library /javax/net/ssl/templates /java/security/testlibrary
2929
* @build SimpleOCSPServer
3030
* @modules java.base/sun.security.util
3131
* java.base/sun.security.provider.certpath
3232
* java.base/sun.security.x509
3333
* @run main/othervm GetAndPostTests
34+
* @run main/othervm -Dcom.sun.security.ocsp.useget=false GetAndPostTests
3435
*/
3536

3637
import java.io.ByteArrayInputStream;

0 commit comments

Comments
 (0)