Skip to content

Commit

Permalink
Different logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh committed Jul 27, 2018
1 parent 557af8f commit 6df4b42
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.cloud.tools.jib.registry.json.ErrorEntryTemplate;
import com.google.cloud.tools.jib.registry.json.ErrorResponseTemplate;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -135,18 +136,28 @@ T call() throws IOException, RegistryException {

@Nullable
private T callWithAllowInsecureRegistryHandling(URL url) throws IOException, RegistryException {
if (allowInsecureRegistries) {
return possbilyInsecureCall(url);
}

try {
if (!isHttpsProtocol(url) && !allowInsecureRegistries) {
if (!isHttpsProtocol(url)) {
throw new InsecureRegistryException(url);
}
return call(url, connectionFactory);
} catch (SSLPeerUnverifiedException ex) {
throw new InsecureRegistryException(url);
}
}

@Nullable
private T possbilyInsecureCall(URL url) throws IOException, RegistryException {
Preconditions.checkState(allowInsecureRegistries);
try {
return call(url, connectionFactory);

} catch (SSLPeerUnverifiedException exception) {
try {
// Cannot verify the server (e.g., self-signed certificate or plain HTTP).
if (!allowInsecureRegistries) {
throw new InsecureRegistryException(url);
}
if (insecureConnectionFactory == null) {
insecureConnectionFactory = Connection.getInsecureConnectionFactory();
}
Expand Down

0 comments on commit 6df4b42

Please sign in to comment.