KeyExchange.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 package com.jcraft.jsch;
00031
00043 public abstract class KeyExchange{
00044
00045 static final int PROPOSAL_KEX_ALGS=0;
00046 static final int PROPOSAL_SERVER_HOST_KEY_ALGS=1;
00047 static final int PROPOSAL_ENC_ALGS_CTOS=2;
00048 static final int PROPOSAL_ENC_ALGS_STOC=3;
00049 static final int PROPOSAL_MAC_ALGS_CTOS=4;
00050 static final int PROPOSAL_MAC_ALGS_STOC=5;
00051 static final int PROPOSAL_COMP_ALGS_CTOS=6;
00052 static final int PROPOSAL_COMP_ALGS_STOC=7;
00053 static final int PROPOSAL_LANG_CTOS=8;
00054 static final int PROPOSAL_LANG_STOC=9;
00055 static final int PROPOSAL_MAX=10;
00056
00057
00058
00059
00060
00061 static String kex="diffie-hellman-group1-sha1";
00062 static String server_host_key="ssh-rsa,ssh-dss";
00063 static String enc_c2s="blowfish-cbc";
00064 static String enc_s2c="blowfish-cbc";
00065 static String mac_c2s="hmac-md5";
00066
00067 static String mac_s2c="hmac-md5";
00068
00069
00070 static String lang_c2s="";
00071 static String lang_s2c="";
00072
00077 public static final int STATE_END=0;
00078
00079 protected Session session=null;
00080 protected HASH sha=null;
00081 protected byte[] K=null;
00082 protected byte[] H=null;
00083 protected byte[] K_S=null;
00084
00085
00102 public abstract void init(Session session,
00103 byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception;
00104
00112 public abstract boolean next(Buffer buf) throws Exception;
00113
00118 public abstract String getKeyType();
00119
00125 public abstract int getState();
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 protected static String[] guess(byte[]I_S, byte[]I_C){
00139 String[] guess=new String[PROPOSAL_MAX];
00140 Buffer sb=new Buffer(I_S); sb.setOffSet(17);
00141 Buffer cb=new Buffer(I_C); cb.setOffSet(17);
00142
00143 for(int i=0; i<PROPOSAL_MAX; i++){
00144 byte[] sp=sb.getString();
00145 byte[] cp=cb.getString();
00146 int j=0;
00147 int k=0;
00148
00149 loop:
00150 while(j<cp.length){
00151 while(j<cp.length && cp[j]!=',')j++;
00152 if(k==j) return null;
00153 String algorithm=Util.byte2str(cp, k, j-k);
00154 int l=0;
00155 int m=0;
00156 while(l<sp.length){
00157 while(l<sp.length && sp[l]!=',')l++;
00158 if(m==l) return null;
00159 if(algorithm.equals(Util.byte2str(sp, m, l-m))){
00160 guess[i]=algorithm;
00161 break loop;
00162 }
00163 l++;
00164 m=l;
00165 }
00166 j++;
00167 k=j;
00168 }
00169 if(j==0){
00170 guess[i]="";
00171 }
00172 else if(guess[i]==null){
00173 return null;
00174 }
00175 }
00176
00177 if(JSch.getLogger().isEnabled(Logger.INFO)){
00178 JSch.getLogger().log(Logger.INFO,
00179 "kex: server->client"+
00180 " "+guess[PROPOSAL_ENC_ALGS_STOC]+
00181 " "+guess[PROPOSAL_MAC_ALGS_STOC]+
00182 " "+guess[PROPOSAL_COMP_ALGS_STOC]);
00183 JSch.getLogger().log(Logger.INFO,
00184 "kex: client->server"+
00185 " "+guess[PROPOSAL_ENC_ALGS_CTOS]+
00186 " "+guess[PROPOSAL_MAC_ALGS_CTOS]+
00187 " "+guess[PROPOSAL_COMP_ALGS_CTOS]);
00188 }
00189
00190
00191
00192
00193
00194 return guess;
00195 }
00196
00205 public String getFingerPrint(){
00206 HASH hash=null;
00207 try{
00208 Class c=Class.forName(session.getConfig("md5"));
00209 hash=(HASH)(c.newInstance());
00210 }
00211 catch(Exception e){ System.err.println("getFingerPrint: "+e); }
00212 return Util.getFingerPrint(hash, getHostKey());
00213 }
00214 byte[] getK(){ return K; }
00215 byte[] getH(){ return H; }
00216 HASH getHash(){ return sha; }
00217 byte[] getHostKey(){ return K_S; }
00218 }