I tried your example but its the same like before.
try {
final Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
JSch.setConfig(config);
// 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() {
@Override
protected void configure(Host hc, Session session) {
try {
UserInfo userinfo = new MyUserInfo();
session.setUserInfo(userinfo);
final JSch jsch = getJSch(hc, FS.DETECTED);
jsch.addIdentity(pathToKey);
} catch (JSchException e) {
throw new RuntimeException(e);
}
}
});
public class MyUserInfo implements UserInfo, UIKeyboardInteractive {
@Override
public String getPassphrase() {
return null;
}
@Override
public String getPassword() {
return null;
}
@Override
public boolean promptPassphrase(String arg0) {
return false;
}
@Override
public boolean promptPassword(String arg0) {
return false;
}
@Override
public boolean promptYesNo(String arg0) {
return false;
}
@Override
public void showMessage(String arg0) {
}
@Override
public String[] promptKeyboardInteractive(String arg0, String arg1,
String arg2, String[] arg3, boolean[] arg4) {
return null;
}
}
Maybe its a fault of my settings so I simply generated some new keys
with ssh-keygen -t rsa and copied both on the android device, and
the public key on the server and set write access for the new keys
(using gitosis). That didn't helped also. I only modified
jsch.addIdentity("KeyPair", a.privateKey(),
a.sshKey.getPublicKeyBlob(), null);
to
jsch.addIdentity(pathToKey);
To call addIdentity with this signature
public void addIdentity(String prvkey) throws
JSchException
And provided a UserInfo, because some people wrote at stackoverflow,
that they got the Auth failed without providing it.
Thanks in advance,
Flask
|