0

I'm trying to list branches in a remote git server via my java application, im using jgit org.eclipse.jgit-3.7.0.201502260915-r.jar but when i run i have ans ssl exception, i want to customize mu git connection to disable sslVerify

 public List<String> GetProductBranches(String prductUrl) throws IOException {
        List<String> versions = new ArrayList<String>();
        System.out.println("User: " + this.gitUser);
        System.out.println("Pwd: " + this.gitPwd);
        String gitPrductUrl="https://"+this.gitUser+"@"+prductUrl;

        System.out.println("Pwd: " + gitPrductUrl);

  try {
        Collection<Ref> remoteRefs = Git.lsRemoteRepository()
                      .setHeads(false)
                      .setTags(false)
                      .setRemote(gitPrductUrl)
                      .setCredentialsProvider(new UsernamePasswordCredentialsProvider(this.gitUser, this.gitPwd))
                      .call();
              for( Ref ref : remoteRefs ) {
                    if (ref.getName().contains("refs/heads/"))
                    {
                          System.out.println("Ref: " + ref.getName().replace("refs/heads/", ""));
                          versions.add(ref.getName().replace("refs/heads/", ""));
                    }
              }
        } catch (GitAPIException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
        }
  return versions;

  }

this is the exception

`org.eclipse.jgit.api.errors.TransportException: https://***.git: cannot open git-upload-pack
        at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:223)
        at org.eclipse.jgit.api.LsRemoteCommand.call(LsRemoteCommand.java:159)
        at testGit.Authenticate.GetProductBranches(Authenticate.java:69)
        at testGit.Authenticate.main(Authenticate.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: org.eclipse.jgit.errors.TransportException: https://T***.git: cannot open git-upload-pack
        at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:524)
        at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:309)
        at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:202)
        ... 8 more
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
        at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1961)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1077)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:515)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1299)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
        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:168)
        at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:475)
        ... 10 more`
  • 1
    I think this has been answered here: https://stackoverflow.com/questions/33998477/turn-ssl-verification-off-for-jgit-clone-command. BTW, you are using a fairly old version of JGit, I recommend upgrading to a more reecent version. – Rüdiger Herrmann Feb 25 '19 at 15:50
  • i have to use this version because it s the only one compatible with my tomcat, actually i have customized the conf as mentioned in the answer you recommanded to me and even make config setted from a local file but always i have the same problem, – moncef nsiri Feb 25 '19 at 16:01
  • in fact it works in my windows 10 machine with java 8 , but when i run it in centos7 vm it shows this exception – moncef nsiri Feb 25 '19 at 16:02
  • Perhaps, the `http.sslVerify` setting is disabled on Windows but not on CentOS. Did you check the repository-, user and system-config? – Rüdiger Herrmann Feb 25 '19 at 16:12
  • how to disable http.sslVerify on centos7? – moncef nsiri Feb 25 '19 at 16:16
  • To see if this is the source of the problem, you can try to disable http.`sslVerify` 'globally' through native Git . See https://git-scm.com/docs/git-config – Rüdiger Herrmann Feb 25 '19 at 20:32
  • thanks for your reply but i don't have git on the machine i only have a java application which uses Jgit,but i have this ssl Exception even though i disabled sslVerify in Storedconfig: StoredConfig config = git.getRepository().getConfig(); config.setBoolean( "http", null, "sslVerify", false ); config.save(); – moncef nsiri Feb 26 '19 at 09:39
  • The `LsRemoteCommand` as you use it is not connected to a local repository, hence the config changes are without effect. If you have a local repository that corresponds to the one you are listing remotes then use `git.lsRemote()`. This way, the config of the repository associated with `git` is taken into account. – Rüdiger Herrmann Feb 26 '19 at 13:20
  • Problem solved by changing JDK used in my tomcat server to 1.8 – moncef nsiri Feb 28 '19 at 16:37

0 Answers0