mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-05 13:46:38 +00:00
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:
parent
e33452476f
commit
120d3fdd9d
6
docs/static/openapi.yml
vendored
6
docs/static/openapi.yml
vendored
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user