389
private boolean isIncluded(String hosts, String host){
391
int hostlen=host.length();
392
int hostslen=hosts.length();
395
j=hosts.indexOf(',', i);
397
if(hostlen!=hostslen-i) return false;
398
return hosts.regionMatches(true, i, host, 0, hostlen);
399
//return hosts.substring(i).equals(host);
402
if(hosts.regionMatches(true, i, host, 0, hostlen)) return true;
403
//if(hosts.substring(i, i+hostlen).equals(host)) return true;
410
private static boolean equals(byte[] foo, byte[] bar){
411
if(foo.length!=bar.length)return false;
412
for(int i=0; i<foo.length; i++){
413
if(foo[i]!=bar[i])return false;
420
private static final byte[] space={(byte)0x20};
421
private static final byte[] sshdss="ssh-dss".getBytes();
422
private static final byte[] sshrsa="ssh-rsa".getBytes();
423
private static final byte[] cr="\n".getBytes();
425
public class HostKey{
429
HostKey(String host, int type, byte[] key){
430
this.host=host; this.type=type; this.key=key;
432
void dump(OutputStream out) throws IOException{
434
out.write(host.getBytes());
438
out.write(host.getBytes());
440
if(type==HostKey.SSHDSS){ out.write(sshdss); }
441
else if(type==HostKey.SSHRSA){ out.write(sshrsa);}
443
out.write(Util.toBase64(key, 0, key.length));
447
public String getHost(){ return host; }
448
public String getType(){
449
if(type==SSHDSS){ return new String(sshdss); }
450
if(type==SSHRSA){ return new String(sshrsa);}
453
public String getKey(){
454
return new String(Util.toBase64(key, 0, key.length));
456
public String getFingerPrint(){
459
Class c=Class.forName(jsch.getConfig("md5"));
460
hash=(HASH)(c.newInstance());
462
catch(Exception e){ System.err.println("getFingerPrint: "+e); }
463
return Util.getFingerPrint(hash, key);
399
private synchronized MAC getHMACSHA1(){
402
Class c=Class.forName(jsch.getConfig("hmac-sha1"));
403
hmacsha1=(MAC)(c.newInstance());
406
System.err.println("hmacsha1: "+e);
412
HostKey createHashedHostKey(String host, byte[]key) throws JSchException {
413
HashedHostKey hhk=new HashedHostKey(host, key);
417
class HashedHostKey extends HostKey{
418
private static final String HASH_MAGIC="|1|";
419
private static final String HASH_DELIM="|";
421
private boolean hashed=false;
426
HashedHostKey(String host, byte[] key) throws JSchException {
427
this(host, GUESS, key);
429
HashedHostKey(String host, int type, byte[] key) throws JSchException {
430
super(host, type, key);
431
if(this.host.startsWith(HASH_MAGIC) &&
432
this.host.substring(HASH_MAGIC.length()).indexOf(HASH_DELIM)>0){
433
String data=this.host.substring(HASH_MAGIC.length());
434
String _salt=data.substring(0, data.indexOf(HASH_DELIM));
435
String _hash=data.substring(data.indexOf(HASH_DELIM)+1);
436
salt=Util.fromBase64(_salt.getBytes(), 0, _salt.length());
437
hash=Util.fromBase64(_hash.getBytes(), 0, _hash.length());
438
if(salt.length!=20 || // block size of hmac-sha1
448
boolean isMatched(String _host){
450
return super.isMatched(_host);
452
MAC macsha1=getHMACSHA1();
454
synchronized(macsha1){
456
byte[] foo=_host.getBytes();
457
macsha1.update(foo, 0, foo.length);
458
byte[] bar=new byte[macsha1.getBlockSize()];
459
macsha1.doFinal(bar, 0);
460
return Util.array_equals(hash, bar);
464
System.out.println(e);
476
MAC macsha1=getHMACSHA1();
478
Random random=Session.random;
479
synchronized(random){
480
salt=new byte[macsha1.getBlockSize()];
481
random.fill(salt, 0, salt.length);
485
synchronized(macsha1){
487
byte[] foo=host.getBytes();
488
macsha1.update(foo, 0, foo.length);
489
hash=new byte[macsha1.getBlockSize()];
490
macsha1.doFinal(hash, 0);
495
host=HASH_MAGIC+new String(Util.toBase64(salt, 0, salt.length))+
496
HASH_DELIM+new String(Util.toBase64(hash, 0, hash.length));