aries-framework-go icon indicating copy to clipboard operation
aries-framework-go copied to clipboard

Error importing a private key into the KMS in the mobile agent

Open angel-palomares opened this issue 3 years ago • 0 comments

Hello there,

I am trying to import a private key in a mobile app, set up for using a local agent, so the kms is within the telephone. This is something that is is working without problem in the rest api agent but when trying to do the same in the mobile using the following method:

 private fun import() {
        val privateKey ="{\"kty\":\"OKP\",\"kid\":\"kid\",\"crv\":\"Ed25519\",\"alg\":\"EdDSA\",\"x\":\"jXAvdkE8oHbFat1HYkdq3FXsuPdGtdl8NhKr163kikA\",\"d\":\"QlXTAvl0V7Kh7ckWXTVmdAdZZQcIdZ0yqXxwvw9QX04\"}"

        val request = RequestEnvelope(privateKey.toByteArray(StandardCharsets.UTF_8))
        val response = getKMSController().importKey(request)
        response?.error?.message?.let {
            Log.e(TAG, "import key error: $it")
            throw AgentException(it)
        }
        response.payload?.let {
            val result = String(it, StandardCharsets.UTF_8)
            Log.d(TAG, "Added key: $result")
        }
    }

I have the following error message:

I/MobileAgentLogger aries-framework/command/kms: command=[kms] action=[ImportKey] [] msg=[unable to read JWK: json: cannot unmarshal string into Go value of type jwk.jsonWebKey]
E/KMConnector: import key error: failed request decode : %!w(<nil>)

I have tried to follow the same interface and even the same example of the key that you are using on the tests but I am still having the same error, am I doing something wrong?

Would you please help me with this?

Thank you very much in advance

Kind regards

angel-palomares avatar Jan 11 '22 17:01 angel-palomares