Skip to content

Commit

Permalink
Update PAE to expect byte sequence for payload
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Sirish <aditya@saky.in>
  • Loading branch information
adityasaky committed Oct 28, 2021
1 parent 9da84e7 commit 293854d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dsse/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Signature struct {
PAE implementes the DSSE Pre-Authentic Encoding
https://github.com/secure-systems-lab/dsse/blob/master/protocol.md#signature-definition
*/
func PAE(payloadType, payload string) []byte {
func PAE(payloadType string, payload []byte) []byte {
return []byte(fmt.Sprintf("DSSEv1 %d %s %d %s",
len(payloadType), payloadType,
len(payload), payload))
Expand Down Expand Up @@ -124,7 +124,7 @@ func (es *EnvelopeSigner) SignPayload(payloadType string, body []byte) (*Envelop
PayloadType: payloadType,
}

paeEnc := PAE(payloadType, string(body))
paeEnc := PAE(payloadType, body)

for _, signer := range es.providers {
sig, keyID, err := signer.Sign(paeEnc)
Expand Down
12 changes: 9 additions & 3 deletions dsse/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ func TestPAE(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
var want = []byte("DSSEv1 0 0 ")

got := PAE("", "")
got := PAE("", []byte{})
assert.Equal(t, want, got, "Wrong encoding")
})
t.Run("Hello world", func(t *testing.T) {
var want = []byte("DSSEv1 29 http://example.com/HelloWorld 11 hello world")

got := PAE("http://example.com/HelloWorld", "hello world")
got := PAE("http://example.com/HelloWorld", []byte("hello world"))
assert.Equal(t, want, got, "Wrong encoding")
})
t.Run("Unicode-only", func(t *testing.T) {
var want = []byte("DSSEv1 29 http://example.com/HelloWorld 3 ಠ")

got := PAE("http://example.com/HelloWorld", []byte("ಠ"))
assert.Equal(t, want, got, "Wrong encoding")
})
}
Expand Down Expand Up @@ -144,7 +150,7 @@ func TestNoSigners(t *testing.T) {
func TestNilSign(t *testing.T) {
var keyID = "nil"
var payloadType = "http://example.com/HelloWorld"
var payload = "hello world"
var payload = []byte("hello world")

pae := PAE(payloadType, payload)
want := Envelope{
Expand Down
2 changes: 1 addition & 1 deletion dsse/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (ev *EnvelopeVerifier) Verify(e *Envelope) error {
return err
}
// Generate PAE(payloadtype, serialized body)
paeEnc := PAE(e.PayloadType, string(body))
paeEnc := PAE(e.PayloadType, body)

// If *any* signature is found to be incorrect, the entire verification
// step fails even if *some* signatures are correct.
Expand Down

0 comments on commit 293854d

Please sign in to comment.