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 );
0 commit comments