jargon2-api icon indicating copy to clipboard operation
jargon2-api copied to clipboard

Could not find appropriate jargon2Backend. Use either a service provider or define its class with -Dcom.kosprov.jargon2.spi.backend

Open RMrenex opened this issue 4 years ago • 23 comments

Hi,

I am using your library in one of my minecraft plugins and I have this error: https://pastebin.com/WppHxW6w

Thanks for your help.

RMrenex avatar Jan 30 '21 21:01 RMrenex

Hi,

Have you added the dependency to a backend? Like that:

<dependency>
    <groupId>com.kosprov.jargon2</groupId>
    <artifactId>jargon2-native-ri-backend</artifactId>
    <version>1.1.1</version>
    <scope>runtime</scope>
</dependency>

kosprov avatar Jan 31 '21 07:01 kosprov

Yes, here is my pom.xml : http://pastebin.fr/82704

RMrenex avatar Jan 31 '21 17:01 RMrenex

I would, first, remove the <scope>runtime</scope> from the dependency. Maybe there's something fishy with shade or your runtime environment.

If that didn't work, I would try to define the jvm argument -Dcom.kosprov.jargon2.spi.backend=com.kosprov.jargon2.nativeri.backend.NativeRiJargon2Backend. You can set it in the surfire plugin if you like.

If that didn't work, I would statically define the class in the code:

jargon2Hasher()
    .backend("com.kosprov.jargon2.nativeri.backend.NativeRiJargon2Backend")
    ...

kosprov avatar Feb 01 '21 06:02 kosprov

Sorry for my late reply but I tried the first and last solution but it didn't work. For the second I do not understand too much or I have to pass these arguments on Maven at the time of build?

RMrenex avatar Feb 04 '21 13:02 RMrenex

Open your final jar and check if it has this content inside it: https://github.com/kosprov/jargon2-backends/tree/master/jargon2-native-ri-binaries-generic/src/main/resources

kosprov avatar Feb 04 '21 18:02 kosprov

Yes, this is it https://www.noelshack.com/2021-05-4-1612464580-capture.jpg

RMrenex avatar Feb 04 '21 18:02 RMrenex

Where do you run it? Which JVM type/version?

kosprov avatar Feb 04 '21 19:02 kosprov

JVM version = 1.8.0_201 I compile my plugin with maven integrated in Intelij : Lifecycle > package. And I start my server with my .bat

RMrenex avatar Feb 04 '21 19:02 RMrenex

I get the same error from Coldfusion.

I load the first backend jars, then jargon2-api-1.1.1.jar. This is OK by itself but then when I call the hasher function jargon2.jargon2Hasher() or jargon2.jargon2Hasher().backend("com.kosprov.jargon2.nativeri.backend.NativeRiJargon2Backend") I get the same error: "Could not find appropriate jargon2Backend. Use either a service provider or define its class with -Dcom.kosprov.jargon2.spi.backend"

Then when I set this: -Dcom.kosprov.jargon2.spi.backend=com.kosprov.jargon2.nativeri.backend.NativeRiJargon2Backend in my JVM Arguments I get: "java.lang.NoClassDefFoundError Diagnose com/sun/jna/Pointer null"

What am I missing?

ebreeze avatar Mar 25 '21 14:03 ebreeze

Please, clone the jargon2-examples repository, minimal branch, and follow the instructions on the README file.

https://github.com/kosprov/jargon2-examples/tree/minimal

This is the minimal example and I've just tested with openjdk 8 and 11 on Linux.

Try with this and let me know if it doesn't work.

kosprov avatar Mar 25 '21 19:03 kosprov

Thank you for the quick response.

I did what you suggested (compiled the jargon2-examples-1.1.1.jar) and got the following info on the command line:

D:\projects\jargon2\jargon2-examples>echo -n "password" | java -jar target/jargon2-examples-1.1.1.jar somesalt -t 2 -m 16 -p 4 -l 24
Type:           Argon2i
Iterations:     2
Memory:         65536 KiB
Parallelism:    4
Hash:           2380da7e054be36fd4bf868672598a1e8283fbd072c4533c
Encoded:        $argon2i$v=19$m=65536,t=2,p=4$c29tZXNhbHQ$I4DafgVL42/Uv4aGclmKHoKD+9ByxFM8
0.985 seconds
Verification ok

So far so good, but I am not sure how exactly this could help me.

On the other hand I have made some changes in my coldfusion project pom.xml - I explicitly included this dependency:

		<dependency>
		    <groupId>net.java.dev.jna</groupId>
		    <artifactId>jna</artifactId>
		    <version>4.1.0</version>
		</dependency>

and the "Could not find appropriate jargon2Backend" error disappeared. So I am able now able to create the hasher object in ColdFusion.

However when I call this function: hasher.password(password).encodedHash(); the following exception occurs:

Typ | java.lang.UnsatisfiedLinkError Diagnose | Unable to load library 'argon2': Native library (win32-x86-64/argon2.dll) not found in resource path

So I am not sure where is ist dll supposed to be?

I have found the dll here: https://github.com/kosprov/jargon2-backends/blob/master/jargon2-native-ri-binaries-generic/src/main/resources/win32-x86-64/argon2.dll (it was not on my local maven repo) and I am wondering now - where should I put this dll to be found or am I doing something totally wrong?

ebreeze avatar Mar 26 '21 09:03 ebreeze

Since the example code works as-is in your machine, you have a baseline to compare your project with.

net.java.dev.jna:jna:4.1.0 is a transitive runtime dependency, so it's already in the classpath. There is no need to declare it as a build-time dependency. See, for example, the dependency tree for the example project.

~/Dev/Projects/jargon2-examples$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< com.kosprov.jargon2:jargon2-examples >----------------
[INFO] Building jargon2-examples 1.1.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ jargon2-examples ---
[INFO] com.kosprov.jargon2:jargon2-examples:jar:1.1.1
[INFO] +- com.kosprov.jargon2:jargon2-api:jar:1.1.1:compile
[INFO] +- com.kosprov.jargon2:jargon2-native-ri-backend:jar:1.1.1:runtime
[INFO] |  +- com.nativelibs4java:jnaerator-runtime:jar:0.12:runtime
[INFO] |  |  +- com.nativelibs4java:ochafik-util:jar:0.12:runtime
[INFO] |  |  \- net.java.dev.jna:jna:jar:4.1.0:runtime
[INFO] |  \- com.kosprov.jargon2:jargon2-native-ri-binaries-generic:jar:1.1.1:runtime
[INFO] +- commons-cli:commons-cli:jar:1.4:compile
[INFO] \- commons-codec:commons-codec:jar:1.11:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.586 s
[INFO] Finished at: 2021-03-26T12:33:36+02:00
[INFO] ------------------------------------------------------------------------

That said, I think there's something wrong with how you package or run your code. I cannot support you further because I don't see your project.

kosprov avatar Mar 26 '21 10:03 kosprov

https://github.com/kosprov/jargon2-backends/blob/master/jargon2-native-ri-binaries-generic/src/main/resources/win32-x86-64/argon2.dll

is packaged inside com.kosprov.jargon2:jargon2-native-ri-binaries-generic which is, also, a runtime dependency.

kosprov avatar Mar 26 '21 10:03 kosprov

Yes, you are right, the dll is there. I have unzipped the jar to make sure it is contained. So it must have been correctly downloaded from Maven (Does it matter for this exactly if runtime is set in pom.xml?) But still at runtime it cannot be found. My project is on ColdFusion, I don't know if you have experience with this rare language, that's why I did not post any code. What is specific in the ColdFusion code is that it is using the JavaLoader (https://github.com/markmandel/JavaLoader) to load the jars (plus any dependencies) one by one:

jarArray = [								
	ExpandPath("/jars/net/java/dev/jna/jna/4.1.0/jna-4.1.0.jar"),
	ExpandPath("/jars/com/nativelibs4java/ochafik-util/0.12/ochafik-util-0.12.jar"),
	ExpandPath("/jars/com/nativelibs4java/jnaerator-runtime/0.12/jnaerator-runtime-0.12.jar"),
	ExpandPath("/jars/com/kosprov/jargon2/jargon2-native-ri-backend/1.1.1/jargon2-native-ri-backend-1.1.1.jar"),
	ExpandPath("/jars/com/kosprov/jargon2/jargon2-native-ri-binaries-generic/1.1.1/jargon2-native-ri-binaries-generic-1.1.1.jar"),				
	ExpandPath("/jars/com/kosprov/jargon2/jargon2-api/1.1.1/jargon2-api-1.1.1.jar")
];

javaLoader = CreateObject("component", "lib.shared.javaloader.JavaLoader").init(jarArray);

So maybe I somehow have to explicitly load the dll as well, otherwise it cannot be found. Could this dll be converted to a jar to be loaded separately? Although I this should not be necessary because with the other Java Binding phxql/argon2-jvm this is not needed and the dll is loaded without any issues. So I am trying to figure out what is different in the war the dll gets loaded in the other binding - perhaps because it does not happen at 'runtime'?

If you have any ideas I'll appreciate it!

ebreeze avatar Mar 26 '21 12:03 ebreeze

I see jna-5.6.0. Try not to deviate from the working example.

kosprov avatar Mar 26 '21 12:03 kosprov

OK, I just tried both versions, but it seems like the jna version does not matter.

ebreeze avatar Mar 26 '21 12:03 ebreeze

I would seek assistance from the Coldfusion support/community, at this point.

kosprov avatar Mar 26 '21 13:03 kosprov

Do you have a new solution for my problem? :/

RMrenex avatar Apr 02 '21 18:04 RMrenex

Please, do this: https://github.com/kosprov/jargon2-api/issues/8#issuecomment-807335083

If it works, then there's something wrong in your project poms or runtime.

kosprov avatar Apr 03 '21 09:04 kosprov

It works well. I'll try to find out what's wrong then.

RMrenex avatar Apr 03 '21 19:04 RMrenex

I tried clone and package both projects jargon2-api and jargon2-native-ri-backend only I didn't succeed to package jargon2-native-ri-backend would it be possible to have the .jar?

RMrenex avatar Apr 03 '21 19:04 RMrenex

Go to the jargon2-examples repo, make sure you have branch minimal checked out (as you already did), and run:

mvn dependency:copy-dependencies

all jars will be copied to target/dependency.

kosprov avatar Apr 06 '21 15:04 kosprov

I did manage to download the dependencies. Then I recompiled my plugin without using maven or gradlle and I have the same problem :c

RMrenex avatar Apr 09 '21 16:04 RMrenex