@Override protected Session createSession(Host hc, String user, String host, int port, FS fs) throws JSchException { if (sshKeysByHostname.containsKey(host)) { JGitEnvironmentProperties sshUriProperties = sshKeysByHostname.get(host); jSch.addIdentity(host, sshUriProperties.getPrivateKey().getBytes(), null, null); if (sshUriProperties.getKnownHostsFile() != null) { jSch.setKnownHosts(sshUriProperties.getKnownHostsFile()); } if (sshUriProperties.getHostKey() != null) { HostKey hostkey = new HostKey(host, Base64.decode(sshUriProperties.getHostKey())); jSch.getHostKeyRepository().add(hostkey, null); } return jSch.getSession(user, host, port); } throw new JSchException("no keys configured for hostname " + host); }
public String getType() { return key.getType(); }
for (HostKey aPool : pool) { hk = aPool; String marker = hk.getMarker(); String host = hk.getHost(); String type = hk.getType(); String comment = hk.getComment(); if (type.equals("UNKNOWN")) { out.write(Util.str2byte(host)); out.write(Util.str2byte(type)); out.write(space); out.write(Util.str2byte(hk.getKey())); if (comment != null) { out.write(space);
public void remove(String host, String type, byte[] key){ boolean sync=false; synchronized(pool){ for(int i=0; i<pool.size(); i++){ HostKey hk=(HostKey)(pool.elementAt(i)); if(host==null || (hk.isMatched(host) && (type==null || (hk.getType().equals(type) && (key==null || Util.array_equals(key, hk.key)))))){ String hosts=hk.getHost(); if(hosts.equals(host) || ((hk instanceof HashedHostKey) && ((HashedHostKey)hk).isHashed())){ pool.removeElement(hk); } else{ hk.host=deleteSubString(hosts, host); } sync=true; } } } if(sync){ try{sync();}catch(Exception e){}; } }
void dump(OutputStream out) throws IOException { try{ HostKey hk; synchronized(pool){ for(int i=0; i<pool.size(); i++){ hk=(HostKey)(pool.elementAt(i)); //hk.dump(out); String host=hk.getHost(); String type=hk.getType(); if(type.equals("UNKNOWN")){ out.write(host.getBytes()); out.write(cr); continue; } out.write(host.getBytes()); out.write(space); out.write(type.getBytes()); out.write(space); out.write(hk.getKey().getBytes()); out.write(cr); } } } catch(Exception e){ System.err.println(e); } } private int getType(byte[] key){
hostkey = ((KnownHosts) hkr).createHashedHostKey(chost, K_S); } else { hostkey = new HostKey(chost, K_S); String _key = Util.byte2str(Util.toBase64(K_S, 0, K_S.length)); for (HostKey key : keys) { if (keys[i].getKey().equals(_key) && key.getMarker().equals("@revoked")) { if (userinfo != null) { userinfo.showMessage(
public int check(String host, byte[] key) { int result = NOT_INCLUDED; if (host == null) { return result; } HostKey hk; try { hk = new HostKey(host, HostKey.GUESS, key); } catch (JSchException e) { return result; } synchronized (pool) { for (HostKey _hk : pool) { if (_hk.isMatched(host) && _hk.type == hk.type) { if (Util.array_equals(_hk.key, key)) { return OK; } else { result = CHANGED; } } } } if (result == NOT_INCLUDED && host.startsWith("[") && host.indexOf("]:") > 1 ) { return check(host.substring(1, host.indexOf("]:")), key); } return result; }
public HostKey[] getHostKey(String host, String type){ synchronized(pool){ int count=0; for(int i=0; i<pool.size(); i++){ HostKey hk=(HostKey)pool.elementAt(i); if(hk.type==HostKey.UNKNOWN) continue; if(host==null || (hk.isMatched(host) && (type==null || hk.getType().equals(type)))){ count++; } } if(count==0)return null; HostKey[] foo=new HostKey[count]; int j=0; for(int i=0; i<pool.size(); i++){ HostKey hk=(HostKey)pool.elementAt(i); if(hk.type==HostKey.UNKNOWN) continue; if(host==null || (hk.isMatched(host) && (type==null || hk.getType().equals(type)))){ foo[j++]=hk; } } return foo; } } public void remove(String host, String type){
log.debug("Host keys in {}", hkr.getKnownHostsRepositoryID()); for (HostKey hk : hks) { log.trace("Loaded host key {} {} {}", hk.getHost(), hk.getType(), hk.getFingerPrint(jsch));
public String getHost() { return key.getHost(); }
public boolean hasSameFingerprint(String pubkey, String fingerprint) { try { byte[] pubKeyDecoded = Base64.getDecoder().decode(pubkey.getBytes()); HostKey hk; hk = new HostKey(HOST, pubKeyDecoded); String pubkeyFingerprint = hk.getFingerPrint(new JSch()); return fingerprint.equals(pubkeyFingerprint); } catch (JSchException e) { log.warn(e.getMessage()); return false; } }
public int check(String host, byte[] key){ int result=NOT_INCLUDED; if(host==null){ return result; } int type=getType(key); HostKey hk; synchronized(pool){ for(int i=0; i<pool.size(); i++){ hk=(HostKey)(pool.elementAt(i)); if(hk.isMatched(host) && hk.type==type){ if(Util.array_equals(hk.key, key)){ //System.err.println("find!!"); return OK; } else{ result=CHANGED; } } } } //System.err.println("fail!!"); return result; } public void add(HostKey hostkey, UserInfo userinfo){
public byte[] getKey() { try { Method m = Class.forName("com.jcraft.jsch.Util").getDeclaredMethod("fromBase64", new Class[] { byte[].class, int.class, int.class }); m.setAccessible(true); return (byte[]) m.invoke(null, new Object[] { key.getKey().getBytes(), new Integer(0), new Integer(key.getKey().length()) }); } catch (Exception e) { throw new RuntimeException(e); } } }
/** * checks if the key applies to some host. */ boolean isMatched(String _host){ return isIncluded(_host); }
public String getFingerprint() { return key.getFingerPrint(jsch); }
hk=(HostKey)(pool.elementAt(i)); String marker=hk.getMarker(); String host=hk.getHost(); String type=hk.getType(); String comment = hk.getComment(); if(type.equals("UNKNOWN")){ out.write(Util.str2byte(host)); out.write(Util.str2byte(type)); out.write(space); out.write(Util.str2byte(hk.getKey())); if(comment!=null){ out.write(space);
public void remove(String host, String type, byte[] key){ boolean sync=false; synchronized(pool){ for(int i=0; i<pool.size(); i++){ HostKey hk=(HostKey)(pool.elementAt(i)); if(host==null || (hk.isMatched(host) && (type==null || (hk.getType().equals(type) && (key==null || Util.array_equals(key, hk.key)))))){ String hosts=hk.getHost(); if(hosts.equals(host) || ((hk instanceof HashedHostKey) && ((HashedHostKey)hk).isHashed())){ pool.removeElement(hk); } else{ hk.host=deleteSubString(hosts, host); } sync=true; } } } if(sync){ try{sync();}catch(Exception e){}; } }