You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by GitBox <gi...@apache.org> on 2022/04/15 17:54:51 UTC
[GitHub] [mina-sshd] tomaswolf opened a new pull request, #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
tomaswolf opened a new pull request, #217:
URL: https://github.com/apache/mina-sshd/pull/217
Previous code flushed them synchronously before setting KEX state to
DONE. This could lead to deadlocks if there were exceptions and the
session got closed while flushing.
Moreover, AbstractSession.writePacket() had a race condition: after
having determined the kex state, it was still possible that an incoming
SSH_MSG_KEX_INIT would change the KEX state and then get the encodeLock
and send back its answer before the first thread. In that case the
client might have received a high-level message during KEX, which is
forbidden by RFC 4253.
Change the code to flush pending packets asynchronously. In
writePackets, keep enqueuing packets if KEX is DONE but we're still
flushing. To avoid keeping the flushing thread busy forever, we block
new writes, unless they are direct replies to SSH protocol messages.
I.e., channel data messages block the calling thread while flushing
is still in progress.
Some care has to be exercised to avoid new deadlocks. First, obviously
a thread holding the decodeLock must not be blocked. Second, threads
holding the futureLock must never block. Additionally, the code never
blocks writes that occur inside a future listener.
Note that while KEX is in progress (not DONE yet), an application may
put arbitrarily many packets onto the queue (for instance, if the
remote's channel window is large, and there's an asynchronous
application thread pumping data through a channel). This was the case
already before this change, and it is still the case. If there is so
much data in the queue that a new KEX will be triggered, the new code
will actually initiate a new KEX, flushing stops, and is resumed once
the new KEX finishes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1103647246
> This should be done carefully
Of course. I'm not being reckless.
As for complexity: yes, the current code is convoluted and complex, and uses too many locks with too broad scopes. Reducing synchronization on locks with broad scope, or possibly even eliminating some of these altogether simplifies the overall structure of the code and will make it easier to understand, even if it may _locally_ increase perceived complexity.
Factoring out certain things into dedicated classes/objects may actually help reducing complexity or at least keeping it local to isolated classes and making the code easier to understand overall.
The current implementation has bugs that cause deadlocks in production servers. I know we don't provide any guarantees that our open-source software actually works or was fit for any purpose, but personally I don't like maintaining software that I know has such bugs. As long as it's fun trying to solve such problems and as long as I do have the time, I'm happy to try.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1101229205
I changed this to "draft". I think it's the going the right way, but it still has problems. Looks like I really need to get rid of the synchronized methods in `ChannelOutputStream` and `ChannelAsyncOutputStream`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857178494
##########
sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java:
##########
@@ -70,6 +70,10 @@ public class ClientUserAuthService extends AbstractCloseable implements Service,
private UserAuth userAuth;
private int currentMethod;
+ private Object initLock = new Object();
Review Comment:
Done.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java:
##########
@@ -90,52 +93,174 @@ public byte getCommandType() {
return cmd;
}
- public void onWindowExpanded() throws IOException {
- doWriteIfPossible(true);
- }
-
+ /**
+ * {@inheritDoc}
+ *
+ * This write operation is <em>asynchronous</em>: if there is not enough window space, it may keep the write pending
+ * or write only part of the buffer and keep the rest pending. Concurrent writes are not allowed and will throw a
+ * {@link WritePendingException}. Any subsequent write <em>must</em> occur only once the returned future is
+ * fulfilled; for instance triggered via a listener on the returned future. Try to avoid doing a subsequent write
+ * directly in a future listener, though; doing so may lead to deep chains of nested listener calls with deep stack
+ * traces, and may ultimately lead to a stack overflow.
+ *
+ * @throws WritePendingException if a concurrent write is attempted
+ */
@Override
- public synchronized IoWriteFuture writeBuffer(Buffer buffer) throws IOException {
+ public IoWriteFuture writeBuffer(Buffer buffer) throws IOException {
if (isClosing()) {
- throw new EOFException("Closing: " + state);
+ throw new EOFException("Closing: " + writeState);
}
IoWriteFutureImpl future = new IoWriteFutureImpl(packetWriteId, buffer);
- if (!pendingWrite.compareAndSet(null, future)) {
- throw new WritePendingException("A write operation is already pending");
+ synchronized (writeState) {
+ if (writeState.isClosing()) { // Double check.
+ throw new EOFException("Closing: " + writeState);
+ }
+ if (writeState.writeInProgress) {
+ throw new WritePendingException("A write operation is already pending");
+ }
+ writeState.lastWrite = future;
+ writeState.pendingWrite = future;
+ writeState.writeInProgress = true;
+ writeState.waitingOnIo = false;
}
doWriteIfPossible(false);
return future;
}
@Override
protected void preClose() {
- if (!(packetWriter instanceof Channel)) {
- try {
- packetWriter.close();
- } catch (IOException e) {
- error("preClose({}) Failed ({}) to pre-close packet writer: {}",
- this, e.getClass().getSimpleName(), e.getMessage(), e);
+ synchronized (writeState) {
+ writeState.openState = state.get();
+ }
+ super.preClose();
+ }
+
+ @Override
+ protected void doCloseImmediately() {
+ try {
+ // Can't close this in preClose(); a graceful close waits for the currently pending write to finish and thus
+ // still needs the packet writer.
+ if (!(packetWriter instanceof Channel)) {
+ try {
+ packetWriter.close();
+ } catch (IOException e) {
+ error("preClose({}) Failed ({}) to pre-close packet writer: {}",
+ this, e.getClass().getSimpleName(), e.getMessage(), e);
+ }
}
+ super.doCloseImmediately();
+ } finally {
+ shutdown();
}
+ }
- super.preClose();
+ private void shutdown() {
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857178945
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -171,43 +227,52 @@ public synchronized void write(byte[] buf, int s, int l) throws IOException {
"Interrupted while waiting for remote space on write len=" + l + " to " + this)
.initCause(e);
}
- }
- session.resetIdleTimeout();
- continue;
+ session.resetIdleTimeout();
+ break;
+ default:
+ // BUFFERED implies l == 0; outer loop will terminate
+ break;
Review Comment:
Not done. I prefer to have *every* switch branch be terminated by a break, return, or throw. (I can't remember the last time I had the urge to use a fall-though.) It may not be necessary here, but it doesn't hurt.
##########
sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java:
##########
@@ -712,6 +762,17 @@ protected boolean handleServiceRequest(String serviceName, Buffer buffer) throws
return true;
}
+ private boolean validateServiceKexState(KexState state) {
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1100267827
@lgoldstein, @gnodet: this is my take on SSHD-966. The change factors out into a separate per-session object `KeyExchangeMessageHandler` all the logic about which packets to enqueue during KEX and how to flush them. Locally, I have green test runs, with a few flaky tests when Netty is used, but (a) I always have them, also without this change, and (b) the failures occur on connect() and are unrelated to KEX.
This resolves the race condition in `AbstractSession.writePacket()` I mentioned in SSHD-966, and avoids the lock inversion that could occur between the `ChannelOutputStream` and the flushing if some error occurred an the session was closed while flushing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r856517636
##########
docs/kex.md:
##########
@@ -0,0 +1,131 @@
+## SSH Key Exchange
+
+**Key Exchange** (or **KEX** for short) is a sub-protocol in the SSH protocol
+enabling the two parties in a connection to exchange information and compute a
+shared secret that will then be used for encrypting all following messages.
+
+A key exchange runs initially, after the network connection is established,
+but before authentication. Later on, KEX may be repeated; when exactly,
+depends on various settings:
+
+* it is re-run when a certain amount of bytes have been sent since the last KEX.
+* it may be re-run when a certain number of SSH packets have been sent since the last KEX.
+* it may be re-run when a certain time has elapsed since the last KEX.
+
+The purpose of re-running KEX is to establish a new shared secret from time to
+time, changing the encryption for all subsequent messages, until the next KEX.
+This mitigates possible attacks against the encryption when a lot of data is sent
+using the same encryption with the same shared secret.
+
+KEX is specified in [RFC 4253, section 7](https://tools.ietf.org/html/rfc4253#section-7).
+
+### Basic KEX message exchange
+
+A key exchange starts with both parties sending a SSH_MSG_KEX_INIT message,
+passing along information about available cryptographic algorithms. Both
+parties can decide from this information what kind of key exchange to perform.
+They then run the cryptographic key exchange protocol, which may incur several
+message exchanges. Once that protocol ends, both sides know the shared secret.
+At that point they both send a SSH_MSG_NEW_KEYS message to tell the other side
+they're ready, and use the new encryption for any subsequent outgoing message.
+The SSH_MSG_NEW_KEYS message itself is still sent with the old encryption. On
+receiving a SSH_MSG_NEW_KEYS message, each side starts using the new encryption
+to decrypt any subsequent incoming messages. Note that the SSH_MSG_NEW_KEYS
+message does not contain the new encryption key or the shared secret; it is
+just a marker message telling the other side that from now on, the new encryption
+will be used.
+
+Apache MINA sshd maintains internally in [`AbstractSession`](../sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java)
+a *KEX state* (in Java [`KexState`](../sshd-common/src/main/java/org/apache/sshd/common/kex/KexState.java)).
+This models the key exchange on one side of the connection as a state machine
+going through the states `DONE`, `INIT`, `RUN`, `KEYS`, `DONE`.
+
+
+
+These states mark important points in the key exchange sub-protocol:
+
+* `DONE` means no key exchange is ongoing, this side has received the peer's SSH_MSG_NEW_KEYS message, and both sides have a shared secret that they use for encryption.
+* `INIT` means this side of the connection has requested a new KEX; it has sent it's SSH_MSG_KEX_INIT message.
+* `RUN` means this side has received the peer's SSH_MSG_KEX_INIT message, and key exchange is running now to determine a new shared secret.
+* `KEYS` means the key exchange has been done; both sides know the shared secret, and this side has sent its SSH_MS_NEW_KEYS message.
+* When the peer's SSH_MSG_NEW_KEYS message is received, the state changes back to `DONE`.
+
+In Apache MINA sshd, there are methods in `AbstractSession` for each of the KEX
+messages:
+
+* `requestNewKeyExchange`: switches from `DONE` to `INIT` and calls `sendKexInit` to send the SSH_MSG_KEX_INIT message.
+* `handleKexInit`: receives the peer's SSH_MSG_KEX_INIT message; switches to `RUN`.
+* `sendNewKeys`: switches from `RUN` to `KEYS` and sends this side's SSH_MS_NEW_KEYS message.
+* `handleNewKeys`: receives the peer's SSH_MSG_KEX_INIT message; switches from `KEYS` to `DONE`.
+
+
+
+Because both sides my request a new key exchange at any time, it's also possible
Review Comment:
Thanks; will be fixed in the next update of this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857178515
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java:
##########
@@ -90,52 +93,174 @@ public byte getCommandType() {
return cmd;
}
- public void onWindowExpanded() throws IOException {
- doWriteIfPossible(true);
- }
-
+ /**
+ * {@inheritDoc}
+ *
+ * This write operation is <em>asynchronous</em>: if there is not enough window space, it may keep the write pending
+ * or write only part of the buffer and keep the rest pending. Concurrent writes are not allowed and will throw a
+ * {@link WritePendingException}. Any subsequent write <em>must</em> occur only once the returned future is
+ * fulfilled; for instance triggered via a listener on the returned future. Try to avoid doing a subsequent write
+ * directly in a future listener, though; doing so may lead to deep chains of nested listener calls with deep stack
+ * traces, and may ultimately lead to a stack overflow.
+ *
+ * @throws WritePendingException if a concurrent write is attempted
+ */
@Override
- public synchronized IoWriteFuture writeBuffer(Buffer buffer) throws IOException {
+ public IoWriteFuture writeBuffer(Buffer buffer) throws IOException {
if (isClosing()) {
- throw new EOFException("Closing: " + state);
+ throw new EOFException("Closing: " + writeState);
}
IoWriteFutureImpl future = new IoWriteFutureImpl(packetWriteId, buffer);
- if (!pendingWrite.compareAndSet(null, future)) {
- throw new WritePendingException("A write operation is already pending");
+ synchronized (writeState) {
+ if (writeState.isClosing()) { // Double check.
+ throw new EOFException("Closing: " + writeState);
+ }
+ if (writeState.writeInProgress) {
+ throw new WritePendingException("A write operation is already pending");
+ }
+ writeState.lastWrite = future;
+ writeState.pendingWrite = future;
+ writeState.writeInProgress = true;
+ writeState.waitingOnIo = false;
}
doWriteIfPossible(false);
return future;
}
@Override
protected void preClose() {
- if (!(packetWriter instanceof Channel)) {
- try {
- packetWriter.close();
- } catch (IOException e) {
- error("preClose({}) Failed ({}) to pre-close packet writer: {}",
- this, e.getClass().getSimpleName(), e.getMessage(), e);
+ synchronized (writeState) {
+ writeState.openState = state.get();
+ }
+ super.preClose();
+ }
+
+ @Override
+ protected void doCloseImmediately() {
+ try {
+ // Can't close this in preClose(); a graceful close waits for the currently pending write to finish and thus
+ // still needs the packet writer.
+ if (!(packetWriter instanceof Channel)) {
+ try {
+ packetWriter.close();
+ } catch (IOException e) {
+ error("preClose({}) Failed ({}) to pre-close packet writer: {}",
+ this, e.getClass().getSimpleName(), e.getMessage(), e);
+ }
}
+ super.doCloseImmediately();
+ } finally {
+ shutdown();
}
+ }
- super.preClose();
+ private void shutdown() {
+ IoWriteFutureImpl current = null;
+ synchronized (writeState) {
+ writeState.openState = State.Closed;
+ current = writeState.pendingWrite;
+ writeState.pendingWrite = null;
+ writeState.waitingOnIo = false;
+ }
+ if (current != null) {
+ terminateFuture(current);
+ }
+ }
+
+ private void terminateFuture(IoWriteFutureImpl future) {
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857178603
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java:
##########
@@ -282,4 +435,43 @@ public boolean isSendChunkIfRemoteWindowIsSmallerThanPacketSize() {
public void setSendChunkIfRemoteWindowIsSmallerThanPacketSize(boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize) {
this.sendChunkIfRemoteWindowIsSmallerThanPacketSize = sendChunkIfRemoteWindowIsSmallerThanPacketSize;
}
+
+ // Marker type to avoid repeated buffering
+ private static class BufferedFuture extends IoWriteFutureImpl {
+
+ BufferedFuture(Object id, Buffer buffer) {
+ super(id, buffer);
+ }
+ }
+
+ // Collects state variables; access is always synchronized on the single instance per stream.
+ private static class WriteState {
Review Comment:
Done.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -42,6 +43,19 @@
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class ChannelOutputStream extends OutputStream implements java.nio.channels.Channel, ChannelHolder {
+
+ private enum WriteState {
+ BUFFERED,
+ NEED_FLUSH,
+ NEED_SPACE
+ }
+
+ private enum OpenState {
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1107904736
There is no hurry. I'll see if the Gerrit team can run their test suite with this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1108173323
> I'll see if the Gerrit team can run their test suite with this.
https://bugs.chromium.org/p/gerrit/issues/detail?id=12758#c8
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1100578622
@tomaswolf The code is very complex and I am having a hard time following it - this is in no way criticism on it since I am aware of the complexity of the issue and the initial code state so I can truly appreciate the effort. I have reviewed it only from "30,000 feet" so to speak and nothing special stands out - however, I do admit I was not able to run through its logic with a fine toothcomb. My point is that I don't feel I can do justice to it so I trust you have reviewed it, thought about and tested it **thoroughly** since it touches on a most sensitive and crucial piece of the entire project. I appreciate the effort that must have gone into it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r856502302
##########
docs/kex.md:
##########
@@ -0,0 +1,131 @@
+## SSH Key Exchange
+
+**Key Exchange** (or **KEX** for short) is a sub-protocol in the SSH protocol
+enabling the two parties in a connection to exchange information and compute a
+shared secret that will then be used for encrypting all following messages.
+
+A key exchange runs initially, after the network connection is established,
+but before authentication. Later on, KEX may be repeated; when exactly,
+depends on various settings:
+
+* it is re-run when a certain amount of bytes have been sent since the last KEX.
+* it may be re-run when a certain number of SSH packets have been sent since the last KEX.
+* it may be re-run when a certain time has elapsed since the last KEX.
+
+The purpose of re-running KEX is to establish a new shared secret from time to
+time, changing the encryption for all subsequent messages, until the next KEX.
+This mitigates possible attacks against the encryption when a lot of data is sent
+using the same encryption with the same shared secret.
+
+KEX is specified in [RFC 4253, section 7](https://tools.ietf.org/html/rfc4253#section-7).
+
+### Basic KEX message exchange
+
+A key exchange starts with both parties sending a SSH_MSG_KEX_INIT message,
+passing along information about available cryptographic algorithms. Both
+parties can decide from this information what kind of key exchange to perform.
+They then run the cryptographic key exchange protocol, which may incur several
+message exchanges. Once that protocol ends, both sides know the shared secret.
+At that point they both send a SSH_MSG_NEW_KEYS message to tell the other side
+they're ready, and use the new encryption for any subsequent outgoing message.
+The SSH_MSG_NEW_KEYS message itself is still sent with the old encryption. On
+receiving a SSH_MSG_NEW_KEYS message, each side starts using the new encryption
+to decrypt any subsequent incoming messages. Note that the SSH_MSG_NEW_KEYS
+message does not contain the new encryption key or the shared secret; it is
+just a marker message telling the other side that from now on, the new encryption
+will be used.
+
+Apache MINA sshd maintains internally in [`AbstractSession`](../sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java)
+a *KEX state* (in Java [`KexState`](../sshd-common/src/main/java/org/apache/sshd/common/kex/KexState.java)).
+This models the key exchange on one side of the connection as a state machine
+going through the states `DONE`, `INIT`, `RUN`, `KEYS`, `DONE`.
+
+
+
+These states mark important points in the key exchange sub-protocol:
+
+* `DONE` means no key exchange is ongoing, this side has received the peer's SSH_MSG_NEW_KEYS message, and both sides have a shared secret that they use for encryption.
+* `INIT` means this side of the connection has requested a new KEX; it has sent it's SSH_MSG_KEX_INIT message.
+* `RUN` means this side has received the peer's SSH_MSG_KEX_INIT message, and key exchange is running now to determine a new shared secret.
+* `KEYS` means the key exchange has been done; both sides know the shared secret, and this side has sent its SSH_MS_NEW_KEYS message.
+* When the peer's SSH_MSG_NEW_KEYS message is received, the state changes back to `DONE`.
+
+In Apache MINA sshd, there are methods in `AbstractSession` for each of the KEX
+messages:
+
+* `requestNewKeyExchange`: switches from `DONE` to `INIT` and calls `sendKexInit` to send the SSH_MSG_KEX_INIT message.
+* `handleKexInit`: receives the peer's SSH_MSG_KEX_INIT message; switches to `RUN`.
+* `sendNewKeys`: switches from `RUN` to `KEYS` and sends this side's SSH_MS_NEW_KEYS message.
+* `handleNewKeys`: receives the peer's SSH_MSG_KEX_INIT message; switches from `KEYS` to `DONE`.
+
+
+
+Because both sides my request a new key exchange at any time, it's also possible
Review Comment:
Typo `may request`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r856517459
##########
docs/kex.md:
##########
@@ -0,0 +1,131 @@
+## SSH Key Exchange
+
+**Key Exchange** (or **KEX** for short) is a sub-protocol in the SSH protocol
+enabling the two parties in a connection to exchange information and compute a
+shared secret that will then be used for encrypting all following messages.
+
+A key exchange runs initially, after the network connection is established,
+but before authentication. Later on, KEX may be repeated; when exactly,
+depends on various settings:
+
+* it is re-run when a certain amount of bytes have been sent since the last KEX.
+* it may be re-run when a certain number of SSH packets have been sent since the last KEX.
+* it may be re-run when a certain time has elapsed since the last KEX.
+
+The purpose of re-running KEX is to establish a new shared secret from time to
+time, changing the encryption for all subsequent messages, until the next KEX.
+This mitigates possible attacks against the encryption when a lot of data is sent
+using the same encryption with the same shared secret.
+
+KEX is specified in [RFC 4253, section 7](https://tools.ietf.org/html/rfc4253#section-7).
+
+### Basic KEX message exchange
+
+A key exchange starts with both parties sending a SSH_MSG_KEX_INIT message,
+passing along information about available cryptographic algorithms. Both
+parties can decide from this information what kind of key exchange to perform.
+They then run the cryptographic key exchange protocol, which may incur several
+message exchanges. Once that protocol ends, both sides know the shared secret.
+At that point they both send a SSH_MSG_NEW_KEYS message to tell the other side
+they're ready, and use the new encryption for any subsequent outgoing message.
+The SSH_MSG_NEW_KEYS message itself is still sent with the old encryption. On
+receiving a SSH_MSG_NEW_KEYS message, each side starts using the new encryption
+to decrypt any subsequent incoming messages. Note that the SSH_MSG_NEW_KEYS
+message does not contain the new encryption key or the shared secret; it is
+just a marker message telling the other side that from now on, the new encryption
+will be used.
+
+Apache MINA sshd maintains internally in [`AbstractSession`](../sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java)
+a *KEX state* (in Java [`KexState`](../sshd-common/src/main/java/org/apache/sshd/common/kex/KexState.java)).
+This models the key exchange on one side of the connection as a state machine
+going through the states `DONE`, `INIT`, `RUN`, `KEYS`, `DONE`.
+
+
+
+These states mark important points in the key exchange sub-protocol:
+
+* `DONE` means no key exchange is ongoing, this side has received the peer's SSH_MSG_NEW_KEYS message, and both sides have a shared secret that they use for encryption.
+* `INIT` means this side of the connection has requested a new KEX; it has sent it's SSH_MSG_KEX_INIT message.
+* `RUN` means this side has received the peer's SSH_MSG_KEX_INIT message, and key exchange is running now to determine a new shared secret.
+* `KEYS` means the key exchange has been done; both sides know the shared secret, and this side has sent its SSH_MS_NEW_KEYS message.
+* When the peer's SSH_MSG_NEW_KEYS message is received, the state changes back to `DONE`.
+
+In Apache MINA sshd, there are methods in `AbstractSession` for each of the KEX
+messages:
+
+* `requestNewKeyExchange`: switches from `DONE` to `INIT` and calls `sendKexInit` to send the SSH_MSG_KEX_INIT message.
+* `handleKexInit`: receives the peer's SSH_MSG_KEX_INIT message; switches to `RUN`.
+* `sendNewKeys`: switches from `RUN` to `KEYS` and sends this side's SSH_MS_NEW_KEYS message.
+* `handleNewKeys`: receives the peer's SSH_MSG_KEX_INIT message; switches from `KEYS` to `DONE`.
+
+
Review Comment:
I can also use SVG. Won't make it much easier to change the diagrams, though. Inkscape has some problems with the SVG exported by the tool I used.
Binary files in git are totally fine. What is problematic are large files.
But I agree, let's use SVG for diagrams, and I'll also put the original source somewhere.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1100609787
I know it's non-trivial. That's why there are so many inline comments, and a lengthy commit message.
I've tested it as good as I can. But so far I've failed to write a test that would reproduce either the original lock inversion or the race (when run without this change).
I went through a number of false starts when developing this, which I discovered when tests failed. Luckily we do have a fairly comprehensive test suite, and it does some fairly unusual things in a number of places, too. If our test suite succeeds I'm fairly confident that a change is correct.
The overall state machine of KEX is not that complicated. In our code it's a bit hard to follow because it's intermingled with other code. I'll see if I can come up with some diagram that might help to understand this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1101422734
> Looks like I really need to get rid of the synchronized methods in ChannelOutputStream and ChannelAsyncOutputStream.
This should be done **carefully** - I believe the synchronization is in place for good reason. BTW, I dimly remember that I encountered the same issue and when I tried to get rid of the synchronization (or at least limit its scope) I got into trouble. Keeping my fingers crossed you can come up with something...
BTW, at some point it may be worth re-evaluating the price in effort and code complexity vs the benefits - this is what got me to abort the attempt originally - the code was becoming way too convoluted and the effort of maintaining in future releases seemed to me to be too prohibitive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857178553
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -42,6 +43,19 @@
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class ChannelOutputStream extends OutputStream implements java.nio.channels.Channel, ChannelHolder {
+
+ private enum WriteState {
Review Comment:
Made protected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857153233
##########
docs/kex.md:
##########
@@ -0,0 +1,131 @@
+## SSH Key Exchange
+
+**Key Exchange** (or **KEX** for short) is a sub-protocol in the SSH protocol
+enabling the two parties in a connection to exchange information and compute a
+shared secret that will then be used for encrypting all following messages.
+
+A key exchange runs initially, after the network connection is established,
+but before authentication. Later on, KEX may be repeated; when exactly,
+depends on various settings:
+
+* it is re-run when a certain amount of bytes have been sent since the last KEX.
+* it may be re-run when a certain number of SSH packets have been sent since the last KEX.
+* it may be re-run when a certain time has elapsed since the last KEX.
+
+The purpose of re-running KEX is to establish a new shared secret from time to
+time, changing the encryption for all subsequent messages, until the next KEX.
+This mitigates possible attacks against the encryption when a lot of data is sent
+using the same encryption with the same shared secret.
+
+KEX is specified in [RFC 4253, section 7](https://tools.ietf.org/html/rfc4253#section-7).
+
+### Basic KEX message exchange
+
+A key exchange starts with both parties sending a SSH_MSG_KEX_INIT message,
+passing along information about available cryptographic algorithms. Both
+parties can decide from this information what kind of key exchange to perform.
+They then run the cryptographic key exchange protocol, which may incur several
+message exchanges. Once that protocol ends, both sides know the shared secret.
+At that point they both send a SSH_MSG_NEW_KEYS message to tell the other side
+they're ready, and use the new encryption for any subsequent outgoing message.
+The SSH_MSG_NEW_KEYS message itself is still sent with the old encryption. On
+receiving a SSH_MSG_NEW_KEYS message, each side starts using the new encryption
+to decrypt any subsequent incoming messages. Note that the SSH_MSG_NEW_KEYS
+message does not contain the new encryption key or the shared secret; it is
+just a marker message telling the other side that from now on, the new encryption
+will be used.
+
+Apache MINA sshd maintains internally in [`AbstractSession`](../sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java)
+a *KEX state* (in Java [`KexState`](../sshd-common/src/main/java/org/apache/sshd/common/kex/KexState.java)).
+This models the key exchange on one side of the connection as a state machine
+going through the states `DONE`, `INIT`, `RUN`, `KEYS`, `DONE`.
+
+
+
+These states mark important points in the key exchange sub-protocol:
+
+* `DONE` means no key exchange is ongoing, this side has received the peer's SSH_MSG_NEW_KEYS message, and both sides have a shared secret that they use for encryption.
+* `INIT` means this side of the connection has requested a new KEX; it has sent it's SSH_MSG_KEX_INIT message.
+* `RUN` means this side has received the peer's SSH_MSG_KEX_INIT message, and key exchange is running now to determine a new shared secret.
+* `KEYS` means the key exchange has been done; both sides know the shared secret, and this side has sent its SSH_MS_NEW_KEYS message.
+* When the peer's SSH_MSG_NEW_KEYS message is received, the state changes back to `DONE`.
+
+In Apache MINA sshd, there are methods in `AbstractSession` for each of the KEX
+messages:
+
+* `requestNewKeyExchange`: switches from `DONE` to `INIT` and calls `sendKexInit` to send the SSH_MSG_KEX_INIT message.
+* `handleKexInit`: receives the peer's SSH_MSG_KEX_INIT message; switches to `RUN`.
+* `sendNewKeys`: switches from `RUN` to `KEYS` and sends this side's SSH_MS_NEW_KEYS message.
+* `handleNewKeys`: receives the peer's SSH_MSG_KEX_INIT message; switches from `KEYS` to `DONE`.
+
+
Review Comment:
Great - one more reason why I think SVGs are better is that they are basically text, so when one changes them GIT stores only the differences which are easier to review.
As far as inkspace is concerned - I was just suggesting it since it seems to be a popular open-source free tool (which I never used ....) but whatever SVG tool you prefer is just fine...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857179032
##########
sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java:
##########
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.common.session.helpers;
+
+import java.io.IOException;
+import java.net.ProtocolException;
+import java.security.GeneralSecurityException;
+import java.util.AbstractMap.SimpleImmutableEntry;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Queue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Supplier;
+
+import org.apache.sshd.common.SshConstants;
+import org.apache.sshd.common.future.DefaultKeyExchangeFuture;
+import org.apache.sshd.common.io.IoWriteFuture;
+import org.apache.sshd.common.kex.KexState;
+import org.apache.sshd.common.util.ExceptionUtils;
+import org.apache.sshd.common.util.ValidateUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.threads.ThreadUtils;
+import org.slf4j.Logger;
+
+/**
+ * Manages SSH message sending during a key exchange. RFC 4253 specifies that during a key exchange, no high-level
+ * messages are to be sent, but a receiver must be able to deal with messages "in flight" until the peer's
+ * {@link SshConstants#SSH_MSG_KEX_INIT} message is received.
+ * <p>
+ * Apache MINA sshd queues up high-level messages that threads try to send while a key exchange is ongoing, and sends
+ * them once the key exchange is done. Sending queued messages may make the peer re-trigger a new key exchange, in which
+ * case sending queued messages stops and is resumed at the end of the new key exchange.
+ * </p>
+ *
+ * @see <a href="https://tools.ietf.org/html/rfc4253#section-7">RFC 4253</a>
+ */
+public class KeyExchangeMessageHandler {
+
+ // With asynchronous flushing we get a classic producer-consumer problem. The flushing thread is the single
+ // consumer, and there is a risk that it might get overrun by the producers. The classical solution of using a
+ // LinkedBlockingQueue with a fixed maximum capacity doesn't work: we cannot make the producers block when the queue
+ // is full; we might deadlock or be unable to handle any incoming message.
+ //
+ // We need an unbounded queue that never blocks the producers, but that manages to throttle them such that the
+ // flushing thread can actually finish, and we still can handle incoming messages (in particular also the peer's
+ // SSH_MSG_NEW_KEYS, since we start flushing already after having sent our own SSH_MSG_NEW_KEYS).
+ //
+ // This is achieved by giving the flushing thread priority over the threads that might enqueue additional packets
+ // and flushing at least two packets at a time. Additionally the flush loop releases and shortly afterwards
+ // re-acquires the write lock, so normally not many readers (i.e., writePacket() calls) will get a chance to enqueue
+ // new packets.
+
+ /**
+ * We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over
+ * readers, and any state updates and the flushing thread are writers, while writePacket() is a reader.
+ */
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
Review Comment:
Done.
##########
sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java:
##########
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.common.session.helpers;
+
+import java.io.IOException;
+import java.net.ProtocolException;
+import java.security.GeneralSecurityException;
+import java.util.AbstractMap.SimpleImmutableEntry;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Queue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Supplier;
+
+import org.apache.sshd.common.SshConstants;
+import org.apache.sshd.common.future.DefaultKeyExchangeFuture;
+import org.apache.sshd.common.io.IoWriteFuture;
+import org.apache.sshd.common.kex.KexState;
+import org.apache.sshd.common.util.ExceptionUtils;
+import org.apache.sshd.common.util.ValidateUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.threads.ThreadUtils;
+import org.slf4j.Logger;
+
+/**
+ * Manages SSH message sending during a key exchange. RFC 4253 specifies that during a key exchange, no high-level
+ * messages are to be sent, but a receiver must be able to deal with messages "in flight" until the peer's
+ * {@link SshConstants#SSH_MSG_KEX_INIT} message is received.
+ * <p>
+ * Apache MINA sshd queues up high-level messages that threads try to send while a key exchange is ongoing, and sends
+ * them once the key exchange is done. Sending queued messages may make the peer re-trigger a new key exchange, in which
+ * case sending queued messages stops and is resumed at the end of the new key exchange.
+ * </p>
+ *
+ * @see <a href="https://tools.ietf.org/html/rfc4253#section-7">RFC 4253</a>
+ */
+public class KeyExchangeMessageHandler {
+
+ // With asynchronous flushing we get a classic producer-consumer problem. The flushing thread is the single
+ // consumer, and there is a risk that it might get overrun by the producers. The classical solution of using a
+ // LinkedBlockingQueue with a fixed maximum capacity doesn't work: we cannot make the producers block when the queue
+ // is full; we might deadlock or be unable to handle any incoming message.
+ //
+ // We need an unbounded queue that never blocks the producers, but that manages to throttle them such that the
+ // flushing thread can actually finish, and we still can handle incoming messages (in particular also the peer's
+ // SSH_MSG_NEW_KEYS, since we start flushing already after having sent our own SSH_MSG_NEW_KEYS).
+ //
+ // This is achieved by giving the flushing thread priority over the threads that might enqueue additional packets
+ // and flushing at least two packets at a time. Additionally the flush loop releases and shortly afterwards
+ // re-acquires the write lock, so normally not many readers (i.e., writePacket() calls) will get a chance to enqueue
+ // new packets.
+
+ /**
+ * We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over
+ * readers, and any state updates and the flushing thread are writers, while writePacket() is a reader.
+ */
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
+
+ private final ExecutorService flushRunner = Executors.newSingleThreadExecutor();
+
+ private final AbstractSession session;
+
+ private final Logger log;
+
+ /**
+ * Queues up high-level packets written during an ongoing key exchange.
+ */
+ private final Queue<PendingWriteFuture> pendingPackets = new LinkedList<>();
+
+ /**
+ * Indicates that all pending packets have been flushed.
+ */
+ private boolean kexFlushed = true;
+
+ /**
+ * Never {@code null}. Used to block some threads when writing packets while pending packets are still being flushed
+ * at the end of a KEX to avoid overrunning the flushing thread. Always set, initially fulfilled. At the beginning
+ * of a KEX a new future is installed, which is fulfilled at the end of the KEX once there are no more pending
+ * packets to be flushed.
+ */
+ private DefaultKeyExchangeFuture kexFlushedFuture;
+
+ /**
+ * Creates a new {@link KeyExchangeMessageHandler} for the given {@code session}, using the given {@code Logger}.
+ *
+ * @param session {@link AbstractSession} the new instance belongs to
+ * @param log {@link Logger} to use for writing log messages
+ */
+ public KeyExchangeMessageHandler(AbstractSession session, Logger log) {
+ this.session = Objects.requireNonNull(session);
+ this.log = Objects.requireNonNull(log);
+ // Start with a fulfilled kexFlushed future.
+ kexFlushedFuture = new DefaultKeyExchangeFuture(session.toString(), session.getFutureLock());
+ kexFlushedFuture.setValue(Boolean.TRUE);
+ }
+
+ public void updateState(Runnable update) {
+ lock.writeLock().lock();
+ try {
+ update.run();
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ public <V> V updateState(Supplier<V> update) {
+ lock.writeLock().lock();
+ try {
+ return update.get();
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ /**
+ * Initializes the state for a new key exchange. {@link #allPacketsFlushed()} will be {@code false}, and a new
+ * future to be fulfilled when all queued packets will be flushed once the key exchange is done is set. The
+ * currently set future from an earlier key exchange is returned. The returned future may or may not be fulfilled;
+ * if it isn't, there are still left-over pending packets to write from the previous key exchange, which will be
+ * written once the new key exchange flushes pending packets.
+ *
+ * @return the previous {@link DefaultKeyExchangeFuture} indicating whether all pending packets were flushed.
+ */
+ public DefaultKeyExchangeFuture initNewKeyExchange() {
+ return updateState(() -> {
+ kexFlushed = false;
+ DefaultKeyExchangeFuture oldFuture = kexFlushedFuture;
+ kexFlushedFuture = new DefaultKeyExchangeFuture(session.toString(), session.getFutureLock());
+ return oldFuture;
+ });
+ }
+
+ /**
+ * To be called when the key exchange is done. If there are any pending packets, returns a future that will be
+ * fulfilled when {@link #flushQueue(DefaultKeyExchangeFuture)} with that future as argument has flushed all pending
+ * packets, if there are any.
+ *
+ * @return the current {@link DefaultKeyExchangeFuture} and the number of currently pending packets
+ */
+ public SimpleImmutableEntry<Integer, DefaultKeyExchangeFuture> terminateKeyExchange() {
+ return updateState(() -> {
+ int numPending = pendingPackets.size();
+ if (numPending == 0) {
+ kexFlushed = true;
+ }
+ return new SimpleImmutableEntry<Integer, DefaultKeyExchangeFuture>(Integer.valueOf(numPending), kexFlushedFuture);
+ });
+ }
+
+ /**
+ * Pretends all pending packets had been written. To be called when the {@link AbstractSession} closes.
+ */
+ public void shutdown() {
+ SimpleImmutableEntry<Integer, DefaultKeyExchangeFuture> items = updateState(() -> {
+ kexFlushed = true;
+ return new SimpleImmutableEntry<Integer, DefaultKeyExchangeFuture>(
+ Integer.valueOf(pendingPackets.size()),
+ kexFlushedFuture);
+ });
+ items.getValue().setValue(Boolean.valueOf(items.getKey().intValue() == 0));
+ flushRunner.shutdownNow();
+ }
+
+ /**
+ * Writes a packet. If a key exchange is ongoing, only low-level messages are written directly; all other messages
+ * are queued and will be written once {@link #flushQueue(DefaultKeyExchangeFuture)} is called when the key exchange
+ * is done. Packets written while there are still pending packets to be flushed will either be queued, too, or the
+ * calling thread will be blocked with the given timeout until all packets have been flushed. Whether a write will
+ * be blocked is determined by {@link #isBlockAllowed(int)}.
+ * <p>
+ * If {@code timeout <= 0} or {@code unit == null}, a time-out of "forever" is assumed. Note that a timeout applies
+ * only if the calling thread is blocked.
+ * </p>
+ *
+ * @param buffer packet to write
+ * @param timeout number of {@link TimeUnit}s to wait at most if the calling thread is blocked
+ * @param unit {@link TimeUnit} of {@code timeout}
+ * @return an {@link IoWriteFuture} that will be fulfilled once the packet has indeed been written.
+ * @throws IOException if an error occurs
+ */
+ public IoWriteFuture writePacket(Buffer buffer, long timeout, TimeUnit unit) throws IOException {
+ // While exchanging key, queue high level packets.
+ byte[] bufData = buffer.array();
+ int cmd = bufData[buffer.rpos()] & 0xFF;
+ boolean enqueued = false;
+ boolean isLowLevelMessage = cmd <= SshConstants.SSH_MSG_KEX_LAST && cmd != SshConstants.SSH_MSG_SERVICE_REQUEST
+ && cmd != SshConstants.SSH_MSG_SERVICE_ACCEPT;
+ try {
+ if (isLowLevelMessage) {
+ // Low-level messages can always be sent.
+ return session.doWritePacket(buffer);
+ }
+ IoWriteFuture future = writeOrEnqueue(cmd, buffer, timeout, unit);
+ enqueued = future instanceof PendingWriteFuture;
+ return future;
+ } finally {
+ session.resetIdleTimeout();
+ if (!enqueued) {
+ try {
+ session.checkRekey();
+ } catch (GeneralSecurityException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("writePacket({}) failed ({}) to check re-key: {}", session, e.getClass().getSimpleName(),
+ e.getMessage(), e);
+ }
+ throw ValidateUtils.initializeExceptionCause(new ProtocolException(
+ "Failed (" + e.getClass().getSimpleName() + ")" + " to check re-key necessity: " + e.getMessage()),
+ e);
+ } catch (Exception e) {
+ ExceptionUtils.rethrowAsIoException(e);
+ }
+ }
+ }
+ }
+
+ private IoWriteFuture writeOrEnqueue(int cmd, Buffer buffer, long timeout, TimeUnit unit) throws IOException {
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r856503293
##########
docs/kex.md:
##########
@@ -0,0 +1,131 @@
+## SSH Key Exchange
+
+**Key Exchange** (or **KEX** for short) is a sub-protocol in the SSH protocol
+enabling the two parties in a connection to exchange information and compute a
+shared secret that will then be used for encrypting all following messages.
+
+A key exchange runs initially, after the network connection is established,
+but before authentication. Later on, KEX may be repeated; when exactly,
+depends on various settings:
+
+* it is re-run when a certain amount of bytes have been sent since the last KEX.
+* it may be re-run when a certain number of SSH packets have been sent since the last KEX.
+* it may be re-run when a certain time has elapsed since the last KEX.
+
+The purpose of re-running KEX is to establish a new shared secret from time to
+time, changing the encryption for all subsequent messages, until the next KEX.
+This mitigates possible attacks against the encryption when a lot of data is sent
+using the same encryption with the same shared secret.
+
+KEX is specified in [RFC 4253, section 7](https://tools.ietf.org/html/rfc4253#section-7).
+
+### Basic KEX message exchange
+
+A key exchange starts with both parties sending a SSH_MSG_KEX_INIT message,
+passing along information about available cryptographic algorithms. Both
+parties can decide from this information what kind of key exchange to perform.
+They then run the cryptographic key exchange protocol, which may incur several
+message exchanges. Once that protocol ends, both sides know the shared secret.
+At that point they both send a SSH_MSG_NEW_KEYS message to tell the other side
+they're ready, and use the new encryption for any subsequent outgoing message.
+The SSH_MSG_NEW_KEYS message itself is still sent with the old encryption. On
+receiving a SSH_MSG_NEW_KEYS message, each side starts using the new encryption
+to decrypt any subsequent incoming messages. Note that the SSH_MSG_NEW_KEYS
+message does not contain the new encryption key or the shared secret; it is
+just a marker message telling the other side that from now on, the new encryption
+will be used.
+
+Apache MINA sshd maintains internally in [`AbstractSession`](../sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java)
+a *KEX state* (in Java [`KexState`](../sshd-common/src/main/java/org/apache/sshd/common/kex/KexState.java)).
+This models the key exchange on one side of the connection as a state machine
+going through the states `DONE`, `INIT`, `RUN`, `KEYS`, `DONE`.
+
+
+
+These states mark important points in the key exchange sub-protocol:
+
+* `DONE` means no key exchange is ongoing, this side has received the peer's SSH_MSG_NEW_KEYS message, and both sides have a shared secret that they use for encryption.
+* `INIT` means this side of the connection has requested a new KEX; it has sent it's SSH_MSG_KEX_INIT message.
+* `RUN` means this side has received the peer's SSH_MSG_KEX_INIT message, and key exchange is running now to determine a new shared secret.
+* `KEYS` means the key exchange has been done; both sides know the shared secret, and this side has sent its SSH_MS_NEW_KEYS message.
+* When the peer's SSH_MSG_NEW_KEYS message is received, the state changes back to `DONE`.
+
+In Apache MINA sshd, there are methods in `AbstractSession` for each of the KEX
+messages:
+
+* `requestNewKeyExchange`: switches from `DONE` to `INIT` and calls `sendKexInit` to send the SSH_MSG_KEX_INIT message.
+* `handleKexInit`: receives the peer's SSH_MSG_KEX_INIT message; switches to `RUN`.
+* `sendNewKeys`: switches from `RUN` to `KEYS` and sends this side's SSH_MS_NEW_KEYS message.
+* `handleNewKeys`: receives the peer's SSH_MSG_KEX_INIT message; switches from `KEYS` to `DONE`.
+
+
Review Comment:
I was wondering if we could use vector graphics (SVGs) instead of binary PNG(s) (see *inkscape* for such a freeware tool). As a rule of thumb I believe it is not recomended to store binary files in GIT.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1106805227
OK, this is ready for review again. The CI build failures are SSHD-1256; that one test fails regularly. I don't know why, and I cannot reproduce locally, neither on OS X nor on Windows 10.
The four commits have commit messages explaining what is done; and the PR message at the top of this page has been updated, too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1100675000
> The overall state machine of KEX is not that complicated. In our code it's a bit hard to follow because it's intermingled with other code. I'll see if I can come up with some diagram that might help to understand this.
Maybe we can make it part of the README file(s) of our documentation somehow - just a suggestion...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857178648
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -50,12 +64,15 @@ public class ChannelOutputStream extends OutputStream implements java.nio.channe
private final Duration maxWaitTimeout;
private final byte cmd;
private final boolean eofOnClose;
- private final byte[] b = new byte[1];
- private final AtomicBoolean closedState = new AtomicBoolean(false);
+ private final AtomicReference<OpenState> openState = new AtomicReference<>(OpenState.OPEN);
+
+ private final Object bufferLock = new Object();
private Buffer buffer;
private int bufferLength;
private int lastSize;
- private boolean noDelay;
+ private boolean isFlushing;
+
+ private volatile boolean noDelay;
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857179062
##########
sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java:
##########
@@ -124,7 +128,15 @@ public Map<String, Object> getProperties() {
@Override
public void start() {
- // ignored
+ Runnable initial = null;
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857860639
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -171,43 +227,52 @@ public synchronized void write(byte[] buf, int s, int l) throws IOException {
"Interrupted while waiting for remote space on write len=" + l + " to " + this)
.initCause(e);
}
- }
- session.resetIdleTimeout();
- continue;
+ session.resetIdleTimeout();
+ break;
+ default:
+ // BUFFERED implies l == 0; outer loop will terminate
+ break;
Review Comment:
That's fine - a matter of coding style
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#issuecomment-1104155476
> As long as it's fun trying to solve such problems and as long as I do have the time, I'm happy to try
Go for it - that's the spirit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r856861589
##########
docs/kex.md:
##########
@@ -0,0 +1,131 @@
+## SSH Key Exchange
Review Comment:
It was your idea. :-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857153738
##########
sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java:
##########
@@ -70,6 +70,10 @@ public class ClientUserAuthService extends AbstractCloseable implements Service,
private UserAuth userAuth;
private int currentMethod;
+ private Object initLock = new Object();
Review Comment:
Recommend making *initLock* `final`
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java:
##########
@@ -90,52 +93,174 @@ public byte getCommandType() {
return cmd;
}
- public void onWindowExpanded() throws IOException {
- doWriteIfPossible(true);
- }
-
+ /**
+ * {@inheritDoc}
+ *
+ * This write operation is <em>asynchronous</em>: if there is not enough window space, it may keep the write pending
+ * or write only part of the buffer and keep the rest pending. Concurrent writes are not allowed and will throw a
+ * {@link WritePendingException}. Any subsequent write <em>must</em> occur only once the returned future is
+ * fulfilled; for instance triggered via a listener on the returned future. Try to avoid doing a subsequent write
+ * directly in a future listener, though; doing so may lead to deep chains of nested listener calls with deep stack
+ * traces, and may ultimately lead to a stack overflow.
+ *
+ * @throws WritePendingException if a concurrent write is attempted
+ */
@Override
- public synchronized IoWriteFuture writeBuffer(Buffer buffer) throws IOException {
+ public IoWriteFuture writeBuffer(Buffer buffer) throws IOException {
if (isClosing()) {
- throw new EOFException("Closing: " + state);
+ throw new EOFException("Closing: " + writeState);
}
IoWriteFutureImpl future = new IoWriteFutureImpl(packetWriteId, buffer);
- if (!pendingWrite.compareAndSet(null, future)) {
- throw new WritePendingException("A write operation is already pending");
+ synchronized (writeState) {
+ if (writeState.isClosing()) { // Double check.
+ throw new EOFException("Closing: " + writeState);
+ }
+ if (writeState.writeInProgress) {
+ throw new WritePendingException("A write operation is already pending");
+ }
+ writeState.lastWrite = future;
+ writeState.pendingWrite = future;
+ writeState.writeInProgress = true;
+ writeState.waitingOnIo = false;
}
doWriteIfPossible(false);
return future;
}
@Override
protected void preClose() {
- if (!(packetWriter instanceof Channel)) {
- try {
- packetWriter.close();
- } catch (IOException e) {
- error("preClose({}) Failed ({}) to pre-close packet writer: {}",
- this, e.getClass().getSimpleName(), e.getMessage(), e);
+ synchronized (writeState) {
+ writeState.openState = state.get();
+ }
+ super.preClose();
+ }
+
+ @Override
+ protected void doCloseImmediately() {
+ try {
+ // Can't close this in preClose(); a graceful close waits for the currently pending write to finish and thus
+ // still needs the packet writer.
+ if (!(packetWriter instanceof Channel)) {
+ try {
+ packetWriter.close();
+ } catch (IOException e) {
+ error("preClose({}) Failed ({}) to pre-close packet writer: {}",
+ this, e.getClass().getSimpleName(), e.getMessage(), e);
+ }
}
+ super.doCloseImmediately();
+ } finally {
+ shutdown();
}
+ }
- super.preClose();
+ private void shutdown() {
+ IoWriteFutureImpl current = null;
+ synchronized (writeState) {
+ writeState.openState = State.Closed;
+ current = writeState.pendingWrite;
+ writeState.pendingWrite = null;
+ writeState.waitingOnIo = false;
+ }
+ if (current != null) {
+ terminateFuture(current);
+ }
+ }
+
+ private void terminateFuture(IoWriteFutureImpl future) {
Review Comment:
Let's make this *protected* in the spirit of allowing users to overload anything they want in our code.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java:
##########
@@ -282,4 +435,43 @@ public boolean isSendChunkIfRemoteWindowIsSmallerThanPacketSize() {
public void setSendChunkIfRemoteWindowIsSmallerThanPacketSize(boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize) {
this.sendChunkIfRemoteWindowIsSmallerThanPacketSize = sendChunkIfRemoteWindowIsSmallerThanPacketSize;
}
+
+ // Marker type to avoid repeated buffering
+ private static class BufferedFuture extends IoWriteFutureImpl {
+
+ BufferedFuture(Object id, Buffer buffer) {
+ super(id, buffer);
+ }
+ }
+
+ // Collects state variables; access is always synchronized on the single instance per stream.
+ private static class WriteState {
Review Comment:
Let's make this *protected* (as well as its constructor, fields and methods) in the spirit of allowing users to overload anything they want in our code.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -171,43 +227,52 @@ public synchronized void write(byte[] buf, int s, int l) throws IOException {
"Interrupted while waiting for remote space on write len=" + l + " to " + this)
.initCause(e);
}
- }
- session.resetIdleTimeout();
- continue;
+ session.resetIdleTimeout();
+ break;
+ default:
+ // BUFFERED implies l == 0; outer loop will terminate
+ break;
Review Comment:
No need for *break* in *default* clause.
##########
sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java:
##########
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.common.session.helpers;
+
+import java.io.IOException;
+import java.net.ProtocolException;
+import java.security.GeneralSecurityException;
+import java.util.AbstractMap.SimpleImmutableEntry;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Queue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Supplier;
+
+import org.apache.sshd.common.SshConstants;
+import org.apache.sshd.common.future.DefaultKeyExchangeFuture;
+import org.apache.sshd.common.io.IoWriteFuture;
+import org.apache.sshd.common.kex.KexState;
+import org.apache.sshd.common.util.ExceptionUtils;
+import org.apache.sshd.common.util.ValidateUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.threads.ThreadUtils;
+import org.slf4j.Logger;
+
+/**
+ * Manages SSH message sending during a key exchange. RFC 4253 specifies that during a key exchange, no high-level
+ * messages are to be sent, but a receiver must be able to deal with messages "in flight" until the peer's
+ * {@link SshConstants#SSH_MSG_KEX_INIT} message is received.
+ * <p>
+ * Apache MINA sshd queues up high-level messages that threads try to send while a key exchange is ongoing, and sends
+ * them once the key exchange is done. Sending queued messages may make the peer re-trigger a new key exchange, in which
+ * case sending queued messages stops and is resumed at the end of the new key exchange.
+ * </p>
+ *
+ * @see <a href="https://tools.ietf.org/html/rfc4253#section-7">RFC 4253</a>
+ */
+public class KeyExchangeMessageHandler {
+
+ // With asynchronous flushing we get a classic producer-consumer problem. The flushing thread is the single
+ // consumer, and there is a risk that it might get overrun by the producers. The classical solution of using a
+ // LinkedBlockingQueue with a fixed maximum capacity doesn't work: we cannot make the producers block when the queue
+ // is full; we might deadlock or be unable to handle any incoming message.
+ //
+ // We need an unbounded queue that never blocks the producers, but that manages to throttle them such that the
+ // flushing thread can actually finish, and we still can handle incoming messages (in particular also the peer's
+ // SSH_MSG_NEW_KEYS, since we start flushing already after having sent our own SSH_MSG_NEW_KEYS).
+ //
+ // This is achieved by giving the flushing thread priority over the threads that might enqueue additional packets
+ // and flushing at least two packets at a time. Additionally the flush loop releases and shortly afterwards
+ // re-acquires the write lock, so normally not many readers (i.e., writePacket() calls) will get a chance to enqueue
+ // new packets.
+
+ /**
+ * We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over
+ * readers, and any state updates and the flushing thread are writers, while writePacket() is a reader.
+ */
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
Review Comment:
Let's make the members *protected* in the spirit of letting our users override whatever they like - e,g, provide their own derived handler.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -42,6 +43,19 @@
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class ChannelOutputStream extends OutputStream implements java.nio.channels.Channel, ChannelHolder {
+
+ private enum WriteState {
Review Comment:
Let's make this *protected* (or even *public*) in the spirit of allowing users to overload anything they want in our code.
##########
sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java:
##########
@@ -124,7 +128,15 @@ public Map<String, Object> getProperties() {
@Override
public void start() {
- // ignored
+ Runnable initial = null;
Review Comment:
No need to initialize *initial* to *null* since its value is set unconditionally inside the *synchronized* block.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java:
##########
@@ -90,52 +93,174 @@ public byte getCommandType() {
return cmd;
}
- public void onWindowExpanded() throws IOException {
- doWriteIfPossible(true);
- }
-
+ /**
+ * {@inheritDoc}
+ *
+ * This write operation is <em>asynchronous</em>: if there is not enough window space, it may keep the write pending
+ * or write only part of the buffer and keep the rest pending. Concurrent writes are not allowed and will throw a
+ * {@link WritePendingException}. Any subsequent write <em>must</em> occur only once the returned future is
+ * fulfilled; for instance triggered via a listener on the returned future. Try to avoid doing a subsequent write
+ * directly in a future listener, though; doing so may lead to deep chains of nested listener calls with deep stack
+ * traces, and may ultimately lead to a stack overflow.
+ *
+ * @throws WritePendingException if a concurrent write is attempted
+ */
@Override
- public synchronized IoWriteFuture writeBuffer(Buffer buffer) throws IOException {
+ public IoWriteFuture writeBuffer(Buffer buffer) throws IOException {
if (isClosing()) {
- throw new EOFException("Closing: " + state);
+ throw new EOFException("Closing: " + writeState);
}
IoWriteFutureImpl future = new IoWriteFutureImpl(packetWriteId, buffer);
- if (!pendingWrite.compareAndSet(null, future)) {
- throw new WritePendingException("A write operation is already pending");
+ synchronized (writeState) {
+ if (writeState.isClosing()) { // Double check.
+ throw new EOFException("Closing: " + writeState);
+ }
+ if (writeState.writeInProgress) {
+ throw new WritePendingException("A write operation is already pending");
+ }
+ writeState.lastWrite = future;
+ writeState.pendingWrite = future;
+ writeState.writeInProgress = true;
+ writeState.waitingOnIo = false;
}
doWriteIfPossible(false);
return future;
}
@Override
protected void preClose() {
- if (!(packetWriter instanceof Channel)) {
- try {
- packetWriter.close();
- } catch (IOException e) {
- error("preClose({}) Failed ({}) to pre-close packet writer: {}",
- this, e.getClass().getSimpleName(), e.getMessage(), e);
+ synchronized (writeState) {
+ writeState.openState = state.get();
+ }
+ super.preClose();
+ }
+
+ @Override
+ protected void doCloseImmediately() {
+ try {
+ // Can't close this in preClose(); a graceful close waits for the currently pending write to finish and thus
+ // still needs the packet writer.
+ if (!(packetWriter instanceof Channel)) {
+ try {
+ packetWriter.close();
+ } catch (IOException e) {
+ error("preClose({}) Failed ({}) to pre-close packet writer: {}",
+ this, e.getClass().getSimpleName(), e.getMessage(), e);
+ }
}
+ super.doCloseImmediately();
+ } finally {
+ shutdown();
}
+ }
- super.preClose();
+ private void shutdown() {
Review Comment:
Let's make this *protected* in the spirit of allowing users to overload anything they want in our code.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -50,12 +64,15 @@ public class ChannelOutputStream extends OutputStream implements java.nio.channe
private final Duration maxWaitTimeout;
private final byte cmd;
private final boolean eofOnClose;
- private final byte[] b = new byte[1];
- private final AtomicBoolean closedState = new AtomicBoolean(false);
+ private final AtomicReference<OpenState> openState = new AtomicReference<>(OpenState.OPEN);
+
+ private final Object bufferLock = new Object();
private Buffer buffer;
private int bufferLength;
private int lastSize;
- private boolean noDelay;
+ private boolean isFlushing;
+
+ private volatile boolean noDelay;
Review Comment:
Personally I am not a big fan of *volatile* as means of multi-threading safety - I prefer *AtomicBoolean*-s - but I defer to your judgement here if you prefer *volatile*
##########
sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java:
##########
@@ -712,6 +762,17 @@ protected boolean handleServiceRequest(String serviceName, Buffer buffer) throws
return true;
}
+ private boolean validateServiceKexState(KexState state) {
Review Comment:
Let's make this *protected* in the spirit of letting our users override whatever they like.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java:
##########
@@ -42,6 +43,19 @@
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class ChannelOutputStream extends OutputStream implements java.nio.channels.Channel, ChannelHolder {
+
+ private enum WriteState {
+ BUFFERED,
+ NEED_FLUSH,
+ NEED_SPACE
+ }
+
+ private enum OpenState {
Review Comment:
Let's make this *protected* (or even *public*) in the spirit of allowing users to overload anything they want in our code.
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java:
##########
@@ -282,4 +435,43 @@ public boolean isSendChunkIfRemoteWindowIsSmallerThanPacketSize() {
public void setSendChunkIfRemoteWindowIsSmallerThanPacketSize(boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize) {
this.sendChunkIfRemoteWindowIsSmallerThanPacketSize = sendChunkIfRemoteWindowIsSmallerThanPacketSize;
}
+
+ // Marker type to avoid repeated buffering
+ private static class BufferedFuture extends IoWriteFutureImpl {
Review Comment:
Let's make this *protected* (as well as its constructor and methods) in the spirit of allowing users to overload anything they want in our code.
##########
sshd-core/src/main/java/org/apache/sshd/common/session/helpers/KeyExchangeMessageHandler.java:
##########
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.common.session.helpers;
+
+import java.io.IOException;
+import java.net.ProtocolException;
+import java.security.GeneralSecurityException;
+import java.util.AbstractMap.SimpleImmutableEntry;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Queue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Supplier;
+
+import org.apache.sshd.common.SshConstants;
+import org.apache.sshd.common.future.DefaultKeyExchangeFuture;
+import org.apache.sshd.common.io.IoWriteFuture;
+import org.apache.sshd.common.kex.KexState;
+import org.apache.sshd.common.util.ExceptionUtils;
+import org.apache.sshd.common.util.ValidateUtils;
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.threads.ThreadUtils;
+import org.slf4j.Logger;
+
+/**
+ * Manages SSH message sending during a key exchange. RFC 4253 specifies that during a key exchange, no high-level
+ * messages are to be sent, but a receiver must be able to deal with messages "in flight" until the peer's
+ * {@link SshConstants#SSH_MSG_KEX_INIT} message is received.
+ * <p>
+ * Apache MINA sshd queues up high-level messages that threads try to send while a key exchange is ongoing, and sends
+ * them once the key exchange is done. Sending queued messages may make the peer re-trigger a new key exchange, in which
+ * case sending queued messages stops and is resumed at the end of the new key exchange.
+ * </p>
+ *
+ * @see <a href="https://tools.ietf.org/html/rfc4253#section-7">RFC 4253</a>
+ */
+public class KeyExchangeMessageHandler {
+
+ // With asynchronous flushing we get a classic producer-consumer problem. The flushing thread is the single
+ // consumer, and there is a risk that it might get overrun by the producers. The classical solution of using a
+ // LinkedBlockingQueue with a fixed maximum capacity doesn't work: we cannot make the producers block when the queue
+ // is full; we might deadlock or be unable to handle any incoming message.
+ //
+ // We need an unbounded queue that never blocks the producers, but that manages to throttle them such that the
+ // flushing thread can actually finish, and we still can handle incoming messages (in particular also the peer's
+ // SSH_MSG_NEW_KEYS, since we start flushing already after having sent our own SSH_MSG_NEW_KEYS).
+ //
+ // This is achieved by giving the flushing thread priority over the threads that might enqueue additional packets
+ // and flushing at least two packets at a time. Additionally the flush loop releases and shortly afterwards
+ // re-acquires the write lock, so normally not many readers (i.e., writePacket() calls) will get a chance to enqueue
+ // new packets.
+
+ /**
+ * We need the flushing thread to have priority over writing threads. So we use a lock that favors writers over
+ * readers, and any state updates and the flushing thread are writers, while writePacket() is a reader.
+ */
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
+
+ private final ExecutorService flushRunner = Executors.newSingleThreadExecutor();
+
+ private final AbstractSession session;
+
+ private final Logger log;
+
+ /**
+ * Queues up high-level packets written during an ongoing key exchange.
+ */
+ private final Queue<PendingWriteFuture> pendingPackets = new LinkedList<>();
+
+ /**
+ * Indicates that all pending packets have been flushed.
+ */
+ private boolean kexFlushed = true;
+
+ /**
+ * Never {@code null}. Used to block some threads when writing packets while pending packets are still being flushed
+ * at the end of a KEX to avoid overrunning the flushing thread. Always set, initially fulfilled. At the beginning
+ * of a KEX a new future is installed, which is fulfilled at the end of the KEX once there are no more pending
+ * packets to be flushed.
+ */
+ private DefaultKeyExchangeFuture kexFlushedFuture;
+
+ /**
+ * Creates a new {@link KeyExchangeMessageHandler} for the given {@code session}, using the given {@code Logger}.
+ *
+ * @param session {@link AbstractSession} the new instance belongs to
+ * @param log {@link Logger} to use for writing log messages
+ */
+ public KeyExchangeMessageHandler(AbstractSession session, Logger log) {
+ this.session = Objects.requireNonNull(session);
+ this.log = Objects.requireNonNull(log);
+ // Start with a fulfilled kexFlushed future.
+ kexFlushedFuture = new DefaultKeyExchangeFuture(session.toString(), session.getFutureLock());
+ kexFlushedFuture.setValue(Boolean.TRUE);
+ }
+
+ public void updateState(Runnable update) {
+ lock.writeLock().lock();
+ try {
+ update.run();
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ public <V> V updateState(Supplier<V> update) {
+ lock.writeLock().lock();
+ try {
+ return update.get();
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ /**
+ * Initializes the state for a new key exchange. {@link #allPacketsFlushed()} will be {@code false}, and a new
+ * future to be fulfilled when all queued packets will be flushed once the key exchange is done is set. The
+ * currently set future from an earlier key exchange is returned. The returned future may or may not be fulfilled;
+ * if it isn't, there are still left-over pending packets to write from the previous key exchange, which will be
+ * written once the new key exchange flushes pending packets.
+ *
+ * @return the previous {@link DefaultKeyExchangeFuture} indicating whether all pending packets were flushed.
+ */
+ public DefaultKeyExchangeFuture initNewKeyExchange() {
+ return updateState(() -> {
+ kexFlushed = false;
+ DefaultKeyExchangeFuture oldFuture = kexFlushedFuture;
+ kexFlushedFuture = new DefaultKeyExchangeFuture(session.toString(), session.getFutureLock());
+ return oldFuture;
+ });
+ }
+
+ /**
+ * To be called when the key exchange is done. If there are any pending packets, returns a future that will be
+ * fulfilled when {@link #flushQueue(DefaultKeyExchangeFuture)} with that future as argument has flushed all pending
+ * packets, if there are any.
+ *
+ * @return the current {@link DefaultKeyExchangeFuture} and the number of currently pending packets
+ */
+ public SimpleImmutableEntry<Integer, DefaultKeyExchangeFuture> terminateKeyExchange() {
+ return updateState(() -> {
+ int numPending = pendingPackets.size();
+ if (numPending == 0) {
+ kexFlushed = true;
+ }
+ return new SimpleImmutableEntry<Integer, DefaultKeyExchangeFuture>(Integer.valueOf(numPending), kexFlushedFuture);
+ });
+ }
+
+ /**
+ * Pretends all pending packets had been written. To be called when the {@link AbstractSession} closes.
+ */
+ public void shutdown() {
+ SimpleImmutableEntry<Integer, DefaultKeyExchangeFuture> items = updateState(() -> {
+ kexFlushed = true;
+ return new SimpleImmutableEntry<Integer, DefaultKeyExchangeFuture>(
+ Integer.valueOf(pendingPackets.size()),
+ kexFlushedFuture);
+ });
+ items.getValue().setValue(Boolean.valueOf(items.getKey().intValue() == 0));
+ flushRunner.shutdownNow();
+ }
+
+ /**
+ * Writes a packet. If a key exchange is ongoing, only low-level messages are written directly; all other messages
+ * are queued and will be written once {@link #flushQueue(DefaultKeyExchangeFuture)} is called when the key exchange
+ * is done. Packets written while there are still pending packets to be flushed will either be queued, too, or the
+ * calling thread will be blocked with the given timeout until all packets have been flushed. Whether a write will
+ * be blocked is determined by {@link #isBlockAllowed(int)}.
+ * <p>
+ * If {@code timeout <= 0} or {@code unit == null}, a time-out of "forever" is assumed. Note that a timeout applies
+ * only if the calling thread is blocked.
+ * </p>
+ *
+ * @param buffer packet to write
+ * @param timeout number of {@link TimeUnit}s to wait at most if the calling thread is blocked
+ * @param unit {@link TimeUnit} of {@code timeout}
+ * @return an {@link IoWriteFuture} that will be fulfilled once the packet has indeed been written.
+ * @throws IOException if an error occurs
+ */
+ public IoWriteFuture writePacket(Buffer buffer, long timeout, TimeUnit unit) throws IOException {
+ // While exchanging key, queue high level packets.
+ byte[] bufData = buffer.array();
+ int cmd = bufData[buffer.rpos()] & 0xFF;
+ boolean enqueued = false;
+ boolean isLowLevelMessage = cmd <= SshConstants.SSH_MSG_KEX_LAST && cmd != SshConstants.SSH_MSG_SERVICE_REQUEST
+ && cmd != SshConstants.SSH_MSG_SERVICE_ACCEPT;
+ try {
+ if (isLowLevelMessage) {
+ // Low-level messages can always be sent.
+ return session.doWritePacket(buffer);
+ }
+ IoWriteFuture future = writeOrEnqueue(cmd, buffer, timeout, unit);
+ enqueued = future instanceof PendingWriteFuture;
+ return future;
+ } finally {
+ session.resetIdleTimeout();
+ if (!enqueued) {
+ try {
+ session.checkRekey();
+ } catch (GeneralSecurityException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("writePacket({}) failed ({}) to check re-key: {}", session, e.getClass().getSimpleName(),
+ e.getMessage(), e);
+ }
+ throw ValidateUtils.initializeExceptionCause(new ProtocolException(
+ "Failed (" + e.getClass().getSimpleName() + ")" + " to check re-key necessity: " + e.getMessage()),
+ e);
+ } catch (Exception e) {
+ ExceptionUtils.rethrowAsIoException(e);
+ }
+ }
+ }
+ }
+
+ private IoWriteFuture writeOrEnqueue(int cmd, Buffer buffer, long timeout, TimeUnit unit) throws IOException {
Review Comment:
Let's make this *protected* in the spirit of letting our users override whatever they like.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r857178527
##########
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java:
##########
@@ -282,4 +435,43 @@ public boolean isSendChunkIfRemoteWindowIsSmallerThanPacketSize() {
public void setSendChunkIfRemoteWindowIsSmallerThanPacketSize(boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize) {
this.sendChunkIfRemoteWindowIsSmallerThanPacketSize = sendChunkIfRemoteWindowIsSmallerThanPacketSize;
}
+
+ // Marker type to avoid repeated buffering
+ private static class BufferedFuture extends IoWriteFutureImpl {
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] lgoldstein commented on a diff in pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
lgoldstein commented on code in PR #217:
URL: https://github.com/apache/mina-sshd/pull/217#discussion_r856503925
##########
docs/kex.md:
##########
@@ -0,0 +1,131 @@
+## SSH Key Exchange
Review Comment:
This is a very good idea to document this - I always thought about it, but never got around to it. Great initiative
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org
[GitHub] [mina-sshd] tomaswolf merged pull request #217: [SSHD-966] Flush pending packets asynchronously at end of KEX
Posted by GitBox <gi...@apache.org>.
tomaswolf merged PR #217:
URL: https://github.com/apache/mina-sshd/pull/217
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org