hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
705 stars 179 forks source link

SMB3 file share wrong recognized as SMBv1 #820

Closed koettert closed 4 months ago

koettert commented 5 months ago

Hi, A KNIME user experiences a strange problem that the connection to the same file share occasionally is wrong recognized as SMBv1 resulting in the following error:

Caused by: java.util.concurrent.ExecutionException: com.hierynomus.smbj.common.SMBRuntimeException: com.hierynomus.mssmb.SMB1NotSupportedException: SMBv1 is not supported by SMBJ   at com.hierynomus.protocol.commons.concurrent.PromiseBackedFuture.get(PromiseBackedFuture.java:59)   at com.hierynomus.protocol.commons.concurrent.CancellableFuture.get(CancellableFuture.java:84)   at com.hierynomus.protocol.commons.concurrent.Futures.get(Futures.java:42)   ... 21 more Caused by: com.hierynomus.smbj.common.SMBRuntimeException: com.hierynomus.mssmb.SMB1NotSupportedException: SMBv1 is not supported by SMBJ   at com.hierynomus.smbj.common.SMBRuntimeException$1.wrap(SMBRuntimeException.java:28)   at com.hierynomus.smbj.common.SMBRuntimeException$1.wrap(SMBRuntimeException.java:22)   at com.hierynomus.protocol.commons.concurrent.Promise.deliverError(Promise.java:95)   at com.hierynomus.smbj.connection.OutstandingRequests.handleError(OutstandingRequests.java:88)   at com.hierynomus.smbj.connection.Connection.handleError(Connection.java:293)   at com.hierynomus.smbj.transport.PacketReader.run(PacketReader.java:54)   at java.base/java.lang.Thread.run(Unknown Source) Caused by: com.hierynomus.mssmb.SMB1NotSupportedException: SMBv1 is not supported by SMBJ   at com.hierynomus.mssmb.SMB1PacketFactory.read(SMB1PacketFactory.java:26)   at com.hierynomus.mssmb.SMB1PacketFactory.read(SMB1PacketFactory.java:23)   at com.hierynomus.smbj.connection.Connection$DelegatingSMBMessageConverter.read(Connection.java:332)   at com.hierynomus.smbj.connection.Connection$DelegatingSMBMessageConverter.read(Connection.java:321)   at com.hierynomus.smbj.transport.tcp.direct.DirectTcpPacketReader.readPacket(DirectTcpPacketReader.java:42)   at com.hierynomus.smbj.transport.tcp.direct.DirectTcpPacketReader.doRead(DirectTcpPacketReader.java:49)   at com.hierynomus.smbj.transport.PacketReader.readPacket(PacketReader.java:70)   at com.hierynomus.smbj.transport.PacketReader.run(PacketReader.java:48)

Any idea what could cause this occasional false error message? Any additional information that would help solve this mystery? Any settings that could enforce the library to enforce SMBv3 instead of calling the SMB1PacketFactory.canHandle() method? Thanks Tobias

koettert commented 4 months ago

I have more details about the SMB server:

Vendor – Microsoft
Version – 1607
Operating system - Windows Server 2016
Build - 14393.6796

and the used SmbConfig:

final var builder = SmbConfig.builder() //
                .withMultiProtocolNegotiate(true) //
                .withSocketFactory(new ProxySocketFactory(30000))//
                .withDfsEnabled(true) //
                .withTimeout(0, TimeUnit.SECONDS) //
                .withEncryptData(false)
               .withDialects(new SMB2Dialect[]{SMB2Dialect.SMB_2_1, SMB2Dialect.SMB_2_0_2});

Any idea what could cause these occasional SMBv1 error messages?

hierynomus commented 4 months ago

Hi Tobias! Long time already since we spoke.

SMBJ will only go into the SMB1PacketFactory if the message received from the server is an SMB1 message type (Different message format entirely). To enforce a server to always talk SMB2/3, you could disable the withMultiProtocolNegotiate. That flag will actually start with sending an SMB1 message asking the server to upgrade to SMB2 if possible.

If you disable that flag, SMBJ will initiate the connection using an SMB2 message, but this will give a connection setup error if the server really does not support SMB1.

So my only suggestion would be to disable that, or check on the server side why the server is responding SMB1 only.

koettert commented 4 months ago

Hi @hierynomus it is good hearing from you. Thanks a lot for your valuable input. We will check with the user to see if hey can figure out why the server is occasionally sending the wrong format and if not disable the negotiation as you proposed. I will close the issue since it is not related to the SMBJ.