rethinkdb / rethinkdb-java

Official RethinkDB Java client
https://rethinkdb.com/api/java/
Apache License 2.0
21 stars 10 forks source link

Could not generate secret key #61

Closed PXNX closed 3 years ago

PXNX commented 3 years ago

I'm using the unofficial 2.4 for Windows and try to connect from an Android-app using the Java-driver. All via ddns.net/DUC with forwarded ports.

On the client side I launch it using Dispatchers.IO as context for the Couritine, so that the network operation won't happen on the main thread.

import com.rethinkdb.RethinkDB;
import com.rethinkdb.net.Connection;
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import com.rethinkdb.gen.exc.ReqlError;

//... a normal Fragment or Activity

val scope = rememberCoroutineScope() //used in Jetpack Compose for more or less local scopes
val r = RethinkDB.r

scope.launch(Dispatchers.IO) {
    try{
        r.connection().hostname("my-ddns.net-link-goes-here").port(28015).connect()
    }catch (e: ReqlError){
        Log.w("myFragment", "ERR: $e")
    }
}

Trying to establish a connection results in:

com.rethinkdb.gen.exc.ReqlDriverError: java.security.spec.InvalidKeySpecException: Could not generate secret key

What exactly causes this? Any way to resolve it?

martinpaljak commented 3 years ago

Giving context about your java and environment in general will probably help?

PXNX commented 3 years ago

I'm using Kotlin 1.4.32 for this and Android-Studio 4.2 (shouldn't really make a difference). It's run on various virtual and physical devices running Android 9-11.

find the MWE here: https://github.com/PXNX/RethinkAndroidTest

full stacktrace:

com.rethinkdb.gen.exc.ReqlDriverError: java.security.spec.InvalidKeySpecException: Could not generate secret key
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2.compute(HandshakeProtocol.java:255)
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2$$ExternalSyntheticLambda0.apply(Unknown Source:2)
        at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1716)
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2.compute(HandshakeProtocol.java:213)
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse.nextState(HandshakeProtocol.java:161)
        at com.rethinkdb.net.HandshakeProtocol.doHandshake(HandshakeProtocol.java:51)
        at com.rethinkdb.net.Connection.lambda$connectAsync$0$Connection(Connection.java:131)
        at com.rethinkdb.net.Connection$$ExternalSyntheticLambda1.apply(Unknown Source:4)
        at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:612)
        at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:587)
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:484)
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1632)
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1619)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:285)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1155)
        at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1993)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1941)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
     Caused by: java.security.spec.InvalidKeySpecException: Could not generate secret key
        at javax.crypto.SecretKeyFactory.generateSecret(SecretKeyFactory.java:535)
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2.compute(HandshakeProtocol.java:253)
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2$$ExternalSyntheticLambda0.apply(Unknown Source:2) 
        at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1716) 
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2.compute(HandshakeProtocol.java:213) 
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse.nextState(HandshakeProtocol.java:161) 
        at com.rethinkdb.net.HandshakeProtocol.doHandshake(HandshakeProtocol.java:51) 
        at com.rethinkdb.net.Connection.lambda$connectAsync$0$Connection(Connection.java:131) 
        at com.rethinkdb.net.Connection$$ExternalSyntheticLambda1.apply(Unknown Source:4) 
        at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:612) 
        at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:587) 
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:484) 
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1632) 
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1619) 
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:285) 
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1155) 
        at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1993) 
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1941) 
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) 
     Caused by: java.lang.IllegalArgumentException: password empty
        at com.android.org.bouncycastle.jcajce.provider.symmetric.PBEPBKDF2$BasePBKDF2.engineGenerateSecret(PBEPBKDF2.java:237)
        at javax.crypto.SecretKeyFactory.generateSecret(SecretKeyFactory.java:524)
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2.compute(HandshakeProtocol.java:253) 
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2$$ExternalSyntheticLambda0.apply(Unknown Source:2) 
        at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1716) 
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse$PBKDF2.compute(HandshakeProtocol.java:213) 
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse.nextState(HandshakeProtocol.java:161) 
        at com.rethinkdb.net.HandshakeProtocol.doHandshake(HandshakeProtocol.java:51) 
        at com.rethinkdb.net.Connection.lambda$connectAsync$0$Connection(Connection.java:131) 
        at com.rethinkdb.net.Connection$$ExternalSyntheticLambda1.apply(Unknown Source:4) 
        at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:612) 
        at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:587) 
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:484) 
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1632) 
        at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1619) 
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:285) 
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1155) 
        at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1993) 
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1941) 
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) 
rohitsangwan01 commented 3 years ago

@PXNX Am Doing Exactly Same Steps , But Getting Same error in Android , its Working fine in Normal Java Project and in Flutter also Dart version Working Fine ,But Getting This in Android only , my tetsing Android Version is 10, Found Any Solution??

PXNX commented 3 years ago

@rohitsangwan01 Seems like you have to add a user to it.

for example: r.connection().hostname("some-url.com").port(42069).user("bob", "salat").connect()

This was not mentioned in the guide though :(

Find the full code here: https://github.com/PXNX/RethinkAndroidTest

I also recommend you to use reQL-pro to edit your database

rohitsangwan01 commented 3 years ago

@PXNX ,Thanks man, so is it working for you in Android ??,. Just Checked , Great ,its Working Fine , waisted almost 2 hours , they should atleast write a line in docs about t , Thanks again man