Skip to content

Commit

Permalink
Merge pull request #80 from gmacf/refactor
Browse files Browse the repository at this point in the history
Use signature methods in entitymanager_test
  • Loading branch information
gmacf authored Oct 24, 2023
2 parents 26d2165 + 6dc02d1 commit 5f51765
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions server/entitymanager/entitymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package entitymanager

import (
"crypto"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/pem"
Expand All @@ -27,6 +24,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/h-fam/errdiff"
"github.com/openconfig/bootz/common/signature"
"github.com/openconfig/bootz/server/service"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
Expand Down Expand Up @@ -310,24 +308,19 @@ func TestSign(t *testing.T) {
}
t.Errorf("Sign() err = %v, want %v", err, test.wantErr)
}
hashed := sha256.Sum256(test.resp.GetSerializedBootstrapData())
sigDecoded, err := base64.StdEncoding.DecodeString(test.resp.GetResponseSignature())
if err != nil {
t.Fatal(err)
}

block, _ := pem.Decode([]byte(artifacts.OC.PrivateKey))
block, _ := pem.Decode([]byte(artifacts.OC.Cert))
if block == nil {
t.Fatal("unable to decode OC private key")
t.Fatal("unable to decode OC public key")
}
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
t.Fatal("unable to parse OC private key")
t.Fatal("unable to parse OC public key")
}

err = rsa.VerifyPKCS1v15(&priv.PublicKey, crypto.SHA256, hashed[:], sigDecoded)
err = signature.Verify(cert, test.resp.GetSerializedBootstrapData(), test.resp.GetResponseSignature())
if err != nil {
t.Errorf("Sign() err == %v, want %v", err, test.wantErr)
t.Errorf("Verify() err == %v, want %v", err, test.wantErr)
}
wantOVByte, err := base64.StdEncoding.DecodeString(test.wantOV)
if err != nil {
Expand Down

0 comments on commit 5f51765

Please sign in to comment.