3

I am trying to clone from a repository with JGit.

`public class DevJgit {

    public static void main( String[] args ) throws IOException, IllegalStateException, GitAPIException
    {

           String name = "name";
           String password = "password";
           String REMOTE_URL = "https://mycompany.com/stash/pci/devcode.git";

           // credentials
           CredentialsProvider cp = new UsernamePasswordCredentialsProvider(name, password);


            File localPath = File.createTempFile("JavaTemp", "");
            if(!localPath.delete()) {
                throw new IOException("Could not delete temporary file " + localPath);
            }

            System.setProperty("javax.net.ssl.trustStore","cacerts.jks");
            //someone suggested me to add above code and add a certificate to truststore
              System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
              Git result = Git.cloneRepository()
                    .setURI(REMOTE_URL)
                    .setDirectory(localPath)
                    .setCredentialsProvider(cp)
                    .call();    


}

}`

This is first time i am working on JGit as well as https/javassl etc. As commented above i have set the system property line and i was trying to add a certificate to truststore(Not sure if this is what i have to do).

And these are the exceptions i received:

`

 Cloning from https://mycompany.com/stash/pci/devcode.git to /var/folders/g3/xxyghgcj6xqfy8vv74t06x99wgqqsy/T/JavaTemp5733960388741621840
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: https://mycompany.com/stash/scm/pci/devcode.git: cannot open git-upload-pack
    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:135)
    at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:203)
    at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:136)
    at com.mastercard.dev.JgitProject.DevportalJgit.main(DevcodeJgit.java:36)
Caused by: org.eclipse.jgit.errors.TransportException: https://fusion.mastercard.com/stash/scm/api/devportal.git: cannot open git-upload-pack
    at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:551)
    at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:311)
    at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
    at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
    at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1201)
    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)
    ... 3 more
Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1906)
    at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1889)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1410)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
    at org.eclipse.jgit.transport.http.JDKHttpConnection.getResponseCode(JDKHttpConnection.java:98)
    at org.eclipse.jgit.util.HttpSupport.response(HttpSupport.java:196)
    at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:489)
    ... 8 more
Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:90)
    at sun.security.validator.Validator.getInstance(Validator.java:179)
    at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:312)
    at sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:171)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:184)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
    ... 18 more
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:200)
    at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:120)
    at java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:104)
    at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:88)
    ... 30 more
`

First, Is this because of my Jgit application not having any kind certificate or any other reason? Second, If I need to add certificate, Is that something i should get from myCompany? Third, If i have that certificate where should i add in code as well as localpath for my JGit application to recognise?

Finally, I got a two suggestion: 1. add certificate of repo to JGit application(which i am not sure). 2. find what is JGit Httpclient and try to configure it(which i didnt understand what he means).

Please forgive this amateur for typos and vagueness if any

Thanks.

0 Answers0