fixed signing (tests) and signing verification of the machine ID Signature

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-09-06 15:41:39 +02:00
parent e33452476f
commit 120d3fdd9d
No known key found for this signature in database
4 changed files with 23 additions and 2 deletions

View File

@ -46556,6 +46556,8 @@ paths:
type:
type: integer
format: int64
machineIdSignature:
type: string
default:
description: An unexpected error response.
schema:
@ -75415,6 +75417,8 @@ definitions:
type:
type: integer
format: int64
machineIdSignature:
type: string
planetmintgo.machine.Metadata:
type: object
properties:
@ -75473,6 +75477,8 @@ definitions:
type:
type: integer
format: int64
machineIdSignature:
type: string
planetmintgo.machine.QueryParamsResponse:
type: object
properties:

View File

@ -61,7 +61,7 @@ func Machine(name, pubKey string, prvKey string) machinetypes.Machine {
prvKeyBytes, _ := hex.DecodeString(prvKey)
sk := &secp256k1.PrivKey{Key: prvKeyBytes}
pubKeyBytes := []byte(pubKey)
pubKeyBytes, _ := hex.DecodeString(pubKey)
sign, _ := sk.Sign(pubKeyBytes)
signatureHex := hex.EncodeToString(sign)

View File

@ -20,3 +20,18 @@ func ValidateSignature(message string, signature string, publicKey string) bool
return isValid
}
func ValidateSignature_hexstring(message string, signature string, publicKey string) bool {
// Convert the message, signature, and public key from hex to bytes
messageBytes, _ := hex.DecodeString(message)
signatureBytes, _ := hex.DecodeString(signature)
publicKeyBytes, _ := hex.DecodeString(publicKey)
// Create a secp256k1 public key object
pubKey := &secp256k1.PubKey{Key: publicKeyBytes}
// Verify the signature
isValid := pubKey.VerifySignature(messageBytes, signatureBytes)
return isValid
}

View File

@ -33,7 +33,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
return nil, errors.New("trust anchor has already been used for attestation")
}
isValidMachineId := util.ValidateSignature(msg.Machine.MachineId, msg.Machine.MachineIdSignature, msg.Machine.MachineId)
isValidMachineId := util.ValidateSignature_hexstring(msg.Machine.MachineId, msg.Machine.MachineIdSignature, msg.Machine.MachineId)
if !isValidMachineId {
return nil, errors.New("invalid machine id")
}