From 0c52156406a3ab33c283adc89a59386fe87ce5a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Fri, 10 May 2024 14:44:11 +0200 Subject: [PATCH] added uncompressed trust anchor pub key processing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Eckel --- x/machine/keeper/msg_server_register_trust_anchor.go | 6 ++++++ x/machine/keeper/msg_server_test.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/x/machine/keeper/msg_server_register_trust_anchor.go b/x/machine/keeper/msg_server_register_trust_anchor.go index b71d6c2..a566fbd 100644 --- a/x/machine/keeper/msg_server_register_trust_anchor.go +++ b/x/machine/keeper/msg_server_register_trust_anchor.go @@ -35,6 +35,12 @@ func validatePublicKey(pubkey string) bool { return false } + //uncompressed key + if len(pubkeyBytes) == 64 { + return true + } + + // compressed key // Check if byte slice has correct length if len(pubkeyBytes) != 33 { return false diff --git a/x/machine/keeper/msg_server_test.go b/x/machine/keeper/msg_server_test.go index 73dd467..09a28c1 100644 --- a/x/machine/keeper/msg_server_test.go +++ b/x/machine/keeper/msg_server_test.go @@ -71,6 +71,18 @@ func TestMsgServerRegisterTrustAnchor(t *testing.T) { } } +func TestMsgServerRegisterTrustAnchorUncompressedKey(t *testing.T) { + t.Parallel() + pk := "6003d0ab9af4ec112629195a7266a244aecf1ac7691da0084be3e7ceea2ee71571b0963fffd9c80a640317509a681ac66c2ed70ecc9f317a0d2b1a9bff94ff74" + ta := moduleobject.TrustAnchor(pk) + msg := types.NewMsgRegisterTrustAnchor(pk, &ta) + msgServer, ctx := setupMsgServer(t) + res, err := msgServer.RegisterTrustAnchor(ctx, msg) + if assert.NoError(t, err) { + assert.Equal(t, &types.MsgRegisterTrustAnchorResponse{}, res) + } +} + func TestMsgServerRegisterTrustAnchorTwice(t *testing.T) { t.Parallel() _, pk := sample.KeyPair()