hierynomus / smbj

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

Question:0.11.3版本获取Session,Caused by: java.lang.NoSuchMethodError: org.bouncycastle.crypto.StreamCipher.processBytes #688

Closed zhengguofen closed 2 years ago

zhengguofen commented 2 years ago

您好,感谢你的开源分享,才能够使用如此好用的工具。 我在学习使用过程中,将0.11.3版本集成到我spring 项目中,在获取Session session = connection.authenticate(ac)时,需要调用如图方法时,会出现找不到bcprov-jdk15on-1.69.jar包的StreamCipher的实现类,通过查看代码,此包中含有多个实现类,包括您要用的RC4Engine等。于此同时,当我通过java的main方法为入口获取时,此异常是没有出现的。 Caused by: java.lang.NoSuchMethodError: org.bouncycastle.crypto.StreamCipher.processBytes([BII[BI)I at com.hierynomus.security.bc.BCCipherFactory$BCStreamCipher.update(BCCipherFactory.java:119) ~[smbj-0.11.3.jar:?] at com.hierynomus.ntlm.functions.NtlmFunctions.encryptRc4(NtlmFunctions.java:230) ~[smbj-0.11.3.jar:?] at com.hierynomus.smbj.auth.NtlmAuthenticator.authenticate(NtlmAuthenticator.java:115) ~[smbj-0.11.3.jar:?] at com.hierynomus.smbj.connection.SMBSessionBuilder.processAuthenticationToken(SMBSessionBuilder.java:178) ~[smbj-0.11.3.jar:?] at com.hierynomus.smbj.connection.SMBSessionBuilder.setupSession(SMBSessionBuilder.java:141) ~[smbj-0.11.3.jar:?] at com.hierynomus.smbj.connection.SMBSessionBuilder.establish(SMBSessionBuilder.java:109) ~[smbj-0.11.3.jar:?] at com.hierynomus.smbj.connection.Connection.authenticate(Connection.java:202) ~[smbj-0.11.3.jar:?]

1642581117(1) 我是初学者,目前暂时没有找到两种方式获取Session的区别,若各位大神能够重现,能讲解一二更好,谢谢!

hierynomus commented 2 years ago

Sorry, could you post your ticket in English? I cannot read anything except the stacktrace.

zhengguofen commented 2 years ago

Hi,@hierynomus I'm sorry, if you can please help me again.

I integrated version 0.11.3 into my studied project(user Spring MVC). When I get a "Session" from the "Controller" (Session session = connection. Authenticate (AC) in your example), the exception will appear like that(Caused by: java.lang.NoSuchMethodError...).

So I debugger it, the exception appears as shown in the figure, The implementation class of "Streamcipher" cannot be found in the bcprov-jdk15on-1.69.jar package. And then,I found that this package already contains multiple implementation classes, including the "Rc4engine" you want to use.

However, when I repeat the above process through Java's "main" method, this exception does not appear.

May be Spring IOC bean not be found in my project? May be other? If you can reproduce this exception,generous with your criticism(不吝赐教),Thank you!

lawern commented 2 years ago

In our spring application the error occurs as well:

Caused by: java.lang.NoSuchMethodError: 'int org.bouncycastle.crypto.StreamCipher.processBytes(byte[], int, int, byte[], int)'
    at com.hierynomus.security.bc.BCCipherFactory$BCStreamCipher.update(BCCipherFactory.java:119) ~[shared/:na]
    at com.hierynomus.ntlm.functions.NtlmFunctions.encryptRc4(NtlmFunctions.java:230) ~[shared/:na]
    at com.hierynomus.smbj.auth.NtlmAuthenticator.authenticate(NtlmAuthenticator.java:115) ~[shared/:na]
    at com.hierynomus.smbj.connection.SMBSessionBuilder.processAuthenticationToken(SMBSessionBuilder.java:178) ~[shared/:na]
    at com.hierynomus.smbj.connection.SMBSessionBuilder.setupSession(SMBSessionBuilder.java:141) ~[shared/:na]
    at com.hierynomus.smbj.connection.SMBSessionBuilder.establish(SMBSessionBuilder.java:109) ~[shared/:na]
    at com.hierynomus.smbj.connection.Connection.authenticate(Connection.java:202) ~[shared/:na]

In our JUnit tests, this authentication also works without any problems.

Is there already a workaround?

zhengguofen commented 2 years ago

@lawern I went back to 0.10.0, but the same problem did not appear for the time being.

I still didn't find the reason for 0.11.3

lawern commented 2 years ago

I have found the cause. In my case the application was built to an uberJar. During the build of the uberJar a shadowing is done. This changed the package name from "org.bouncycastle.crypto" to "shared.org.bouncycastle.crypto".

My workaround is that I added the bouncycastle jar to the uberJar in build.gradle once again:

uberJar('org.bouncycastle:bcprov-jdk15on:1.69')

hierynomus commented 2 years ago

@lawern I went back to 0.10.0, but the same problem did not appear for the time being.

I still didn't find the reason for 0.11.3

Correct, in 0.11.3 SMB3 is turned on by default, which requires encryption, and thus the Ciphers. 0.10.0 doesn't use encryption.

Your problem is most likely with how you bundle your app. This is no fault of SMBJ.

zhengguofen commented 2 years ago

@lawern I went back to 0.10.0, but the same problem did not appear for the time being. I still didn't find the reason for 0.11.3

Correct, in 0.11.3 SMB3 is turned on by default, which requires encryption, and thus the Ciphers. 0.10.0 doesn't use encryption.

Your problem is most likely with how you bundle your app. This is no fault of SMBJ.

Thank you. I'll try again.