Skip to content

Commit 3325650

Browse files
committed
Multi sign verifier flow.
Interfaces refactor Signed-off-by: houdini91 <[email protected]>
1 parent 9da84e7 commit 3325650

File tree

4 files changed

+271
-113
lines changed

4 files changed

+271
-113
lines changed

dsse/sign.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ using the current algorithm, and the key used (if applicable).
6767
For an example see EcdsaSigner in sign_test.go.
6868
*/
6969
type Signer interface {
70-
Sign(data []byte) ([]byte, string, error)
70+
Sign(data []byte) ([]byte, error)
71+
KeyID() (string, error)
7172
}
7273

7374
// SignVerifer provides both the signing and verification interface.
@@ -77,16 +78,26 @@ type SignVerifier interface {
7778
}
7879

7980
// EnvelopeSigner creates signed Envelopes.
80-
type EnvelopeSigner struct {
81+
type envelopeSigner struct {
8182
providers []SignVerifier
82-
ev EnvelopeVerifier
83+
ev *envelopeMultiVerifier
8384
}
8485

8586
/*
8687
NewEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer
8788
algorithms to sign the data.
89+
Creates a verifier with threshold=1, at least one of the providers must validate signitures successfully.
8890
*/
89-
func NewEnvelopeSigner(p ...SignVerifier) (*EnvelopeSigner, error) {
91+
func NewEnvelopeSigner(p ...SignVerifier) (*envelopeSigner, error) {
92+
return NewMultiEnvelopeSigner(1, p...)
93+
}
94+
95+
/*
96+
NewMultiEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer
97+
algorithms to sign the data.
98+
Creates a verifier with threshold at least threshold amount of the providers must validate signitures successfully.
99+
*/
100+
func NewMultiEnvelopeSigner(threshold int, p ...SignVerifier) (*envelopeSigner, error) {
90101
var providers []SignVerifier
91102

92103
for _, sv := range p {
@@ -104,11 +115,14 @@ func NewEnvelopeSigner(p ...SignVerifier) (*EnvelopeSigner, error) {
104115
evps = append(evps, p.(Verifier))
105116
}
106117

107-
return &EnvelopeSigner{
118+
ev, err := NewMultiEnvelopeVerifier(threshold, evps...)
119+
if err != nil {
120+
return nil, err
121+
}
122+
123+
return &envelopeSigner{
108124
providers: providers,
109-
ev: EnvelopeVerifier{
110-
providers: evps,
111-
},
125+
ev: ev,
112126
}, nil
113127
}
114128

@@ -118,7 +132,7 @@ Returned is an envelope as defined here:
118132
https://github.com/secure-systems-lab/dsse/blob/master/envelope.md
119133
One signature will be added for each Signer in the EnvelopeSigner.
120134
*/
121-
func (es *EnvelopeSigner) SignPayload(payloadType string, body []byte) (*Envelope, error) {
135+
func (es *envelopeSigner) SignPayload(payloadType string, body []byte) (*Envelope, error) {
122136
var e = Envelope{
123137
Payload: base64.StdEncoding.EncodeToString(body),
124138
PayloadType: payloadType,
@@ -127,10 +141,14 @@ func (es *EnvelopeSigner) SignPayload(payloadType string, body []byte) (*Envelop
127141
paeEnc := PAE(payloadType, string(body))
128142

129143
for _, signer := range es.providers {
130-
sig, keyID, err := signer.Sign(paeEnc)
144+
sig, err := signer.Sign(paeEnc)
131145
if err != nil {
132146
return nil, err
133147
}
148+
keyID, err := signer.KeyID()
149+
if err != nil {
150+
keyID = ""
151+
}
134152

135153
e.Signatures = append(e.Signatures, Signature{
136154
KeyID: keyID,
@@ -145,8 +163,9 @@ func (es *EnvelopeSigner) SignPayload(payloadType string, body []byte) (*Envelop
145163
Verify decodes the payload and verifies the signature.
146164
Any domain specific validation such as parsing the decoded body and
147165
validating the payload type is left out to the caller.
166+
Verify returns a list of accepted keys each including a keyid, public and signiture of the accepted provider keys.
148167
*/
149-
func (es *EnvelopeSigner) Verify(e *Envelope) error {
168+
func (es *envelopeSigner) Verify(e *Envelope) ([]AccesptedKey, error) {
150169
return es.ev.Verify(e)
151170
}
152171

0 commit comments

Comments
 (0)