Refactor sign/verify message #6

Closed
dstepanov-yadro wants to merge 6 commits from dstepanov-yadro/feat/refactor-signservicemessage into master
3 changed files with 24 additions and 10 deletions
Showing only changes of commit 635fac42ed - Show all commits

1
go.mod
View file

@ -17,6 +17,7 @@ require (
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.3.3 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect

2
go.sum
View file

@ -84,6 +84,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View file

@ -7,6 +7,7 @@ import (
"github.com/TrueCloudLab/frostfs-api-go/v2/refs"
"github.com/TrueCloudLab/frostfs-api-go/v2/session"
"github.com/TrueCloudLab/frostfs-api-go/v2/util/signature"
"golang.org/x/sync/errgroup"
)
type serviceRequest interface {
@ -68,23 +69,33 @@ func signServiceResponse(key *ecdsa.PrivateKey, v serviceResponse) error {
}
func signMessageParts(key *ecdsa.PrivateKey, body, meta, header stableMarshaler, hasHeader bool, result signatureReceiver) error {
eg := &errgroup.Group{}
if !hasHeader {
// sign session message body
if err := signServiceMessagePart(key, body, result.SetBodySignature); err != nil {
return fmt.Errorf("could not sign body: %w", err)
}
eg.Go(func() error {
if err := signServiceMessagePart(key, body, result.SetBodySignature); err != nil {
return fmt.Errorf("could not sign body: %w", err)
}
return nil
})
}
// sign meta header
if err := signServiceMessagePart(key, meta, result.SetMetaSignature); err != nil {
return fmt.Errorf("could not sign meta header: %w", err)
}
eg.Go(func() error {
if err := signServiceMessagePart(key, meta, result.SetMetaSignature); err != nil {
return fmt.Errorf("could not sign meta header: %w", err)
}
return nil
})
// sign verification header origin
if err := signServiceMessagePart(key, header, result.SetOriginSignature); err != nil {
return fmt.Errorf("could not sign origin of verification header: %w", err)
}
return nil
eg.Go(func() error {
if err := signServiceMessagePart(key, header, result.SetOriginSignature); err != nil {
return fmt.Errorf("could not sign origin of verification header: %w", err)
}
return nil
})
return eg.Wait()
}
func signServiceMessagePart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrite func(*refs.Signature)) error {