mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-07 14:46:39 +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:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
machineIdSignature:
|
||||||
|
type: string
|
||||||
default:
|
default:
|
||||||
description: An unexpected error response.
|
description: An unexpected error response.
|
||||||
schema:
|
schema:
|
||||||
@ -75415,6 +75417,8 @@ definitions:
|
|||||||
type:
|
type:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
machineIdSignature:
|
||||||
|
type: string
|
||||||
planetmintgo.machine.Metadata:
|
planetmintgo.machine.Metadata:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -75473,6 +75477,8 @@ definitions:
|
|||||||
type:
|
type:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
machineIdSignature:
|
||||||
|
type: string
|
||||||
planetmintgo.machine.QueryParamsResponse:
|
planetmintgo.machine.QueryParamsResponse:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -61,7 +61,7 @@ func Machine(name, pubKey string, prvKey string) machinetypes.Machine {
|
|||||||
|
|
||||||
prvKeyBytes, _ := hex.DecodeString(prvKey)
|
prvKeyBytes, _ := hex.DecodeString(prvKey)
|
||||||
sk := &secp256k1.PrivKey{Key: prvKeyBytes}
|
sk := &secp256k1.PrivKey{Key: prvKeyBytes}
|
||||||
pubKeyBytes := []byte(pubKey)
|
pubKeyBytes, _ := hex.DecodeString(pubKey)
|
||||||
sign, _ := sk.Sign(pubKeyBytes)
|
sign, _ := sk.Sign(pubKeyBytes)
|
||||||
signatureHex := hex.EncodeToString(sign)
|
signatureHex := hex.EncodeToString(sign)
|
||||||
|
|
||||||
|
@ -20,3 +20,18 @@ func ValidateSignature(message string, signature string, publicKey string) bool
|
|||||||
|
|
||||||
return isValid
|
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")
|
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 {
|
if !isValidMachineId {
|
||||||
return nil, errors.New("invalid machine id")
|
return nil, errors.New("invalid machine id")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user