Package org.vngx.jsch.hash

Examples of org.vngx.jsch.hash.MAC


   * randomly generated and stored with the host value to hash hosts during
   * matching.
   */
  private void generateHash() throws JSchException {
    // Create random salt for session
    MAC macsha1 = getMAC();
    _salt = new byte[macsha1.getBlockSize()];
    getRandom().fill(_salt, 0, _salt.length);

    try // Create the hashed host using salt and MAC-SHA1
      synchronized( macsha1 ) {  // MAC is not thread-safe
        macsha1.init(_salt);
        byte[] hostBytes = Util.str2byte(_host);
        macsha1.update(hostBytes, 0, hostBytes.length);
        _hashedHost = new byte[macsha1.getBlockSize()];
        macsha1.doFinal(_hashedHost, 0);
      }
    } catch(Exception e) {
      throw new JSchException("Failed to create HashedHostKey: " + e, e);
    }

View Full Code Here


   * @return true if specified host matches key
   */
  @Override
  public boolean isMatched(String host) {
    try {
      MAC macsha1 = getMAC();
      synchronized( macsha1 ) {  // MAC is not thread-safe
        macsha1.init(_salt);
        byte[] hostBytes = Util.str2byte(host);
        macsha1.update(hostBytes, 0, hostBytes.length);
        byte[] hashValue = new byte[macsha1.getBlockSize()];
        macsha1.doFinal(hashValue, 0);
        return Arrays.equals(_hashedHost, hashValue);
      }
    } catch(Exception e) {
      throw new IllegalStateException("Failed to check HashedHostKey isMatched(): "+e, e);
    }
View Full Code Here

      throw new JSchException("Inbound packet is corrupt: "+msg, reasonCode);
    }

    // Finish reading in the rest of the data from the Session's in stream
    // which needs to be discarded.
    MAC discardMac = packetLength != Packet.MAX_SIZE ? _readMac : null;
    discard -= buffer.index;
    while( discard > 0 ) {
      buffer.reset();
      int len = Math.min(discard, buffer.buffer.length);
      getByte(buffer.buffer, 0, len);
      if( discardMac != null ) {
        discardMac.update(buffer.buffer, 0, len);
      }
      discard -= len;
    }
    if( discardMac != null ) {
      discardMac.doFinal(buffer.buffer, 0);
    }
    throw new JSchException("Inbound packet is corrupt: "+msg, reasonCode);
  }
View Full Code Here

TOP

Related Classes of org.vngx.jsch.hash.MAC

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.