-
Notifications
You must be signed in to change notification settings - Fork 162
/
cosign_signer.go
41 lines (33 loc) · 1020 Bytes
/
cosign_signer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package slsa
import (
"bytes"
"context"
"github.com/secure-systems-lab/go-securesystemslib/dsse"
"github.com/sigstore/cosign/v2/pkg/cosign"
"github.com/sigstore/sigstore/pkg/signature"
)
var _ dsse.Signer = (*cosignSigner)(nil)
type cosignSigner struct {
signer signature.Signer
keyid string
}
// NewCosignSigner loads a cosign private key into a dsse signer. The main difference between this signer and the one
// provided by sigstore's dsse.WrappedSigner is that this signer doesn't compute the PAE when signing
func NewCosignSigner(key, pass []byte, id string) (*cosignSigner, error) {
sv, err := cosign.LoadPrivateKey(key, pass)
if err != nil {
return nil, err
}
return &cosignSigner{
signer: sv,
keyid: id,
}, nil
}
// KeyID implements dsse.Signer.
func (s *cosignSigner) KeyID() (string, error) {
return s.keyid, nil
}
// Sign implements dsse.Signer.
func (s *cosignSigner) Sign(ctx context.Context, data []byte) ([]byte, error) {
return s.signer.SignMessage(bytes.NewReader(data))
}