Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] git clone via secured connection

-----Original Message-----
From: jgit-dev-bounces@xxxxxxxxxxx [mailto:jgit-dev-bounces@xxxxxxxxxxx] On Behalf Of nappel
Sent: Freitag, 1. März 2013 05:09
To: jgit-dev
Subject: Re: [jgit-dev] git clone via secured connection

> Thanks for your reply.
> On 01.03.2013 04:18, Shawn Pearce wrote:
>>> And my code:
>>> public class CustomJschConfigSessionFactory extends JschConfigSessionFactory
>>> {
>>>    @Override
>>>    protected void configure(OpenSshConfig.Host host, Session session) {
>>>        session.setConfig("StrictHostKeyChecking", "no");
>>>    }
>>> }
>>> The settings and clonging part:
>>> CloneCommand clone = git.cloneRepository();
>>>       try {
>>>           CustomJschConfigSessionFactory jschConfigSessionFactory = new
>>> CustomJschConfigSessionFactory();
>>>           JSch jsch = new JSch();
>>>           jsch.addIdentity(pathToKey);
>>>           SshSessionFactory.setInstance(jschConfigSessionFactory);
>> This key is not connected to the objects JGit is using... which is
>> probably why you are getting an authentication failure. Don't you need
>> to add the key inside of the jschConfigSessionFactory?
> I can't find any possibility in the javadoc of jsch, it's only possible 
> to configure the session. But the session doesn't hold the keys, the are 
> managed by the Jsch object. You are right, Iam adding the keys to an 
> unrelated instance of Jsch.
> I only have to figure out how to do this with the 
> jschConfigSessionFactory, should get some sleep first.
> Maybe someone has an idea how this can be properbly handled?
Not sure this is the best way, but you may give it a try:

    final Properties config = new Properties();
    config.put("StrictHostKeyChecking", "no");

    // register a JschConfigSessionFactory that adds the private key as identity
    // to the JSch instance of JGit so that SSH communication via JGit can
    // succeed
    SshSessionFactory.setInstance(new JschConfigSessionFactory() {
      protected void configure(Host hc, Session session) {
        try {
          final JSch jsch = getJSch(hc, FS.DETECTED);
          jsch.addIdentity("KeyPair", a.privateKey(),
              a.sshKey.getPublicKeyBlob(), null);
        } catch (JSchException e) {
          throw new RuntimeException(e);

> Thanks in advance,
> Flask

jgit-dev mailing list

Back to the top