Skip to content

Commit d3f1fc6

Browse files
Fix "Empty input" when loading SSL_CERT_FILE/SSL_CERT_DIR cert bundles.
1 parent 5a41af5 commit d3f1fc6

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

api/src/main/java/io/minio/Http.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.security.KeyStoreException;
3838
import java.security.NoSuchAlgorithmException;
3939
import java.security.SecureRandom;
40+
import java.security.cert.Certificate;
4041
import java.security.cert.CertificateException;
4142
import java.security.cert.CertificateFactory;
4243
import java.security.cert.X509Certificate;
@@ -451,8 +452,7 @@ private static int setCertificateEntry(
451452
throws CertificateException, IOException, KeyStoreException {
452453
try (InputStream in = Files.newInputStream(file)) {
453454
int index = 0;
454-
while (in.available() > 0) {
455-
X509Certificate cert = (X509Certificate) cf.generateCertificate(in);
455+
for (Certificate cert : cf.generateCertificates(in)) {
456456
ks.setCertificateEntry(namePrefix + (index++), cert);
457457
}
458458
return index;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage,
3+
* (C) 2026 MinIO, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.minio;
19+
20+
import java.io.File;
21+
import java.nio.charset.StandardCharsets;
22+
import java.nio.file.Files;
23+
import java.util.Arrays;
24+
import java.util.Collection;
25+
import okhttp3.OkHttpClient;
26+
import org.junit.Assert;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
import org.junit.runners.Parameterized;
30+
import org.junit.runners.Parameterized.Parameter;
31+
import org.junit.runners.Parameterized.Parameters;
32+
33+
@RunWith(Parameterized.class)
34+
public class HttpExternalCertificatesTest {
35+
private static final String CERT =
36+
"-----BEGIN CERTIFICATE-----\n"
37+
+ "MIIC8TCCAdmgAwIBAgIIVQI5/aydlf4wDQYJKoZIhvcNAQEMBQAwJzElMCMGA1UE\n"
38+
+ "AxMcbWluaW8tamF2YS10ZXN0LWUwZWVmYWQwYjRiZTAeFw0yNjA2MDkwOTI4MDNa\n"
39+
+ "Fw0zNjA2MDYwOTI4MDNaMCcxJTAjBgNVBAMTHG1pbmlvLWphdmEtdGVzdC1lMGVl\n"
40+
+ "ZmFkMGI0YmUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2wswKet+8\n"
41+
+ "P0KEPycjP0cUeWtVuzwReMG4iMJxU80xg6rHzHW33tx89HEyhqBM0tAhnOlv8uyN\n"
42+
+ "dIlLQRKMNj2U82PW1DNfDqvahCqI1P5HEcqmHXYMXUIIuHQ42Vaq5Jw6LfUT5Xp3\n"
43+
+ "OskJuXsrqhJ/lI2tjO2IA6Ihq2qWH8HMK13usrRU8ercMi3v3l+NmE2v9cAYNjDn\n"
44+
+ "y+wE4TGIjxBnOcR7fSF6zcMydiu371FD53o3any47BGcjQrf11KuToMWCI6xRyox\n"
45+
+ "oRFif2heDNtPlm+sN7fLoz8RozLLN0GCT1+g3RfLDnbMOD/Zpl4JSSW+ZW43wrhH\n"
46+
+ "Kt+M32Wg1mvjAgMBAAGjITAfMB0GA1UdDgQWBBQc31QOSV+G44gzEaP0Nzki7+3j\n"
47+
+ "zDANBgkqhkiG9w0BAQwFAAOCAQEAbS1xk1KS7yflxFHcD0kdwaUi3y+zsD7JEqPo\n"
48+
+ "YtZsJB3YZF+7mCLcvpQpeOj/YjjS4Nfm+BTiBEm4iQ10XYJqq7Ld8+b37Lu0lUwq\n"
49+
+ "BEM05XdGqIy2ZElYLB4uwai/foAPqpASbtqfuF3k/r7Iv+vuLAcNDIZ95gpIbgyS\n"
50+
+ "1VezowSP4jSTlIISFhUlTJwD4sSA4FpdBs2JytjdQ+5bRbQPKC2lTRNUjDzIHWN0\n"
51+
+ "FcA+xu6MMlXe1EtVYSPPRoHnc/qBE0yEiyBglgqETxd1XUGuCZfCNSAICMafHtua\n"
52+
+ "DppeWJHfHv2CXNFva0iicwzYJ5kqoeJF8GAU3+QD0TMx59IfwA==\n"
53+
+ "-----END CERTIFICATE-----\n";
54+
55+
@Parameters(name = "{0}")
56+
public static Collection<Object[]> bundles() {
57+
return Arrays.asList(
58+
new Object[][] {
59+
{"single trailing newline", CERT},
60+
{"no trailing newline", CERT.trim()},
61+
{"trailing blank line", CERT + "\n"},
62+
{"trailing whitespace", CERT + " \n"},
63+
});
64+
}
65+
66+
@Parameter()
67+
public String name;
68+
69+
@Parameter(1)
70+
public String bundle;
71+
72+
@Test
73+
public void loadsExternalCertificateBundle() throws Exception {
74+
String path = writeBundle(bundle);
75+
OkHttpClient client = Http.enableExternalCertificates(new OkHttpClient(), path, null);
76+
Assert.assertNotNull(client);
77+
}
78+
79+
private static String writeBundle(String content) throws Exception {
80+
File file = File.createTempFile("minio-ca-bundle", ".pem");
81+
file.deleteOnExit();
82+
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8));
83+
return file.getAbsolutePath();
84+
}
85+
}

0 commit comments

Comments
 (0)