@@ -67,7 +67,8 @@ using the current algorithm, and the key used (if applicable).
67
67
For an example see EcdsaSigner in sign_test.go.
68
68
*/
69
69
type Signer interface {
70
- Sign (data []byte ) ([]byte , string , error )
70
+ Sign (data []byte ) ([]byte , error )
71
+ KeyID () (string , error )
71
72
}
72
73
73
74
// SignVerifer provides both the signing and verification interface.
@@ -77,16 +78,26 @@ type SignVerifier interface {
77
78
}
78
79
79
80
// EnvelopeSigner creates signed Envelopes.
80
- type EnvelopeSigner struct {
81
+ type envelopeSigner struct {
81
82
providers []SignVerifier
82
- ev EnvelopeVerifier
83
+ ev * envelopeMultiVerifier
83
84
}
84
85
85
86
/*
86
87
NewEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer
87
88
algorithms to sign the data.
89
+ Creates a verifier with threshold=1, at least one of the providers must validate signitures successfully.
88
90
*/
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 ) {
90
101
var providers []SignVerifier
91
102
92
103
for _ , sv := range p {
@@ -104,11 +115,14 @@ func NewEnvelopeSigner(p ...SignVerifier) (*EnvelopeSigner, error) {
104
115
evps = append (evps , p .(Verifier ))
105
116
}
106
117
107
- return & EnvelopeSigner {
118
+ ev , err := NewMultiEnvelopeVerifier (threshold , evps ... )
119
+ if err != nil {
120
+ return nil , err
121
+ }
122
+
123
+ return & envelopeSigner {
108
124
providers : providers ,
109
- ev : EnvelopeVerifier {
110
- providers : evps ,
111
- },
125
+ ev : ev ,
112
126
}, nil
113
127
}
114
128
@@ -118,7 +132,7 @@ Returned is an envelope as defined here:
118
132
https://github.com/secure-systems-lab/dsse/blob/master/envelope.md
119
133
One signature will be added for each Signer in the EnvelopeSigner.
120
134
*/
121
- func (es * EnvelopeSigner ) SignPayload (payloadType string , body []byte ) (* Envelope , error ) {
135
+ func (es * envelopeSigner ) SignPayload (payloadType string , body []byte ) (* Envelope , error ) {
122
136
var e = Envelope {
123
137
Payload : base64 .StdEncoding .EncodeToString (body ),
124
138
PayloadType : payloadType ,
@@ -127,10 +141,14 @@ func (es *EnvelopeSigner) SignPayload(payloadType string, body []byte) (*Envelop
127
141
paeEnc := PAE (payloadType , string (body ))
128
142
129
143
for _ , signer := range es .providers {
130
- sig , keyID , err := signer .Sign (paeEnc )
144
+ sig , err := signer .Sign (paeEnc )
131
145
if err != nil {
132
146
return nil , err
133
147
}
148
+ keyID , err := signer .KeyID ()
149
+ if err != nil {
150
+ keyID = ""
151
+ }
134
152
135
153
e .Signatures = append (e .Signatures , Signature {
136
154
KeyID : keyID ,
@@ -145,8 +163,9 @@ func (es *EnvelopeSigner) SignPayload(payloadType string, body []byte) (*Envelop
145
163
Verify decodes the payload and verifies the signature.
146
164
Any domain specific validation such as parsing the decoded body and
147
165
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.
148
167
*/
149
- func (es * EnvelopeSigner ) Verify (e * Envelope ) error {
168
+ func (es * envelopeSigner ) Verify (e * Envelope ) ([] AccesptedKey , error ) {
150
169
return es .ev .Verify (e )
151
170
}
152
171
0 commit comments