org.apache.sshd.common.util.buffer.Buffer.getUByte()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中org.apache.sshd.common.util.buffer.Buffer.getUByte()方法的一些代码示例,展示了Buffer.getUByte()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.getUByte()方法的具体详情如下:
包路径:org.apache.sshd.common.util.buffer.Buffer
类名称:Buffer
方法名:getUByte

Buffer.getUByte介绍

暂无

代码示例

代码示例来源:origin: org.apache.sshd/sshd-core

protected int getUByte(Buffer buffer) {
  return buffer.getUByte();
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

protected int getUByte(Buffer buffer) {
  return buffer.getUByte();
}

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
protected boolean processAuthDataRequest(ClientSession session, String service, Buffer buffer) throws Exception {
  int cmd = buffer.getUByte();
  throw new IllegalStateException("processAuthDataRequest(" + session + ")[" + service + "]"
        + " received unknown packet: cmd=" + SshConstants.getCommandMessageName(cmd));
}

代码示例来源:origin: org.apache.sshd/sshd-core

protected int readRawInput() throws IOException {
  if (buffer.available() > 0) {
    return buffer.getUByte();
  } else {
    return this.in.read();
  }
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

protected int readRawInput() throws IOException {
  if (buffer.available() > 0) {
    return buffer.getUByte();
  } else {
    return this.in.read();
  }
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

@Override
protected boolean processAuthDataRequest(ClientSession session, String service, Buffer buffer) throws Exception {
  int cmd = buffer.getUByte();
  throw new IllegalStateException("processAuthDataRequest(" + session + ")[" + service + "]"
        + " received unknown packet: cmd=" + SshConstants.getCommandMessageName(cmd));
}

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
public void removeAllIdentities() throws IOException {
  Buffer buffer = createBuffer(SshAgentConstants.SSH2_AGENTC_REMOVE_ALL_IDENTITIES, 1);
  if (log.isDebugEnabled()) {
    log.debug("removeAllIdentities");
  }
  buffer = request(prepare(buffer));
  int available = buffer.available();
  int response = (available >= 1) ? buffer.getUByte() : -1;
  if ((available != 1) || (response != SshAgentConstants.SSH_AGENT_SUCCESS)) {
    throw new SshException("Bad removeAllIdentities response (" + SshAgentConstants.getCommandMessageName(response) + ") - available=" + available);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

@Override
public void removeAllIdentities() throws IOException {
  Buffer buffer = createBuffer(SshAgentConstants.SSH2_AGENTC_REMOVE_ALL_IDENTITIES, 1);
  if (log.isDebugEnabled()) {
    log.debug("removeAllIdentities");
  }
  buffer = request(prepare(buffer));
  int available = buffer.available();
  int response = (available >= 1) ? buffer.getUByte() : -1;
  if ((available != 1) || (response != SshAgentConstants.SSH_AGENT_SUCCESS)) {
    throw new SshException("Bad removeAllIdentities response (" + SshAgentConstants.getCommandMessageName(response) + ") - available=" + available);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

/**
 * Process an SFTP command.
 * If the command throws an exception, the channel will be closed.
 *
 * @param buffer the buffer to process
 * @throws IOException if anything wrong happens
 */
protected void process(Buffer buffer) throws IOException {
  int length = buffer.getInt();
  int type = buffer.getUByte();
  int id = buffer.getInt();
  if (log.isDebugEnabled()) {
    log.debug("process({})[length={}, type={}, id={}] processing",
        getServerSession(), length, SftpConstants.getCommandMessageName(type), id);
  }
  doProcess(buffer, length, type, id);
}

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
public void messageReceived(final IoSession session, org.apache.sshd.common.util.Readable message) throws Exception {
  Buffer buffer = new ByteArrayBuffer(message.available() + Long.SIZE, false);
  buffer.putBuffer(message);
  Proxy proxy = proxies.get(session);
  if (proxy == null) {
    int version = buffer.getUByte();
    if (version == 0x04) {
      proxy = new Socks4(session);
    } else if (version == 0x05) {
      proxy = new Socks5(session);
    } else {
      throw new IllegalStateException("Unsupported version: " + version);
    }
    proxy.onMessage(buffer);
    proxies.put(session, proxy);
  } else {
    proxy.onMessage(buffer);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

@Override
public void messageReceived(final IoSession session, org.apache.sshd.common.util.Readable message) throws Exception {
  Buffer buffer = new ByteArrayBuffer(message.available() + Long.SIZE, false);
  buffer.putBuffer(message);
  Proxy proxy = proxies.get(session);
  if (proxy == null) {
    int version = buffer.getUByte();
    if (version == 0x04) {
      proxy = new Socks4(session);
    } else if (version == 0x05) {
      proxy = new Socks5(session);
    } else {
      throw new IllegalStateException("Unsupported version: " + version);
    }
    proxy.onMessage(buffer);
    proxies.put(session, proxy);
  } else {
    proxy.onMessage(buffer);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

/**
 * Process an SFTP packet
 *
 * @param incoming The received {@link Buffer}
 * @throws IOException if failed to process the buffer
 */
protected void process(Buffer incoming) throws IOException {
  // create a copy of the buffer in case it is being re-used
  Buffer buffer = new ByteArrayBuffer(incoming.available() + Long.SIZE, false);
  buffer.putBuffer(incoming);
  int rpos = buffer.rpos();
  int length = buffer.getInt();
  int type = buffer.getUByte();
  Integer id = buffer.getInt();
  buffer.rpos(rpos);
  if (log.isTraceEnabled()) {
    log.trace("process({}) id={}, type={}, len={}",
         getClientChannel(), id, SftpConstants.getCommandMessageName(type), length);
  }
  synchronized (messages) {
    messages.put(id, buffer);
    messages.notifyAll();
  }
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

@Override
public void addIdentity(KeyPair kp, String comment) throws IOException {
  Buffer buffer = createBuffer(SshAgentConstants.SSH2_AGENTC_ADD_IDENTITY);
  buffer.putKeyPair(kp);
  buffer.putString(comment);
  if (log.isDebugEnabled()) {
    log.debug("addIdentity({})[{}]: {}", KeyUtils.getKeyType(kp), comment, KeyUtils.getFingerPrint(kp.getPublic()));
  }
  buffer = request(prepare(buffer));
  int available = buffer.available();
  int response = (available >= 1) ? buffer.getUByte() : -1;
  if ((available != 1) || (response != SshAgentConstants.SSH_AGENT_SUCCESS)) {
    throw new SshException("Bad addIdentity response (" + SshAgentConstants.getCommandMessageName(response) + ") - available=" + available);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-core

@SuppressWarnings("synthetic-access")
@Override
protected void onMessage(Buffer buffer) throws IOException {
  if (channel == null) {
    int cmd = buffer.getUByte();
    if (cmd != 1) {
      throw new IllegalStateException("Unsupported socks command: " + cmd);
    }
    int port = getUShort(buffer);
    String host = Integer.toString(getUByte(buffer)) + "."
        + Integer.toString(getUByte(buffer)) + "."
        + Integer.toString(getUByte(buffer)) + "."
        + Integer.toString(getUByte(buffer));
    String userId = getNTString(buffer);
    // Socks4a
    if (host.startsWith("0.0.0.")) {
      host = getNTString(buffer);
    }
    if (log.isDebugEnabled()) {
      log.debug("Received socks4 connection request for {} to {}:{}", userId, host, port);
    }
    SshdSocketAddress remote = new SshdSocketAddress(host, port);
    channel = new TcpipClientChannel(TcpipClientChannel.Type.Direct, session, remote);
    service.registerChannel(channel);
    channel.open().addListener(this::onChannelOpened);
  } else {
    super.onMessage(buffer);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
public void removeIdentity(PublicKey key) throws IOException {
  Buffer buffer = createBuffer(SshAgentConstants.SSH2_AGENTC_REMOVE_IDENTITY);
  buffer.putPublicKey(key);
  if (log.isDebugEnabled()) {
    log.debug("removeIdentity({}) {}", KeyUtils.getKeyType(key), KeyUtils.getFingerPrint(key));
  }
  buffer = request(prepare(buffer));
  int available = buffer.available();
  int response = (available >= 1) ? buffer.getUByte() : -1;
  if ((available != 1) || (response != SshAgentConstants.SSH_AGENT_SUCCESS)) {
    throw new SshException("Bad removeIdentity response (" + SshAgentConstants.getCommandMessageName(response) + ") - available=" + available);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
public void addIdentity(KeyPair kp, String comment) throws IOException {
  Buffer buffer = createBuffer(SshAgentConstants.SSH2_AGENTC_ADD_IDENTITY);
  buffer.putKeyPair(kp);
  buffer.putString(comment);
  if (log.isDebugEnabled()) {
    log.debug("addIdentity({})[{}]: {}", KeyUtils.getKeyType(kp), comment, KeyUtils.getFingerPrint(kp.getPublic()));
  }
  buffer = request(prepare(buffer));
  int available = buffer.available();
  int response = (available >= 1) ? buffer.getUByte() : -1;
  if ((available != 1) || (response != SshAgentConstants.SSH_AGENT_SUCCESS)) {
    throw new SshException("Bad addIdentity response (" + SshAgentConstants.getCommandMessageName(response) + ") - available=" + available);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

@Override
public void removeIdentity(PublicKey key) throws IOException {
  Buffer buffer = createBuffer(SshAgentConstants.SSH2_AGENTC_REMOVE_IDENTITY);
  buffer.putPublicKey(key);
  if (log.isDebugEnabled()) {
    log.debug("removeIdentity({}) {}", KeyUtils.getKeyType(key), KeyUtils.getFingerPrint(key));
  }
  buffer = request(prepare(buffer));
  int available = buffer.available();
  int response = (available >= 1) ? buffer.getUByte() : -1;
  if ((available != 1) || (response != SshAgentConstants.SSH_AGENT_SUCCESS)) {
    throw new SshException("Bad removeIdentity response (" + SshAgentConstants.getCommandMessageName(response) + ") - available=" + available);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

protected Attributes checkAttributesResponse(int cmd, Buffer buffer) throws IOException {
  int length = buffer.getInt();
  int type = buffer.getUByte();
  int id = buffer.getInt();
  if (type == SftpConstants.SSH_FXP_ATTRS) {
    return readAttributes(cmd, buffer, new AtomicInteger(0));
  }
  if (type == SftpConstants.SSH_FXP_STATUS) {
    int substatus = buffer.getInt();
    String msg = buffer.getString();
    String lang = buffer.getString();
    if (log.isTraceEnabled()) {
      log.trace("checkAttributesResponse()[id={}] {} - status: {} [{}] {}",
           getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
           SftpConstants.getStatusName(substatus), lang, msg);
    }
    throwStatusException(cmd, id, substatus, msg, lang);
  }
  return handleUnexpectedAttributesPacket(cmd, id, type, length, buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

protected byte[] checkHandleResponse(int cmd, Buffer buffer) throws IOException {
  int length = buffer.getInt();
  int type = buffer.getUByte();
  int id = buffer.getInt();
  if (type == SftpConstants.SSH_FXP_HANDLE) {
    return ValidateUtils.checkNotNullAndNotEmpty(buffer.getBytes(), "Null/empty handle in buffer", GenericUtils.EMPTY_OBJECT_ARRAY);
  }
  if (type == SftpConstants.SSH_FXP_STATUS) {
    int substatus = buffer.getInt();
    String msg = buffer.getString();
    String lang = buffer.getString();
    if (log.isTraceEnabled()) {
      log.trace("checkHandleResponse({})[id={}] {} - status: {} [{}] {}",
           getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
           SftpConstants.getStatusName(substatus), lang, msg);
    }
    throwStatusException(cmd, id, substatus, msg, lang);
  }
  return handleUnexpectedHandlePacket(cmd, id, type, length, buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

/**
 * Checks if the incoming response is an {@code SSH_FXP_STATUS} one,
 * and if so whether the substatus is {@code SSH_FX_OK}.
 *
 * @param cmd The sent command opcode
 * @param buffer The received response {@link Buffer}
 * @throws IOException If response does not carry a status or carries
 * a bad status code
 * @see #checkResponseStatus(int, int, int, String, String)
 */
protected void checkResponseStatus(int cmd, Buffer buffer) throws IOException {
  int length = buffer.getInt();
  int type = buffer.getUByte();
  int id = buffer.getInt();
  if (type == SftpConstants.SSH_FXP_STATUS) {
    int substatus = buffer.getInt();
    String msg = buffer.getString();
    String lang = buffer.getString();
    checkResponseStatus(cmd, id, substatus, msg, lang);
  } else {
    //noinspection ThrowableResultOfMethodCallIgnored
    handleUnexpectedPacket(cmd, SftpConstants.SSH_FXP_STATUS, id, type, length, buffer);
  }
}

相关文章