-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* decompose `StaticSigner` into individual signing stages * move rekor upload logic to `RekorSignerWrapper` * select signing flows based on input variables * add comments to the `Signer` implementations * only perform signing actions in `cosign.Signer` * flip comments on Signer implementations * staticly assert that impls are impls * split Rekor and Fulcio signers into their own packages Signed-off-by: Jake Sanders <jsand@google.com>
- Loading branch information
Jake Sanders
authored
Nov 30, 2021
1 parent
a035b27
commit 304c2b2
Showing
6 changed files
with
421 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2021 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fulcio | ||
|
||
import ( | ||
"context" | ||
"crypto" | ||
"io" | ||
|
||
"github.com/sigstore/cosign/internal/pkg/cosign" | ||
"github.com/sigstore/cosign/pkg/oci" | ||
"github.com/sigstore/cosign/pkg/oci/static" | ||
) | ||
|
||
// signerWrapper still needs to actually upload keys to Fulcio and receive | ||
// the resulting `Cert` and `Chain`, which are added to the returned `oci.Signature` | ||
type signerWrapper struct { | ||
inner cosign.Signer | ||
|
||
cert, chain []byte | ||
} | ||
|
||
var _ cosign.Signer = (*signerWrapper)(nil) | ||
|
||
// Sign implements `cosign.Signer` | ||
func (fs *signerWrapper) Sign(ctx context.Context, payload io.Reader) (oci.Signature, crypto.PublicKey, error) { | ||
sig, pub, err := fs.inner.Sign(ctx, payload) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
payloadBytes, err := sig.Payload() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
b64Sig, err := sig.Base64Signature() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
// TODO(dekkagaijin): move the fulcio SignerVerififer logic here | ||
|
||
opts := []static.Option{static.WithCertChain(fs.cert, fs.chain)} | ||
|
||
// Copy over the other attributes: | ||
if annotations, err := sig.Annotations(); err != nil { | ||
return nil, nil, err | ||
} else if len(annotations) > 0 { | ||
opts = append(opts, static.WithAnnotations(annotations)) | ||
} | ||
if bundle, err := sig.Bundle(); err != nil { | ||
return nil, nil, err | ||
} else if bundle != nil { | ||
opts = append(opts, static.WithBundle(bundle)) | ||
} | ||
if mt, err := sig.MediaType(); err != nil { | ||
return nil, nil, err | ||
} else if mt != "" { | ||
opts = append(opts, static.WithLayerMediaType(mt)) | ||
} | ||
|
||
newSig, err := static.NewSignature(payloadBytes, b64Sig, opts...) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return newSig, pub, nil | ||
} | ||
|
||
// NewSigner returns a `cosign.Signer` which leverages Fulcio to create a Cert and Chain for the signature | ||
func NewSigner(inner cosign.Signer, cert, chain []byte) cosign.Signer { | ||
return &signerWrapper{ | ||
inner: inner, | ||
cert: cert, | ||
chain: chain, | ||
} | ||
} |
Oops, something went wrong.