Я пытаюсь клонировать одно хранилище Bitbucket в мой локальный каталог с помощью кода Java. Тем не менее я получаю Причина: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: не найдено альтернативного DNS-имени субъекта, соответствующего cedt-gct-bitbucket.
Ниже приведен код для того же.
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.CloneCommand;
import java.io.File;
import java.nio.file.Paths;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class Checkout {
private TrustManager[] trustAllCerts;
private SSLContext sslContext;
public void setUp() throws Exception {
trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
if (certs.length != 1 || !certs[0].getIssuerX500Principal().getName()
.contains("CN=localhost")) {
throw new SecurityException("Invalid certificate");
}
}
}
};
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
}
public static void main(String[] args) {
Checkout co = new Checkout();
try {
co.setUp();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String repoUrl = "<------BITBUCKET REPOSITORY----->; //link for bit repo
String cloneDirectoryPath = "C:\\Users\\username\\TestFolder";
try {
System.out.println("Cloning "+repoUrl+" into "+repoUrl);
Git.cloneRepository()
.setURI(repoUrl)
.setDirectory(Paths.get(cloneDirectoryPath).toFile())
.call();
System.out.println("Completed Cloning");
} catch (GitAPIException e) {
System.out.println("Exception occurred while cloning repo");
e.printStackTrace();
}
}
}
Может кто-нибудь предложить?