Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RMrenex opened this issue Jan 30, 2021 · 23 comments

Comments

@RMrenex
Copy link

RMrenex commented Jan 30, 2021

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.

@kosprov
Copy link
Owner

kosprov commented Jan 31, 2021

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>

@RMrenex
Copy link
Author

RMrenex commented Jan 31, 2021

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

@kosprov
Copy link
Owner

kosprov commented Feb 1, 2021

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")
    ...

@RMrenex
Copy link
Author

RMrenex commented Feb 4, 2021

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?

@kosprov
Copy link
Owner

kosprov commented Feb 4, 2021

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

@RMrenex
Copy link
Author

RMrenex commented Feb 4, 2021

@kosprov
Copy link
Owner

kosprov commented Feb 4, 2021

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

@RMrenex
Copy link
Author

RMrenex commented Feb 4, 2021

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

@ebreeze
Copy link

ebreeze commented Mar 25, 2021

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?

@kosprov
Copy link
Owner

kosprov commented Mar 25, 2021

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.

@ebreeze
Copy link

ebreeze commented Mar 26, 2021

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?

@kosprov
Copy link
Owner

kosprov commented Mar 26, 2021

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
Copy link
Owner

kosprov commented Mar 26, 2021

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.

@ebreeze
Copy link

ebreeze commented Mar 26, 2021

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!

@kosprov
Copy link
Owner

kosprov commented Mar 26, 2021

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

@ebreeze
Copy link

ebreeze commented Mar 26, 2021

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

@kosprov
Copy link
Owner

kosprov commented Mar 26, 2021

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

@RMrenex
Copy link
Author

RMrenex commented Apr 2, 2021

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

@kosprov
Copy link
Owner

kosprov commented Apr 3, 2021

Please, do this: #8 (comment)

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

@RMrenex
Copy link
Author

RMrenex commented Apr 3, 2021

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

@RMrenex
Copy link
Author

RMrenex commented Apr 3, 2021

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?

@kosprov
Copy link
Owner

kosprov commented Apr 6, 2021

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.

@RMrenex
Copy link
Author

RMrenex commented Apr 9, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants