@@ -8,109 +8,32 @@ import (
8
8
"context"
9
9
"encoding/base64"
10
10
"errors"
11
- "fmt"
12
11
)
13
12
14
- // ErrUnknownKey indicates that the implementation does not recognize the
15
- // key.
16
- var ErrUnknownKey = errors .New ("unknown key" )
17
-
18
- // ErrNoSignature indicates that an envelope did not contain any signatures.
19
- var ErrNoSignature = errors .New ("no signature found" )
20
-
21
13
// ErrNoSigners indicates that no signer was provided.
22
14
var ErrNoSigners = errors .New ("no signers provided" )
23
15
24
- /*
25
- Envelope captures an envelope as described by the Secure Systems Lab
26
- Signing Specification. See here:
27
- https://github.com/secure-systems-lab/signing-spec/blob/master/envelope.md
28
- */
29
- type Envelope struct {
30
- PayloadType string `json:"payloadType"`
31
- Payload string `json:"payload"`
32
- Signatures []Signature `json:"signatures"`
33
- }
34
-
35
- /*
36
- DecodeB64Payload returns the serialized body, decoded
37
- from the envelope's payload field. A flexible
38
- decoder is used, first trying standard base64, then
39
- URL-encoded base64.
40
- */
41
- func (e * Envelope ) DecodeB64Payload () ([]byte , error ) {
42
- return b64Decode (e .Payload )
43
- }
44
-
45
- /*
46
- Signature represents a generic in-toto signature that contains the identifier
47
- of the key which was used to create the signature.
48
- The used signature scheme has to be agreed upon by the signer and verifer
49
- out of band.
50
- The signature is a base64 encoding of the raw bytes from the signature
51
- algorithm.
52
- */
53
- type Signature struct {
54
- KeyID string `json:"keyid"`
55
- Sig string `json:"sig"`
56
- }
57
-
58
- /*
59
- PAE implementes the DSSE Pre-Authentic Encoding
60
- https://github.com/secure-systems-lab/dsse/blob/master/protocol.md#signature-definition
61
- */
62
- func PAE (payloadType string , payload []byte ) []byte {
63
- return []byte (fmt .Sprintf ("DSSEv1 %d %s %d %s" ,
64
- len (payloadType ), payloadType ,
65
- len (payload ), payload ))
66
- }
67
-
68
- /*
69
- Signer defines the interface for an abstract signing algorithm.
70
- The Signer interface is used to inject signature algorithm implementations
71
- into the EnevelopeSigner. This decoupling allows for any signing algorithm
72
- and key management system can be used.
73
- The full message is provided as the parameter. If the signature algorithm
74
- depends on hashing of the message prior to signature calculation, the
75
- implementor of this interface must perform such hashing.
76
- The function must return raw bytes representing the calculated signature
77
- using the current algorithm, and the key used (if applicable).
78
- For an example see EcdsaSigner in sign_test.go.
79
- */
80
- type Signer interface {
81
- Sign (ctx context.Context , data []byte ) ([]byte , error )
82
- KeyID () (string , error )
83
- }
84
-
85
- // SignVerifer provides both the signing and verification interface.
86
- type SignVerifier interface {
87
- Signer
88
- Verifier
89
- }
90
-
91
16
// EnvelopeSigner creates signed Envelopes.
92
17
type EnvelopeSigner struct {
93
- providers []SignVerifier
94
- ev * EnvelopeVerifier
18
+ providers []SignerVerifier
95
19
}
96
20
97
21
/*
98
- NewEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer
99
- algorithms to sign the data.
100
- Creates a verifier with threshold=1, at least one of the providers must validate signitures successfully.
22
+ NewEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer algorithms to
23
+ sign the data. Creates a verifier with threshold=1, at least one of the
24
+ providers must validate signatures successfully.
101
25
*/
102
- func NewEnvelopeSigner (p ... SignVerifier ) (* EnvelopeSigner , error ) {
26
+ func NewEnvelopeSigner (p ... SignerVerifier ) (* EnvelopeSigner , error ) {
103
27
return NewMultiEnvelopeSigner (1 , p ... )
104
28
}
105
29
106
30
/*
107
31
NewMultiEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer
108
- algorithms to sign the data.
109
- Creates a verifier with threshold.
110
- threashold indicates the amount of providers that must validate the envelope.
32
+ algorithms to sign the data. Creates a verifier with threshold. Threshold
33
+ indicates the amount of providers that must validate the envelope.
111
34
*/
112
- func NewMultiEnvelopeSigner (threshold int , p ... SignVerifier ) (* EnvelopeSigner , error ) {
113
- var providers []SignVerifier
35
+ func NewMultiEnvelopeSigner (threshold int , p ... SignerVerifier ) (* EnvelopeSigner , error ) {
36
+ var providers []SignerVerifier
114
37
115
38
for _ , sv := range p {
116
39
if sv != nil {
@@ -122,19 +45,8 @@ func NewMultiEnvelopeSigner(threshold int, p ...SignVerifier) (*EnvelopeSigner,
122
45
return nil , ErrNoSigners
123
46
}
124
47
125
- evps := []Verifier {}
126
- for _ , p := range providers {
127
- evps = append (evps , p .(Verifier ))
128
- }
129
-
130
- ev , err := NewMultiEnvelopeVerifier (threshold , evps ... )
131
- if err != nil {
132
- return nil , err
133
- }
134
-
135
48
return & EnvelopeSigner {
136
49
providers : providers ,
137
- ev : ev ,
138
50
}, nil
139
51
}
140
52
@@ -170,29 +82,3 @@ func (es *EnvelopeSigner) SignPayload(ctx context.Context, payloadType string, b
170
82
171
83
return & e , nil
172
84
}
173
-
174
- /*
175
- Verify decodes the payload and verifies the signature.
176
- Any domain specific validation such as parsing the decoded body and
177
- validating the payload type is left out to the caller.
178
- Verify returns a list of accepted keys each including a keyid, public and signiture of the accepted provider keys.
179
- */
180
- func (es * EnvelopeSigner ) Verify (ctx context.Context , e * Envelope ) ([]AcceptedKey , error ) {
181
- return es .ev .Verify (ctx , e )
182
- }
183
-
184
- /*
185
- Both standard and url encoding are allowed:
186
- https://github.com/secure-systems-lab/dsse/blob/master/envelope.md
187
- */
188
- func b64Decode (s string ) ([]byte , error ) {
189
- b , err := base64 .StdEncoding .DecodeString (s )
190
- if err != nil {
191
- b , err = base64 .URLEncoding .DecodeString (s )
192
- if err != nil {
193
- return nil , err
194
- }
195
- }
196
-
197
- return b , nil
198
- }
0 commit comments