Skip to content

Commit c974d7f

Browse files
committed
Reorganize DSSE library
* Reorganizes source files * Removes Verify method from EnvelopeSigner -> use EnvelopeVerifier directly * Renames SignVerifier to SignerVerifier (with an alias for compatibility) Signed-off-by: Aditya Sirish <[email protected]>
1 parent 6476f36 commit c974d7f

File tree

5 files changed

+149
-146
lines changed

5 files changed

+149
-146
lines changed

dsse/envelope.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package dsse
2+
3+
import (
4+
"encoding/base64"
5+
)
6+
7+
/*
8+
Envelope captures an envelope as described by the DSSE specification. See here:
9+
https://github.com/secure-systems-lab/dsse/blob/master/envelope.md
10+
*/
11+
type Envelope struct {
12+
PayloadType string `json:"payloadType"`
13+
Payload string `json:"payload"`
14+
Signatures []Signature `json:"signatures"`
15+
}
16+
17+
/*
18+
DecodeB64Payload returns the serialized body, decoded from the envelope's
19+
payload field. A flexible decoder is used, first trying standard base64, then
20+
URL-encoded base64.
21+
*/
22+
func (e *Envelope) DecodeB64Payload() ([]byte, error) {
23+
return b64Decode(e.Payload)
24+
}
25+
26+
/*
27+
Signature represents a generic in-toto signature that contains the identifier
28+
of the key which was used to create the signature.
29+
The used signature scheme has to be agreed upon by the signer and verifer
30+
out of band.
31+
The signature is a base64 encoding of the raw bytes from the signature
32+
algorithm.
33+
*/
34+
type Signature struct {
35+
KeyID string `json:"keyid"`
36+
Sig string `json:"sig"`
37+
}
38+
39+
/*
40+
Both standard and url encoding are allowed:
41+
https://github.com/secure-systems-lab/dsse/blob/master/envelope.md
42+
*/
43+
func b64Decode(s string) ([]byte, error) {
44+
b, err := base64.StdEncoding.DecodeString(s)
45+
if err != nil {
46+
b, err = base64.URLEncoding.DecodeString(s)
47+
if err != nil {
48+
return nil, err
49+
}
50+
}
51+
52+
return b, nil
53+
}

dsse/sign.go

Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,6 @@ var ErrNoSignature = errors.New("no signature found")
2121
// ErrNoSigners indicates that no signer was provided.
2222
var ErrNoSigners = errors.New("no signers provided")
2323

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-
5824
/*
5925
PAE implementes the DSSE Pre-Authentic Encoding
6026
https://github.com/secure-systems-lab/dsse/blob/master/protocol.md#signature-definition
@@ -82,35 +48,27 @@ type Signer interface {
8248
KeyID() (string, error)
8349
}
8450

85-
// SignVerifer provides both the signing and verification interface.
86-
type SignVerifier interface {
87-
Signer
88-
Verifier
89-
}
90-
9151
// EnvelopeSigner creates signed Envelopes.
9252
type EnvelopeSigner struct {
93-
providers []SignVerifier
94-
ev *EnvelopeVerifier
53+
providers []SignerVerifier
9554
}
9655

9756
/*
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.
57+
NewEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer algorithms to
58+
sign the data. Creates a verifier with threshold=1, at least one of the
59+
providers must validate signatures successfully.
10160
*/
102-
func NewEnvelopeSigner(p ...SignVerifier) (*EnvelopeSigner, error) {
61+
func NewEnvelopeSigner(p ...SignerVerifier) (*EnvelopeSigner, error) {
10362
return NewMultiEnvelopeSigner(1, p...)
10463
}
10564

10665
/*
10766
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.
67+
algorithms to sign the data. Creates a verifier with threshold. Threshold
68+
indicates the amount of providers that must validate the envelope.
11169
*/
112-
func NewMultiEnvelopeSigner(threshold int, p ...SignVerifier) (*EnvelopeSigner, error) {
113-
var providers []SignVerifier
70+
func NewMultiEnvelopeSigner(threshold int, p ...SignerVerifier) (*EnvelopeSigner, error) {
71+
var providers []SignerVerifier
11472

11573
for _, sv := range p {
11674
if sv != nil {
@@ -122,19 +80,8 @@ func NewMultiEnvelopeSigner(threshold int, p ...SignVerifier) (*EnvelopeSigner,
12280
return nil, ErrNoSigners
12381
}
12482

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-
13583
return &EnvelopeSigner{
13684
providers: providers,
137-
ev: ev,
13885
}, nil
13986
}
14087

@@ -170,29 +117,3 @@ func (es *EnvelopeSigner) SignPayload(ctx context.Context, payloadType string, b
170117

171118
return &e, nil
172119
}
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

Comments
 (0)