Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Panic on KMSController.createKeySet with BLS12381G2 in the Android local agent #2758

Open
youngjoon-lee opened this issue Apr 26, 2021 · 0 comments

Comments

@youngjoon-lee
Copy link

youngjoon-lee commented Apr 26, 2021

What I'm trying to do

I was trying to generate a keySet for BLS12381G2 using KMSController in the Android local agent.
I'm using aries-framework-go v0.1.6.

Expected result

KMSController.createKeySet(..) returns a ResponseEnvelope which contains a successful result.

Actual result

Panic:

E/Go: panic: runtime error: index out of range [4] with length 4
    goroutine 17 [running, locked to thread]:
E/Go: github.com/kilic/bls12-381.(*Fr).setBig(0x87cc8200, 0x87d2daf8, 0x0, 0x87cc8220)
    	/var/folders/cz/qsd6bhyn2p9b7w3y_dm40j3w0000gn/T/gomobile-work-947807253/pkg/mod/github.com/kilic/[email protected]/fr.go:92 +0x2fa
E/Go: github.com/kilic/bls12-381.(*Fr).setBytes(0x87cc8200, 0x87cc8220, 0x20, 0x20)
    	/var/folders/cz/qsd6bhyn2p9b7w3y_dm40j3w0000gn/T/gomobile-work-947807253/pkg/mod/github.com/kilic/[email protected]/fr.go:69 +0x9c
E/Go: github.com/kilic/bls12-381.(*Fr).RedFromBytes(0x87cc8200, 0x87cc8220, 0x20, 0x20, 0x20)
    	/var/folders/cz/qsd6bhyn2p9b7w3y_dm40j3w0000gn/T/gomobile-work-947807253/pkg/mod/github.com/kilic/[email protected]/fr.go:62 +0x3a
E/Go: github.com/hyperledger/aries-framework-go/pkg/crypto/primitive/bbs12381g2pub.frFromOKM(0x87cc2030, 0x30, 0x30, 0xb8b0bd5c)
    	/Users/magnus/repos/aries-go/pkg/crypto/primitive/bbs12381g2pub/fr.go:38 +0x178
E/Go: github.com/hyperledger/aries-framework-go/pkg/crypto/primitive/bbs12381g2pub.GenerateKeyPair(0xb8b0bd5c, 0x87cc81a0, 0x20, 0x20, 0x0, 0x0, 0x0, 0xb81451a6)
E/Go: 	/Users/magnus/repos/aries-go/pkg/crypto/primitive/bbs12381g2pub/keys.go:176 +0x7b
E/Go: github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/bbs.(*bbsSignerKeyManager).NewKey(0xb8eed954, 0x87cb6188, 0x8, 0x8, 0x0, 0x87d2dc68, 0xb851be2f, 0x0)
E/Go: 	/Users/magnus/repos/aries-go/pkg/crypto/tinkcrypto/primitive/bbs/bbs_signer_key_manager.go:101 +0x2c5
E/Go: github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/bbs.(*bbsSignerKeyManager).NewKeyData(0xb8eed954, 0x87cb6188, 0x8, 0x8, 0x0, 0x0, 0xb851bf55)
E/Go: 	/Users/magnus/repos/aries-go/pkg/crypto/tinkcrypto/primitive/bbs/bbs_signer_key_manager.go:133 +0x3e
E/Go: github.com/google/tink/go/core/registry.NewKeyData(0x87cb8600, 0x20, 0xc7bae2e0, 0x0)
    	/var/folders/cz/qsd6bhyn2p9b7w3y_dm40j3w0000gn/T/gomobile-work-947807253/pkg/mod/github.com/google/tink/[email protected]/core/registry/registry.go:79 +0x80
E/Go: github.com/google/tink/go/keyset.(*Manager).Rotate(0x87d2dd38, 0x87cb8600, 0x2, 0x3)
    	/var/folders/cz/qsd6bhyn2p9b7w3y_dm40j3w0000gn/T/gomobile-work-947807253/pkg/mod/github.com/google/tink/[email protected]/keyset/manager.go:51 +0x2e
E/Go: github.com/google/tink/go/keyset.NewHandle(0x87cb8600, 0xa, 0x87cb8600, 0x0)
    	/var/folders/cz/qsd6bhyn2p9b7w3y_dm40j3w0000gn/T/gomobile-work-947807253/pkg/mod/github.com/google/tink/[email protected]/keyset/handle.go:41 +0x51
E/Go: github.com/hyperledger/aries-framework-go/pkg/kms/localkms.(*LocalKMS).Create(0x87cbe240, 0x87cb6140, 0xa, 0xb83acd65, 0x87cf4014, 0xb8a21860, 0x87cbc660, 0x0, 0x0)
    	/Users/magnus/repos/aries-go/pkg/kms/localkms/localkms.go:115 +0xdc
E/Go: github.com/hyperledger/aries-framework-go/pkg/kms/localkms.(*LocalKMS).CreateAndExportPubKeyBytes(0x87cbe240, 0x87cb6140, 0xa, 0x0, 0x0, 0x0, 0x18, 0x87cf0018, 0xb813cfb0, 0xb894a09c)
    	/Users/magnus/repos/aries-go/pkg/kms/localkms/localkms.go:360 +0x36
E/Go: github.com/hyperledger/aries-framework-go/pkg/controller/command/kms.(*Command).CreateKeySet(0x87cba790, 0xb8b17610, 0x87cc69d8, 0xb8b17624, 0x87cc69f0, 0x87cb0301, 0xb86b84c5)
    	/Users/magnus/repos/aries-go/pkg/controller/command/kms/command.go:96 +0x35b
E/Go: github.com/hyperledger/aries-framework-go/cmd/aries-agent-mobile/pkg/wrappers/command.exec(0x87cbc3f8, 0xb8a82c40, 0x87cbc620, 0xc, 0x87cb2668, 0x0, 0x0)
E/Go: 	/Users/magnus/repos/aries-go/cmd/aries-agent-mobile/pkg/wrappers/command/command.go:27 +0x1be
    github.com/hyperledger/aries-framework-go/cmd/aries-agent-mobile/pkg/wrappers/command.(*KMS).CreateKeySet(0x87cbc560, 0x87cba7b0, 0x87cba7b0)
E/Go: 	/Users/magnus/repos/aries-go/cmd/aries-agent-mobile/pkg/wrappers/command/kms.go:32 +0x1e4
E/Go: main.proxyapi_KMSController_CreateKeySet(0xffffffe6, 0xffffffe5, 0xb87b5a35)
    	/private/var/folders/cz/qsd6bhyn2p9b7w3y_dm40j3w0000gn/T/gomobile-work-947807253/src/gobind/go_apimain.go:1729 +0x7f

I guess it's because of the architecture difference. But, I have seen that kilic/bls12-381 support non-ARM architectures: kilic/bls12-381#2.
Could you check if this scenarios is not intended to be done in mobile environments? Then, it seems that any selective disclosure features don't work in mobile environments.

Sample code / test case

package org.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import org.hyperledger.aries.api.AriesController;
import org.hyperledger.aries.api.KMSController;
import org.hyperledger.aries.ariesagent.Ariesagent;
import org.hyperledger.aries.config.Options;
import org.hyperledger.aries.models.RequestEnvelope;
import org.hyperledger.aries.models.ResponseEnvelope;

import java.nio.charset.StandardCharsets;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Options opts = new Options();
        opts.setUseLocalAgent(true);
        opts.setLogLevel("debug");

        try {
            AriesController ariesController = Ariesagent.new_(opts);

            KMSController kmsController = ariesController.getKMSController();

            RequestEnvelope requestEnvelope = new RequestEnvelope("".getBytes(StandardCharsets.UTF_8));
            // I hardcoded the request inside the createKeySet(), due to another issue.
            ResponseEnvelope resp = kmsController.createKeySet(requestEnvelope);
            Log.i("", new String(resp.getPayload(), StandardCharsets.UTF_8));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

As mentioned as a comment in the sample code, I hardcoded the request in the createKeySet(...) due to #2754.

{"keyType":"BLS12381G2"}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant