From d89334f9eb6dfb1c34001e19f5c932d6dec889f1 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 27 Nov 2017 10:22:57 -0500 Subject: [PATCH] verify certificate fields --- claim/claim.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/claim/claim.go b/claim/claim.go index b6d403d..37caaa5 100644 --- a/claim/claim.go +++ b/claim/claim.go @@ -34,6 +34,22 @@ func (c *ClaimHelper) ValidateAddresses(blockchainName string) error { return nil } +func (c *ClaimHelper) ValidateCertificate() error { + certificate := c.GetCertificate() + if certificate == nil { + return nil + } + keyType := certificate.GetKeyType() + _, err := c.GetCertificatePublicKey() + if err != nil { + return err + } + if keyType.String() != SECP256k1 { + return errors.New("wrong curve: " + keyType.String()) + } + return nil +} + func (c *ClaimHelper) LoadFromBytes(raw_claim []byte, blockchainName string) error { if c.String() != "" { return errors.New("already initialized") @@ -48,7 +64,15 @@ func (c *ClaimHelper) LoadFromBytes(raw_claim []byte, blockchainName string) err return err } *c = ClaimHelper{claim_pb} - c.ValidateAddresses(blockchainName) + err = c.ValidateAddresses(blockchainName) + if err != nil { + return err + } + err = c.ValidateCertificate() + if err != nil { + return err + } + return nil }