Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for insecure TLS while deploying to TIBCO Platform when using Self-Signed Certificate #732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Map;

import javax.net.ssl.*;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
Expand Down Expand Up @@ -70,7 +74,35 @@ public void buildApp(String application, String earPath, String buildName, Strin
File ear = new File(earPath);
this.log.debug("EarLocation : " + earPath + ", EarFile : "+ ear.getName());

Client client = ClientBuilder.newClient();

String tlsInsecure = System.getProperty("com.tibco.platform.tls.insecure");
ClientBuilder builder = ClientBuilder.newBuilder();
if(tlsInsecure != null && "true".equalsIgnoreCase(tlsInsecure)){
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}

public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}

public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sc = SSLContext.getInstance("SSL");

HostnameVerifier allHostValid = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};

sc.init(null, new X509TrustManager[]{tm}, new SecureRandom());
builder.sslContext(sc).hostnameVerifier(allHostValid);
}

Client client = builder.build();
webTarget = client.target(new URI(dpUrl));
webTarget.register(MultiPartFeature.class);

Expand Down