Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/src/main/java/io/minio/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -451,8 +452,7 @@ private static int setCertificateEntry(
throws CertificateException, IOException, KeyStoreException {
try (InputStream in = Files.newInputStream(file)) {
int index = 0;
while (in.available() > 0) {
X509Certificate cert = (X509Certificate) cf.generateCertificate(in);
for (Certificate cert : cf.generateCertificates(in)) {
ks.setCertificateEntry(namePrefix + (index++), cert);
}
return index;
Expand Down
85 changes: 85 additions & 0 deletions api/src/test/java/io/minio/HttpExternalCertificatesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage,
* (C) 2026 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.minio;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collection;
import okhttp3.OkHttpClient;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class HttpExternalCertificatesTest {
private static final String CERT =
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ETxd1XUGuCZfCNSAICMafHtua\n"
+ "DppeWJHfHv2CXNFva0iicwzYJ5kqoeJF8GAU3+QD0TMx59IfwA==\n"
+ "-----END CERTIFICATE-----\n";

@Parameters(name = "{0}")
public static Collection<Object[]> bundles() {
return Arrays.asList(
new Object[][] {
{"single trailing newline", CERT},
{"no trailing newline", CERT.trim()},
{"trailing blank line", CERT + "\n"},
{"trailing whitespace", CERT + " \n"},
});
}

@Parameter()
public String name;

@Parameter(1)
public String bundle;

@Test
public void loadsExternalCertificateBundle() throws Exception {
String path = writeBundle(bundle);
OkHttpClient client = Http.enableExternalCertificates(new OkHttpClient(), path, null);
Assert.assertNotNull(client);
}

private static String writeBundle(String content) throws Exception {
File file = File.createTempFile("minio-ca-bundle", ".pem");
file.deleteOnExit();
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8));
return file.getAbsolutePath();
}
}
Loading