protected void sendClose() throws TransportException { openCloseLock.lock(); try { if (!closeRequested) { log.debug("Sending close"); trans.write(newBuffer(Message.CHANNEL_CLOSE)); } } finally { closeRequested = true; openCloseLock.unlock(); } }
protected void handleRequest(String reqType, SSHPacket buf) throws ConnectionException, TransportException { trans.write(newBuffer(Message.CHANNEL_FAILURE)); }
@Override public void request() throws UserAuthException, TransportException { params.getTransport().write(buildReq()); }
@Override protected void doKeepAlive() throws TransportException { conn.getTransport().write(new SSHPacket(Message.IGNORE)); } }
/** * Send SSH_MSG_USERAUTH_REQUEST containing the signature. * * @throws UserAuthException * @throws TransportException */ private void sendSignedReq() throws UserAuthException, TransportException { log.debug("Key acceptable, sending signed request"); params.getTransport().write(putSig(buildReq(true))); }
@Override public void open() throws ConnectionException, TransportException { trans.write(buildOpenReq()); openEvent.await(conn.getTimeoutMs(), TimeUnit.MILLISECONDS); }
private void sendToken(byte[] token) throws TransportException { SSHPacket packet = new SSHPacket(Message.USERAUTH_INFO_RESPONSE).putString(token); params.getTransport().write(packet); }
private void gotGlobalRequest(SSHPacket buf) throws ConnectionException, TransportException { try { final String requestName = buf.readString(); boolean wantReply = buf.readBoolean(); log.debug("Received GLOBAL_REQUEST `{}`; want reply: {}", requestName, wantReply); if (wantReply) { trans.write(new SSHPacket(Message.REQUEST_FAILURE)); } } catch (Buffer.BufferException be) { throw new ConnectionException(be); } }
private void respond(CharArrWrap[] userReplies) throws TransportException { final SSHPacket pkt = new SSHPacket(Message.USERAUTH_INFO_RESPONSE).putUInt32(userReplies.length); for (final CharArrWrap response : userReplies) pkt.putSensitiveString(response.arr); params.getTransport().write(pkt); }
protected Event<ConnectionException> sendChannelRequest(String reqType, boolean wantReply, Buffer.PlainBuffer reqSpecific) throws TransportException { log.debug("Sending channel request for `{}`", reqType); synchronized (chanReqResponseEvents) { trans.write( newBuffer(Message.CHANNEL_REQUEST) .putString(reqType) .putBoolean(wantReply) .putBuffer(reqSpecific) ); Event<ConnectionException> responseEvent = null; if (wantReply) { responseEvent = new Event<ConnectionException>("chan#" + id + " / " + "chanreq for " + reqType, ConnectionException.chainer, loggerFactory); chanReqResponseEvents.add(responseEvent); } return responseEvent; } }
private boolean parseGexGroup(SSHPacket buffer) throws Buffer.BufferException, GeneralSecurityException, TransportException { BigInteger p = buffer.readMPInt(); BigInteger g = buffer.readMPInt(); int bitLength = p.bitLength(); if (bitLength < minBits || bitLength > maxBits) { throw new GeneralSecurityException("Server generated gex p is out of range (" + bitLength + " bits)"); } log.debug("Received server p bitlength {}", bitLength); dh.init(new DHParameterSpec(p, g), trans.getConfig().getRandomFactory()); log.debug("Sending {}", Message.KEX_DH_GEX_INIT); trans.write(new SSHPacket(Message.KEX_DH_GEX_INIT).putBytes(dh.getE())); return false; } }
@Override public void init(Transport trans, String V_S, String V_C, byte[] I_S, byte[] I_C) throws GeneralSecurityException, TransportException { super.init(trans, V_S, V_C, I_S, I_C); digest.init(); log.debug("Sending {}", Message.KEX_DH_GEX_REQUEST); trans.write(new SSHPacket(Message.KEX_DH_GEX_REQUEST).putUInt32(minBits).putUInt32(preferredBits).putUInt32(maxBits)); }
@Override public void init(Transport trans, String V_S, String V_C, byte[] I_S, byte[] I_C) throws GeneralSecurityException, TransportException { super.init(trans, V_S, V_C, I_S, I_C); digest.init(); initDH(dh); log.debug("Sending SSH_MSG_KEXDH_INIT"); trans.write(new SSHPacket(Message.KEXDH_INIT).putBytes(dh.getE())); }
@Override public Promise<SSHPacket, ConnectionException> sendGlobalRequest(String name, boolean wantReply, byte[] specifics) throws TransportException { synchronized (globalReqPromises) { log.debug("Making global request for `{}`", name); trans.write(new SSHPacket(Message.GLOBAL_REQUEST).putString(name) .putBoolean(wantReply) .putRawBytes(specifics)); Promise<SSHPacket, ConnectionException> promise = null; if (wantReply) { promise = new Promise<SSHPacket, ConnectionException>("global req for " + name, ConnectionException.chainer, trans.getConfig().getLoggerFactory()); globalReqPromises.add(promise); } return promise; } }
private void checkWindow() throws TransportException { synchronized (win) { final long adjustment = win.neededAdjustment(); if (adjustment > 0) { log.debug("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment); trans.write(new SSHPacket(Message.CHANNEL_WINDOW_ADJUST) .putUInt32(chan.getRecipient()).putUInt32(adjustment)); win.expand(adjustment); } } }
@Override public void sendOpenFailure(int recipient, Reason reason, String message) throws TransportException { trans.write(new SSHPacket(Message.CHANNEL_OPEN_FAILURE) .putUInt32(recipient) .putUInt32(reason.getCode()) .putString(message)); }
@Override public void handle(Message cmd, SSHPacket buf) throws UserAuthException, TransportException { if (cmd == Message.USERAUTH_60) { handleContextInitialization(buf); } else if (cmd == Message.USERAUTH_INFO_RESPONSE) { byte[] token = handleTokenFromServer(buf); if (!secContext.isEstablished()) { log.debug("Sending token"); sendToken(token); } else { if (secContext.getIntegState()) { log.debug("Per-message integrity protection available: finalizing authentication with message integrity code"); params.getTransport().write(new SSHPacket(Message.USERAUTH_GSSAPI_MIC).putString(generateMIC())); } else { log.debug("Per-message integrity protection unavailable: finalizing authentication"); params.getTransport().write(new SSHPacket(Message.USERAUTH_GSSAPI_EXCHANGE_COMPLETE)); } } } else { super.handle(cmd, buf); } } }
@Override public void confirm() throws TransportException { log.debug("Confirming `{}` channel #{}", getType(), getID()); // Must ensure channel is attached before confirming, data could start coming in immediately! conn.attach(this); trans.write(newBuffer(Message.CHANNEL_OPEN_CONFIRMATION) .putUInt32(getID()) .putUInt32(getLocalWinSize()) .putUInt32(getLocalMaxPacketSize())); openEvent.set(); }
@Override public void handle(Message cmd, SSHPacket buf) throws UserAuthException, TransportException { if (cmd == Message.USERAUTH_60 && newPasswordProvider != null) { log.info("Received SSH_MSG_USERAUTH_PASSWD_CHANGEREQ."); try { String prompt = buf.readString(); buf.readString(); // lang-tag AccountResource resource = makeAccountResource(); char[] newPassword = newPasswordProvider.provideNewPassword(resource, prompt); SSHPacket sshPacket = super.buildReq().putBoolean(true).putSensitiveString(pwdf.reqPassword(resource)).putSensitiveString(newPassword); params.getTransport().write(sshPacket); } catch (Buffer.BufferException e) { throw new TransportException(e); } } else if (cmd == Message.USERAUTH_60) { throw new UserAuthException("Password change request received; unsupported operation (newPassword was 'null')"); } else { super.handle(cmd, buf); } }
trans.write(packet); win.consume(writeNow);