}
protected void sendNextKey(PublicKey key) throws IOException {
try {
log.info("Send SSH_MSG_USERAUTH_REQUEST for publickey");
Buffer buffer = session.createBuffer(SshConstants.Message.SSH_MSG_USERAUTH_REQUEST, 0);
int pos1 = buffer.wpos() - 1;
buffer.putString(username);
buffer.putString(service);
buffer.putString("publickey");
buffer.putByte((byte) 1);
buffer.putString((key instanceof RSAPublicKey) ? KeyPairProvider.SSH_RSA : KeyPairProvider.SSH_DSS);
int pos2 = buffer.wpos();
buffer.putPublicKey(key);
Buffer bs = new Buffer();
bs.putString(session.getKex().getH());
bs.putCommand(SshConstants.Message.SSH_MSG_USERAUTH_REQUEST);
bs.putString(username);
bs.putString(service);
bs.putString("publickey");
bs.putByte((byte) 1);
bs.putString((key instanceof RSAPublicKey) ? KeyPairProvider.SSH_RSA : KeyPairProvider.SSH_DSS);
bs.putPublicKey(key);
Buffer bs2 = new Buffer();
bs2.putString((key instanceof RSAPublicKey) ? KeyPairProvider.SSH_RSA : KeyPairProvider.SSH_DSS);
bs2.putBytes(agent.sign(key, bs.getCompactData()));
buffer.putBytes(bs2.array(), bs2.rpos(), bs2.available());
session.writePacket(buffer);
} catch (IOException e) {
throw e;
} catch (Exception e) {