Package org.vngx.jsch

Examples of org.vngx.jsch.Buffer


   * @param I_C client key exchange initialization string
   * @return kex proposals or null if failure to guess
   * @throws KexException if algorithm negotiation fails
   */
  static KexProposal createProposal(final byte[] I_S, final byte[] I_C) throws KexException {
    Buffer serverBuffer = new Buffer(I_S)// Wrap in Buffers to easily
    Buffer clientBuffer = new Buffer(I_C)// read Strings
    serverBuffer.setOffSet(17)// Skip over message code and 16 bytes of
    clientBuffer.setOffSet(17)// random padding for each buffer

    List<String> serverProposals, clientProposals;
    KexProposal proposal = new KexProposal();
    for( Proposal p : Proposal.values() ) {
      // Parse out server and client proposal lists
      serverProposals = Arrays.asList(Util.split(Util.byte2str(serverBuffer.getString()), ","));
      clientProposals = Arrays.asList(Util.split(Util.byte2str(clientBuffer.getString()), ","));
      if( JSch.getLogger().isEnabled(Level.DEBUG) ) {
        JSch.getLogger().log(Level.DEBUG, "Kex: S proposes "+p+" -> "+serverProposals);
        JSch.getLogger().log(Level.DEBUG, "Kex: C proposes "+p+" -> "+clientProposals);
      }

View Full Code Here


   * @param signatureOfH received in key exchange
   * @return true if the server's host key is verified
   * @throws KexException if any errors occur
   */
  protected boolean verifyHostKey(byte[] signatureOfH) throws KexException {
    Buffer hostKeyBuffer = new Buffer(K_S);
    String keyAlgorithm = Util.byte2str(hostKeyBuffer.getString())// Read in key algorithm name
    if( KeyType.SSH_DSS.equals(keyAlgorithm) ) {
      _hostKeyType = KeyType.SSH_DSS;
      return verifyHostDSA(hostKeyBuffer, signatureOfH);
    } else if( KeyType.SSH_RSA.equals(keyAlgorithm) ) {
      _hostKeyType = KeyType.SSH_RSA;
View Full Code Here

          data[0] == (byte) 0x3f
          && data[1] == (byte) 0x6f
          && data[2] == (byte) 0xf9
          && data[3] == (byte) 0xeb ) {

        Buffer _buf = new Buffer(data);
        _buf.getInt()// 0x3f6ff9be
        _buf.getInt();
        @SuppressWarnings("unused")
        byte[] _type = _buf.getString();
        byte[] _cipher = _buf.getString();
        String cipher = Util.byte2str(_cipher);
        if( cipher.equals("3des-cbc") ) {
          _buf.getInt();
          byte[] foo = new byte[data.length - _buf.getOffSet()];
          _buf.getBytes(foo);
          data = foo;
          encrypted = true;
          throw new JSchException("unknown privatekey format: " + prvkey);
        } else if( cipher.equals("none") ) {
          _buf.getInt();
          _buf.getInt();
          encrypted = false;
          byte[] foo = new byte[data.length - _buf.getOffSet()];
          _buf.getBytes(foo);
          data = foo;
        }
      }

      if( pubkey != null ) {
View Full Code Here

      int[] index = new int[1];
      int length = 0;

      if( _vendor == VENDOR_FSECURE ) {
        if( plain[index[0]] != 0x30 ) {                  // FSecure
          Buffer buf = new Buffer(plain);
          _pubKey = buf.getMPIntBits();
          _prvKey = buf.getMPIntBits();
          _n = buf.getMPIntBits();
          buf.getMPIntBits()// u array?
          _p = buf.getMPIntBits();
          _q = buf.getMPIntBits();
          return true;
        }
        return false;
      }
View Full Code Here

      return null;
    }

    byte[] buffer = new byte[KeyType.SSH_RSA.toString().length() + 4 +
        _pubKey.length + 4 + _n.length + 4];
    Buffer buf = new Buffer(buffer);
    buf.putString(KeyType.SSH_RSA.getBytes());
    buf.putString(_pubKey);
    buf.putString(_n);
    return buffer;
  }
View Full Code Here

  @Override
  boolean parse(byte[] plain) {
    try {
      if( _vendor == VENDOR_FSECURE ) {
        if( plain[0] != 0x30 ) {              // FSecure
          Buffer buf = new Buffer(plain);
          buf.getInt();
          _p = buf.getMPIntBits();
          _g = buf.getMPIntBits();
          _q = buf.getMPIntBits();
          _pubKey = buf.getMPIntBits();
          _prvKey = buf.getMPIntBits();
          return true;
        }
        return false;
      }
View Full Code Here

      return null;
    }

    byte[] buffer = new byte[KeyType.SSH_DSS.toString().length() + 4 + _p.length + 4 +
        _q.length + 4 + _g.length + 4 + _pubKey.length + 4];
    Buffer buf = new Buffer(buffer);
    buf.putString(KeyType.SSH_DSS.getBytes());
    buf.putString(_p);
    buf.putString(_q);
    buf.putString(_g);
    buf.putString(_pubKey);
    return buffer;
  }
View Full Code Here

  }

  @Override
  public boolean verify(byte[] signature) throws Exception {
    if( (signature[0] | signature[1] | signature[2]) == 0 ) {
      Buffer sigBuffer = new Buffer(signature);
      sigBuffer.getString();        // Skip first string
      signature = sigBuffer.getString()// second is signature
    }
    return _signature.verify(signature);
  }
View Full Code Here

    _signature.initSign(prvKey);
  }

  @Override
  public byte[] sign() throws Exception {
    Buffer signature = new Buffer(_signature.sign());
    // signature is in ASN.1
    // SEQUENCE::={ r INTEGER, offset INTEGER }
    signature.setOffSet(3); // skip DER-sequence type, seq length and DER bytearray type (1 byte each)
       
    byte[] r = signature.getBytes(new byte[signature.getByte()]);
    signature.getByte(); // skip DER bytearray type
    byte[] s = signature.getBytes(new byte[signature.getByte()]);

    // result must be 40 bytes, but length of r and offset may not be 20 bytes
    byte[] result = new byte[40];
    System.arraycopy(r, (r.length > 20) ? 1 : 0,
        result, (r.length > 20) ? 0 : 20 - r.length,
View Full Code Here

  }

  @Override
  public boolean verify(byte[] signature) throws Exception {
    if( (signature[0] | signature[1] | signature[2]) == 0 ) {
      Buffer sigBuffer = new Buffer(signature);
      sigBuffer.getString();        // Skip first string
      signature = sigBuffer.getString()// second is signature
    }

    // ASN.1
    int frst = (signature[0& 0x80) != 0 ? 1 : 0;
    int scnd = (signature[20] & 0x80) != 0 ? 1 : 0;
View Full Code Here

TOP

Related Classes of org.vngx.jsch.Buffer

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.