Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] SSH Gerrit key with JGit

Hey again,

Well, answering my own plight I figured out a way to ensure that JGIT is always using the current key present in the home/.ssh folder. I created a class that inherits from JschConfigSessionFactory and overrode the getJSch method such that I intercepted the result from the super.getJSch to remove all identities present and retrieve the private key present in home/.ssh folder with the addIdentity method. Then it was only a matter of setting the instance of the SshSessionFactory with its setInstance method to my custom class and it worked like a charm.

Not sure if this is the most elegant or even correct way to do this, but it works ok.

Cheers, 
Itzack

On Tue, Dec 20, 2011 at 8:47 AM, Itzack <itzack@xxxxxxxxx> wrote:
Hi,

So I ran into a weird problem these days. I have an app that uses Jgit high level API to perform GIT commands. Recently Gerrit has also come into play and with it the need to register the public SSH key, which is all fine. The problem arises if I start the application without any key generated in my .ssh directory. As expected an exception is thrown which is correctly treated informing me I have to generate the key and register on Gerrit. I also have a Retry button in this window, meaning the application does not close when this happens. So, if I create the key and register it on Gerrit and then hit "Retry" I still get an Auth fail exception. But if I do close the app and simply start again it works like a charm.

My guess is that the SSH session used in the first try to clone the repo is the same being used on subsequent tries and therefore it has not refreshed the status of the private/public key pair. I think I even managed to confirm this by checking the SSHSessionFactory before and after. So my question is, is there a way to tell JGit to refresh the JSch session for it to retrieve the new key generated? Or am I completely out of line and the problem is something else entirely?

Cheers,
Itzack

--
              (-.(-.(-.(-.-).-).-).-)
---------------------------------------------------
The Chinese mafia is watching you!




--
              (-.(-.(-.(-.-).-).-).-)
---------------------------------------------------
The Chinese mafia is watching you!


Back to the top