00001 using System;
00002
00003 namespace Tamir.SharpSsh.jsch
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
00031
00032
00033
00034 public abstract class KeyExchange
00035 {
00036
00037 internal const int PROPOSAL_KEX_ALGS=0;
00038 internal const int PROPOSAL_SERVER_HOST_KEY_ALGS=1;
00039 internal const int PROPOSAL_ENC_ALGS_CTOS=2;
00040 internal const int PROPOSAL_ENC_ALGS_STOC=3;
00041 internal const int PROPOSAL_MAC_ALGS_CTOS=4;
00042 internal const int PROPOSAL_MAC_ALGS_STOC=5;
00043 internal const int PROPOSAL_COMP_ALGS_CTOS=6;
00044 internal const int PROPOSAL_COMP_ALGS_STOC=7;
00045 internal const int PROPOSAL_LANG_CTOS=8;
00046 internal const int PROPOSAL_LANG_STOC=9;
00047 internal const int PROPOSAL_MAX=10;
00048
00049
00050
00051
00052
00053 internal static String kex="diffie-hellman-group1-sha1";
00054 internal static String server_host_key="ssh-rsa,ssh-dss";
00055 internal static String enc_c2s="blowfish-cbc";
00056 internal static String enc_s2c="blowfish-cbc";
00057 internal static String mac_c2s="hmac-md5";
00058
00059 internal static String mac_s2c="hmac-md5";
00060
00061
00062 internal static String lang_c2s="";
00063 internal static String lang_s2c="";
00064
00065 public const int STATE_END=0;
00066
00067 public Tamir.SharpSsh.java.String[] _guess=null;
00068 protected Session session=null;
00069 protected HASH sha=null;
00070 protected byte[] K=null;
00071 protected byte[] H=null;
00072 protected byte[] K_S=null;
00073
00074 public abstract void init(Session session,
00075 byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C);
00076 public abstract bool next(Buffer buf);
00077 public abstract String getKeyType();
00078 public abstract int getState();
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 internal static Tamir.SharpSsh.java.String[] guess(byte[]I_S, byte[]I_C)
00092 {
00093
00094 Tamir.SharpSsh.java.String[] guess=new Tamir.SharpSsh.java.String[PROPOSAL_MAX];
00095 Buffer sb=new Buffer(I_S); sb.setOffSet(17);
00096 Buffer cb=new Buffer(I_C); cb.setOffSet(17);
00097
00098 for(int i=0; i<PROPOSAL_MAX; i++)
00099 {
00100 byte[] sp=sb.getString();
00101 byte[] cp=cb.getString();
00102
00103
00104
00105
00106 int j=0;
00107 int k=0;
00108
00109
00110 while(j<cp.Length)
00111 {
00112 while(j<cp.Length && cp[j]!=',')j++;
00113 if(k==j) return null;
00114 String algorithm=Util.getString(cp, k, j-k);
00115
00116 int l=0;
00117 int m=0;
00118 while(l<sp.Length)
00119 {
00120 while(l<sp.Length && sp[l]!=',')l++;
00121 if(m==l) return null;
00122
00123 if(algorithm.Equals(Util.getString(sp, m, l-m)))
00124 {
00125 guess[i]=algorithm;
00126
00127 goto BREAK;
00128 }
00129 l++;
00130 m=l;
00131 }
00132 j++;
00133 k=j;
00134 }
00135 BREAK:
00136 if(j==0)
00137 {
00138 guess[i]="";
00139 }
00140 else if(guess[i]==null)
00141 {
00142
00143 return null;
00144 }
00145 }
00146
00147
00148
00149
00150
00151 return guess;
00152 }
00153
00154 public String getFingerPrint()
00155 {
00156 HASH hash=null;
00157 try
00158 {
00159 Type t=Type.GetType(session.getConfig("md5"));
00160 hash=(HASH)(Activator.CreateInstance(t));
00161 }
00162 catch(Exception e){ Console.Error.WriteLine("getFingerPrint: "+e); }
00163 return Util.getFingerPrint(hash, getHostKey());
00164 }
00165 internal byte[] getK(){ return K; }
00166 internal byte[] getH(){ return H; }
00167 internal HASH getHash(){ return sha; }
00168 internal byte[] getHostKey(){ return K_S; }
00169 }
00170 }