diff --git a/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java b/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java index 1ebe387b0f7df..9739c31142452 100644 --- a/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java +++ b/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java @@ -12,6 +12,7 @@ import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.util.SecurityUtils; import com.google.auth.oauth2.GoogleCredentials; import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.cloud.ServiceOptions; @@ -34,6 +35,7 @@ import java.net.HttpURLConnection; import java.net.URI; import java.net.URL; +import java.security.KeyStore; import java.util.Map; import static java.nio.charset.StandardCharsets.UTF_8; @@ -126,7 +128,11 @@ private Storage createClient(GoogleCloudStorageClientSettings clientSettings, final NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); // requires java.lang.RuntimePermission "setFactory" // Pin the TLS trust certificates. - builder.trustCertificates(GoogleUtils.getCertificateTrustStore()); + final KeyStore certTrustStore = SecurityUtils.getJavaKeyStore(); + try (InputStream keyStoreStream = GoogleUtils.class.getResourceAsStream("google.jks")) { + SecurityUtils.loadKeyStore(certTrustStore, keyStoreStream, "notasecret"); + } + builder.trustCertificates(certTrustStore); return builder.build(); }); diff --git a/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/SocketAccess.java b/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/SocketAccess.java index f6327e1ba44fd..287b70615840c 100644 --- a/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/SocketAccess.java +++ b/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/SocketAccess.java @@ -32,7 +32,7 @@ public static T doPrivilegedIOException(PrivilegedExceptionAction operati try { return AccessController.doPrivileged(operation); } catch (PrivilegedActionException e) { - throw (IOException) e.getCause(); + throw causeAsIOException(e); } } @@ -44,7 +44,18 @@ public static void doPrivilegedVoidIOException(CheckedRunnable acti return null; }); } catch (PrivilegedActionException e) { - throw (IOException) e.getCause(); + throw causeAsIOException(e); } } + + private static IOException causeAsIOException(PrivilegedActionException e) { + final Throwable cause = e.getCause(); + if (cause instanceof IOException) { + return (IOException) cause; + } + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } + throw new RuntimeException(cause); + } }