⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssh.java

📁 一个非常好的ssh客户端实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	cipherName = "blowfish-cbc";    } else if("rc4".equals(cipherName)) {	cipherName = "arcfour";    } else if("des".equals(cipherName)) {	cipherName = "des-cbc";    } else if("3des".equals(cipherName)) {	cipherName = "3des-cbc";    } else if("idea".equals(cipherName)) {	cipherName = "idea-cbc";    }    for(i = 0; i < cipherClasses.length; i++) {      String ciN = cipherClasses[i][IDX_CIPHER_NAME];      if(ciN.equalsIgnoreCase(cipherName)) {	if(cipherClasses[i][0] == null)	  i = cipherClasses.length;	break;      }    }    return i;  }  public static String getAuthName(int authType) {    return authTypeDesc[authType];  }  public static String getAltAuthName(int authType) {      if(authType == AUTH_TIS || authType == AUTH_SDI ||	 authType == AUTH_CRYPTOCARD) {	  return "keyboard-interactive";      }      return getAuthName(authType);  }  public static int getAuthType(String authName) throws IllegalArgumentException {    int i;    if("sdi-token".equals(authName) || "kbd-interact".equals(authName) ||       "secureid".equals(authName)) {	authName = "securid";    } else if("rsa".equals(authName)) {	authName = "publickey";    } else if("passwd".equals(authName)) {	authName = "password";    }    for(i = 1; i < SSH.authTypeDesc.length; i++) {      if(authTypeDesc[i].equalsIgnoreCase(authName))	break;    }    if(i == AUTH_NOTSUPPORTED)      throw new IllegalArgumentException("Authtype " + authName + " not supported");    return i;  }  static int cntListSize(String authList) {    int cnt = 1;    int i   = 0, n;    while(i < authList.length() && (n = authList.indexOf(',', i)) != -1) {      i = n + 1;      cnt++;    }    return cnt;  }  public static int[] getAuthTypes(String authList) throws IllegalArgumentException {    int len = cntListSize(authList);    int[] authTypes = new int[len];    int r, l = 0;    String type;    for(int i = 0; i < len; i++) {      r = authList.indexOf(',', l);      if(r == -1)	r = authList.length();      type = authList.substring(l, r).trim();      authTypes[i] = getAuthType(type);      l = r + 1;    }    return authTypes;  }  protected boolean isCipherSupported(int cipherType) {    int cipherMask = (0x01 << cipherType);    if((cipherMask & supportedCiphers) != 0)      return true;    return false;  }  protected boolean isAuthTypeSupported(int authType) {    int authTypeMask = (0x01 << authType);    if((authTypeMask & supportedAuthTypes) != 0)      return true;    return false;  }  protected boolean isProtocolFlagSet(int protFlag) {    int protFlagMask = (0x01 << protFlag);    if((protFlagMask & protocolFlags) != 0)      return true;    return false;  }  public static boolean haveSecureRandom() {      return (secureRandom != null);  }  public static synchronized RandomSeed randomSeed() {      if(randomSeed == null) {          if (com.mindbright.util.Util.isNetscapeJava()) {              try {                  netscape.security.PrivilegeManager.enablePrivilege("UniversalFileAccess");              } catch (netscape.security.ForbiddenTargetException e) {              }          }	  randomSeed = new RandomSeed("/dev/random", "/dev/urandom");      }      return randomSeed;  }  public static void initSeedGenerator() {      RandomSeed seed = randomSeed();      if(secureRandom == null) {	  byte[] s = seed.getBytesBlocking(20, false);	  secureRandom = new SecureRandomAndPad(new SecureRandom(s));      } else {	  int bytes = seed.getAvailableBits() / 8;	  if(bytes > 0) {	      secureRandom.setSeed(seed.getBytesBlocking(bytes > 20 ? 20 : bytes));	  }      }      secureRandom.setPadSeed(seed.getBytes(20));  }  public static synchronized SecureRandomAndPad secureRandom() {      initSeedGenerator();      return secureRandom;  }  public static void log(String msg) {    if(DEBUG) System.out.println(msg);  }  public static void logExtra(String msg) {    if(DEBUGMORE) System.out.println(msg);  }  public static void logDebug(String msg) {    if(DEBUG) System.out.println(msg);  }  public static void logIgnore(SSHPduInputStream pdu) {    if(DEBUG) System.out.println("MSG_IGNORE received...(len = " + pdu.length + ")");  }  void generateSessionId() throws IOException {    byte[]        message;    byte[]        srvKey = srvServerKey.getModulus().toByteArray();    byte[]        hstKey = srvHostKey.getModulus().toByteArray();    int           len = srvKey.length + hstKey.length + srvCookie.length;    if(srvKey[0] == 0)      len -= 1;    if(hstKey[0] == 0)      len -= 1;    message = new byte[len];    if(hstKey[0] == 0) {      System.arraycopy(hstKey, 1, message, 0, hstKey.length - 1);      len = hstKey.length - 1;    } else {      System.arraycopy(hstKey, 0, message, 0, hstKey.length);      len = hstKey.length;    }    if(srvKey[0] == 0) {      System.arraycopy(srvKey, 1, message, len, srvKey.length - 1);      len += srvKey.length - 1;    } else {      System.arraycopy(srvKey, 0, message, len, srvKey.length);      len += srvKey.length;    }    System.arraycopy(srvCookie, 0, message, len, srvCookie.length);    try {      MessageDigest md5;      md5 = MessageDigest.getInstance("MD5");      md5.update(message);      sessionId = md5.digest();    } catch(Exception e) {      throw new IOException("MD5 not implemented, can't generate session-id");    }  }  protected void initClientCipher() throws IOException {    initCipher(false);  }  protected void initServerCipher() throws IOException {    initCipher(true);  }  protected void initCipher(boolean server) throws IOException {    sndCipher = SSHCipher.getInstance(cipherClasses[cipherType][0]);    rcvCipher = SSHCipher.getInstance(cipherClasses[cipherType][0]);    if(sndCipher == null) {      throw new IOException("SSHCipher " + cipherClasses[cipherType][1] +			    " not found, can't use it");    }    sndCipher.setKey(sessionKey);    rcvCipher.setKey(sessionKey);  }  public static String generateKeyFiles(RSAPrivateCrtKey key,					String fileName, String passwd,					String comment)    throws IOException  {    SSHRSAKeyFile.createKeyFile(key, passwd, fileName, comment);    SSHRSAPublicKeyString pks =	new SSHRSAPublicKeyString("", comment,				  key.getPublicExponent(), key.getModulus());    pks.toFile(fileName + ".pub");    return pks.toString();  }  /* !!! USED FOR DEBUG !!!  void printSrvKeys() {    BigInteger big;    byte[] theId = new byte[sessionId.length + 1];    theId[0] = 0;    System.arraycopy(sessionId, 0, theId, 1, sessionId.length);    big = new BigInteger(theId);    System.out.println("sessionId: " + big.toString(16));    byte[] theKey = new byte[sessionKey.length + 1];    theKey[0] = 0;    System.arraycopy(sessionKey, 0, theKey, 1, sessionKey.length);    big = new BigInteger(theKey);    System.out.println("sessionkey: " + big.toString(16));    System.out.println("srvkey n: " + ((RSAPublicKey)srvServerKey.getPublic()).getN().toString(16));    System.out.println("srvkey e: " + ((RSAPublicKey)srvServerKey.getPublic()).getE().toString(16));    System.out.println("srvkey bits: " +  ((RSAPublicKey)srvServerKey.getPublic()).bitLength());    System.out.println("hstkey n: " + ((RSAPublicKey)srvHostKey.getPublic()).getN().toString(16));    System.out.println("hstkey e: " + ((RSAPublicKey)srvHostKey.getPublic()).getE().toString(16));    System.out.println("hstkey bits: " +  ((RSAPublicKey)srvHostKey.getPublic()).bitLength());  }  */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -