Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Exception: java.lang.ArrayIndexOutOfBoundsException length=4; index=4 org.whispersystems.libsignal.state.PreKeyRecord.<init> #84

Closed
rubenquadros opened this issue Apr 17, 2021 · 6 comments

Comments

@rubenquadros
Copy link

Getting below error when generating prekeys.
I am trying to achieve end-to-end encryption in a chat window.

Non-fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=4; index=4 at com.google.protobuf.MessageSchema.newSchemaForRawMessageInfo(MessageSchema.java:507) at com.google.protobuf.MessageSchema.newSchema(MessageSchema.java:227) at com.google.protobuf.ManifestSchemaFactory.newSchema(ManifestSchemaFactory.java:77) at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:71) at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:90) at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:104) at com.google.protobuf.GeneratedMessageLite.makeImmutable(GeneratedMessageLite.java:175) at com.google.protobuf.GeneratedMessageLite$Builder.buildPartial(GeneratedMessageLite.java:395) at com.google.protobuf.GeneratedMessageLite$Builder.build(GeneratedMessageLite.java:403) at org.whispersystems.libsignal.state.PreKeyRecord.<init>(PreKeyRecord.java:31) at org.whispersystems.libsignal.util.KeyHelper.generatePreKeys(KeyHelper.java:89) at com.quickfire.messaging.cryptography.SignalProtocolManagerImpl.initProtocol(SignalProtocolManagerImpl.kt:15) at com.quickfire.presentation.login.LoginActivity.updateLoginResult(LoginActivity.kt:176) at com.quickfire.presentation.login.LoginActivity.access$updateLoginResult(LoginActivity.kt:34) at com.quickfire.presentation.login.LoginActivity$observeData$2$invokeSuspend$$inlined$collect$1.emit(Collect.kt:138) at kotlinx.coroutines.flow.StateFlowImpl.collect(StateFlow.kt:348) at kotlinx.coroutines.flow.StateFlowImpl$collect$1.invokeSuspend(:12) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234) at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:190) at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161) at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:369) at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:403) at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:395) at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:300) at kotlinx.coroutines.flow.StateFlowSlot.makePending(StateFlow.kt:236) at kotlinx.coroutines.flow.StateFlowImpl.updateState(StateFlow.kt:301) at kotlinx.coroutines.flow.StateFlowImpl.setValue(StateFlow.kt:268) at com.quickfire.presentation.login.LoginViewModel.handleLoginResult(LoginViewModel.kt:75) at com.quickfire.presentation.login.LoginViewModel.access$handleLoginResult(LoginViewModel.kt:25) at com.quickfire.presentation.login.LoginViewModel$login$1$1.invoke(LoginViewModel.kt:53) at com.quickfire.presentation.login.LoginViewModel$login$1$1.invoke(LoginViewModel.kt:25) at com.quickfire.domain.model.base.Record.handleResult(Record.kt:9) at com.quickfire.presentation.login.LoginViewModel$login$1.invoke(LoginViewModel.kt:53) at com.quickfire.presentation.login.LoginViewModel$login$1.invoke(LoginViewModel.kt:25) at com.quickfire.domain.interactor.base.BaseFlowUseCase$invoke$1$invokeSuspend$$inlined$collect$1.emit(Collect.kt:133) at kotlinx.coroutines.flow.FlowKt__ChannelsKt.emitAllImpl$FlowKt__ChannelsKt(Channels.kt:61) at kotlinx.coroutines.flow.FlowKt__ChannelsKt$emitAllImpl$1.invokeSuspend(:11) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7682) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

@sriram2093
Copy link

@rubenquadros can you provide more information. For example, a code snippet showing how to replicate the issue.

@rubenquadros
Copy link
Author

@sriram2093 I am generating identity keys, prekeys and registration id as below

class SignalProtocolManagerImpl : SignalProtocolManager {

    override fun initProtocol(userId: String) {
        val identityPairKey = KeyHelper.generateIdentityKeyPair()
        val registrationId = KeyHelper.generateRegistrationId(false)
        val preKeys = KeyHelper.generatePreKeys(0, 200)
        val signedPreKey = KeyHelper.generateSignedPreKey(identityPairKey, registrationId)

        FirebaseHelper.sendSignalBundle(
            identityPairKey,
            registrationId,
            preKeys,
            signedPreKey,
            userId
        )
    }

    override fun generatePreKeys() {
        //do nothing
    }
}

I am calling this method from my activity after the user has successfully logged in for the first time

private fun updateLoginResult(loginRecord: ServerRecord) {
        ApplicationUtility.stopProgress(binding.loginPb, this)
        when (loginRecord) {
            is Success -> {
                ApplicationUtility.showToast(this, getString(R.string.all_sign_in))
                updateProfile(FirebaseAuth.getInstance().currentUser!!.uid)
            }
            NewUser -> {
                ApplicationUtility.showToast(this, getString(R.string.all_sign_in_first_time))
                val userId = FirebaseAuth.getInstance().currentUser!!.uid
                signalManager.initProtocol(userId)
                getGoogleProfile(userId)
            }
            AuthFail -> {
                ApplicationUtility.showSnack(getString(R.string.all_auth_fail), binding.loginParent, ok)
            }
            else -> {
                ApplicationUtility.showSnack(genericError, binding.loginParent, ok)
            }
        }
    }

@atyanands
Copy link

getting same error, did you find any solution.?? @rubenquadros

@rubenquadros
Copy link
Author

@atyanands I haven't found anything. Please let me know if you have got anything.
@alan-signal @moxie0 Can you please help?
Thanks in advance.

@atyanands
Copy link

@rubenquadros yes it was because of protobuf library version conflict.
use force version in android config

configurations { all { resolutionStrategy { force group: 'com.google.protobuf', name: 'protobuf-javalite', version: '3.10.0' } } }

@rubenquadros
Copy link
Author

@atyanands I am not getting any error after forcing the protobuf version to 3.10.0.
Thanks for your help!

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

No branches or pull requests

3 participants