tomaswolf commented on issue #403:
URL: https://github.com/apache/mina-sshd/issues/403#issuecomment-1682436151

   Thanks, that helps. I was a bit confused for a moment by the log being 
chronologically descending, but that's OK. The interesting bit are these two 
lines:
   ```
   2023-08-17T03:46:06-07:00    2023-08-17T10:46:06.268Z TRACE 345 --- [] [] [] 
[)-nio2-thread-5] o.a.s.server.session.ServerSessionImpl   : 
decode(ServerSessionImpl[user@/10.209.10.5:23011]) packet #15 [chunk 
#2](128/65573) ff e3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    
................................................................
   2023-08-17T03:46:06-07:00    2023-08-17T10:46:06.268Z TRACE 345 --- [] [] [] 
[)-nio2-thread-5] o.a.s.server.session.ServerSessionImpl   : 
decode(ServerSessionImpl[user@/10.209.10.5:23011]) packet #15 [chunk 
#1](64/65573) 5e 00 00 00 00 00 01 00 1c 00 01 00 18 06 00 00 04 d2 00 00 00 20 
38 32 35 64 35 64 64 33 61 38 30 35 36 34 38 65 65 66 35 35 33 62 64 66 33 61 
64 39 37 66 36 66 00 00 00 00 00 00 00 00 00 00    
^.....................825d5dd3a805648eef553bdf3ad97f6f..........
   ```
   This shows the SSH message itself is internally consistent. We have
   
   - `5e` SSH_MSG_CHANNEL_DATA
   - `00 00 00 00` Channel ID = 0
   - `00 01 00 1c` Length of data following: 65564 bytes, which is higher than 
the packet size you configured (65536)
   
   Next comes the data itself, which is an SFTP write request:
   
   - `00 01 00 18`  Length of data following: 65560 bytes
   - `06` SSH_FXP_WRITE
   - `00 00 04 d2` SFTP request ID
   - `00 00 00 20` SFTP file handle length (32)
   - 32 bytes containing the SFTP file handle "825d5dd3a805648eef553bdf3ad97f6f"
   - `00 00 00 00 00 00 00 00` File position to write to: offset 0
   - `00 00 ff e3` number of bytes to write: 65507 bytes
   - 65507 data bytes following (incidentally all zero bytes)
   
   Also visible from the log: it's the first SSH_FXP_WRITE request for this 
file (there's an SSH_FXP_OPEN request just before).
   
   So whatever that client is doing, it really is sending 28 bytes too many. I 
do notice that 28 = 32 - 4. OpenSSH returns handles that have only 4 bytes. 
Apache MINA sshd uses by default handles of 16 bytes AFAIK. You seem to have to 
configured 32 bytes.
   (For the configuration, see 
[`SftpModuleProperties.FILE_HANDLE_SIZE`](https://github.com/apache/mina-sshd/blob/786fd51ba20e0dc1ed998a6fe3772156983e18a9/sshd-sftp/src/main/java/org/apache/sshd/sftp/SftpModuleProperties.java#L220).
 Apache MINA sshd allows values between 4 and 64.)
   
   The SFTP draft RFCs say that SFTP file handles may be up to 256 bytes long.
   
   If you set the handle size in the Apache MINA sshd server to 16 bytes, does 
that client then send 12 extra bytes? And if the handle size is 40 bytes, does 
it then send 36 extra bytes? If so, we'd have established that this SFTP client 
can only handle SFTP file handles of 4 bytes. For larger handles, its length 
logic for SFTP write requests (SSH_FXP_WRITE) is wrong.
   
   This would also explain why it works with OpenSSH: an OpenSSH server will 
use a handle size of 4 bytes.


-- 
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-unsubscr...@mina.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to