protected int check2048(Class c, int _max) throws Exception { DH dh = (com.jcraft.jsch.DH) (c.newInstance()); dh.init(); byte[] foo = new byte[257]; foo[1] = (byte) 0xdd; foo[256] = 0x73; dh.setP(foo); byte[] bar = {(byte) 0x02}; dh.setG(bar); try { dh.getE(); _max = 2048; } catch (Exception e) { } return _max; }
public void init(Session session, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception { this.session = session; this.V_S = V_S; this.V_C = V_C; this.I_S = I_S; this.I_C = I_C; try { Class c = Class.forName(session.getConfig(hash)); sha = (HASH) (c.newInstance()); sha.init(); } catch (Exception e) { System.err.println(e); } buf = new Buffer(); packet = new Packet(buf); try { Class c = Class.forName(session.getConfig("dh")); // Since JDK8, SunJCE has lifted the keysize restrictions // from 1024 to 2048 for DH. preferred = max = check2048(c, max); dh = (com.jcraft.jsch.DH) (c.newInstance()); dh.init(); } catch (Exception e) { throw e; } packet.reset(); buf.putByte((byte) SSH_MSG_KEX_DH_GEX_REQUEST); buf.putInt(min); buf.putInt(preferred); buf.putInt(max); session.write(packet); if (JSch.getLogger().isEnabled(Logger.INFO)) { JSch.getLogger() .log( Logger.INFO, "SSH_MSG_KEX_DH_GEX_REQUEST(" + min + "<" + preferred + "<" + max + ") sent"); JSch.getLogger().log(Logger.INFO, "expecting SSH_MSG_KEX_DH_GEX_GROUP"); } state = SSH_MSG_KEX_DH_GEX_GROUP; }