1 2 29 30 package com.jcraft.jsch; 31 32 public abstract class KeyExchange{ 33 34 static final int PROPOSAL_KEX_ALGS=0; 35 static final int PROPOSAL_SERVER_HOST_KEY_ALGS=1; 36 static final int PROPOSAL_ENC_ALGS_CTOS=2; 37 static final int PROPOSAL_ENC_ALGS_STOC=3; 38 static final int PROPOSAL_MAC_ALGS_CTOS=4; 39 static final int PROPOSAL_MAC_ALGS_STOC=5; 40 static final int PROPOSAL_COMP_ALGS_CTOS=6; 41 static final int PROPOSAL_COMP_ALGS_STOC=7; 42 static final int PROPOSAL_LANG_CTOS=8; 43 static final int PROPOSAL_LANG_STOC=9; 44 static final int PROPOSAL_MAX=10; 45 46 49 static String kex="diffie-hellman-group1-sha1"; 51 static String server_host_key="ssh-rsa,ssh-dss"; 52 static String enc_c2s="blowfish-cbc"; 53 static String enc_s2c="blowfish-cbc"; 54 static String mac_c2s="hmac-md5"; static String mac_s2c="hmac-md5"; 57 static String lang_c2s=""; 60 static String lang_s2c=""; 61 62 public static final int STATE_END=0; 63 64 protected Session session=null; 65 protected HASH sha=null; 66 protected byte[] K=null; 67 protected byte[] H=null; 68 protected byte[] K_S=null; 69 70 public abstract void init(Session session, 71 byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception ; 72 public abstract boolean next(Buffer buf) throws Exception ; 73 public abstract String getKeyType(); 74 public abstract int getState(); 75 76 86 87 protected static String [] guess(byte[]I_S, byte[]I_C){ 88 String [] guess=new String [PROPOSAL_MAX]; 90 Buffer sb=new Buffer(I_S); sb.setOffSet(17); 91 Buffer cb=new Buffer(I_C); cb.setOffSet(17); 92 93 for(int i=0; i<PROPOSAL_MAX; i++){ 94 byte[] sp=sb.getString(); byte[] cp=cb.getString(); 97 100 int j=0; 101 int k=0; 102 loop: 104 while(j<cp.length){ 105 while(j<cp.length && cp[j]!=',')j++; 106 if(k==j) return null; 107 String algorithm=new String (cp, k, j-k); 108 int l=0; 110 int m=0; 111 while(l<sp.length){ 112 while(l<sp.length && sp[l]!=',')l++; 113 if(m==l) return null; 114 if(algorithm.equals(new String (sp, m, l-m))){ 116 guess[i]=algorithm; 117 break loop; 119 } 120 l++; 121 m=l; 122 } 123 j++; 124 k=j; 125 } 126 if(j==0){ 127 guess[i]=""; 128 } 129 else if(guess[i]==null){ 130 return null; 132 } 133 } 134 135 if(JSch.getLogger().isEnabled(Logger.INFO)){ 136 JSch.getLogger().log(Logger.INFO, 137 "kex: server->client"+ 138 " "+guess[PROPOSAL_ENC_ALGS_STOC]+ 139 " "+guess[PROPOSAL_MAC_ALGS_STOC]+ 140 " "+guess[PROPOSAL_COMP_ALGS_STOC]); 141 JSch.getLogger().log(Logger.INFO, 142 "kex: client->server"+ 143 " "+guess[PROPOSAL_ENC_ALGS_CTOS]+ 144 " "+guess[PROPOSAL_MAC_ALGS_CTOS]+ 145 " "+guess[PROPOSAL_COMP_ALGS_CTOS]); 146 } 147 148 152 return guess; 153 } 154 155 public String getFingerPrint(){ 156 HASH hash=null; 157 try{ 158 Class c=Class.forName(session.getConfig("md5")); 159 hash=(HASH)(c.newInstance()); 160 } 161 catch(Exception e){ System.err.println("getFingerPrint: "+e); } 162 return Util.getFingerPrint(hash, getHostKey()); 163 } 164 byte[] getK(){ return K; } 165 byte[] getH(){ return H; } 166 HASH getHash(){ return sha; } 167 byte[] getHostKey(){ return K_S; } 168 } 169 | Popular Tags |