Skip to content

Commit 626ac1d

Browse files
authored
fix: remove generate-envelope plugin support for blob signing (#546)
resolves #544 --------- Signed-off-by: Junjie Gao <[email protected]>
1 parent de3655a commit 626ac1d

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

signer/plugin.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ func (s *PluginSigner) SignBlob(ctx context.Context, descGenFunc notation.BlobDe
123123
if err != nil {
124124
return nil, nil, err
125125
}
126+
// only support blob signing with the signature generator capability because
127+
// the envelope generator capability is designed for OCI signing.
128+
// A new capability may be added in the future for blob signing.
129+
if !metadata.HasCapability(plugin.CapabilitySignatureGenerator) {
130+
return nil, nil, fmt.Errorf("the plugin %q lacks the signature generator capability required for blob signing", metadata.Name)
131+
}
132+
126133
logger.Debug("Invoking plugin's describe-key command")
127134
ks, err := s.getKeySpec(ctx, mergedConfig)
128135
if err != nil {
@@ -135,12 +142,7 @@ func (s *PluginSigner) SignBlob(ctx context.Context, descGenFunc notation.BlobDe
135142
return nil, nil, err
136143
}
137144
logger.Debugf("Using plugin %v with capabilities %v to sign blob using descriptor %+v", metadata.Name, metadata.Capabilities, desc)
138-
if metadata.HasCapability(plugin.CapabilitySignatureGenerator) {
139-
return s.generateSignature(ctx, desc, opts, ks, metadata, mergedConfig)
140-
} else if metadata.HasCapability(plugin.CapabilityEnvelopeGenerator) {
141-
return s.generateSignatureEnvelope(ctx, desc, opts)
142-
}
143-
return nil, nil, fmt.Errorf("plugin does not have signing capabilities")
145+
return s.generateSignature(ctx, desc, opts, ks, metadata, mergedConfig)
144146
}
145147

146148
func (s *PluginSigner) getKeySpec(ctx context.Context, config map[string]string) (signature.KeySpec, error) {

signer/plugin_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,21 @@ func TestPluginSigner_SignBlob_Valid(t *testing.T) {
363363
}
364364
}
365365

366+
func TestPluginSigner_SignBlob_Invalid(t *testing.T) {
367+
t.Run("blob signing with generate envelope plugin should fail", func(t *testing.T) {
368+
plugin := &mockPlugin{}
369+
plugin.wantEnvelope = true
370+
pluginSigner := PluginSigner{
371+
plugin: plugin,
372+
}
373+
_, _, err := pluginSigner.SignBlob(context.Background(), getDescriptorFunc(false), validSignOpts)
374+
expectedErrMsg := "the plugin \"testPlugin\" lacks the signature generator capability required for blob signing"
375+
if err == nil || !strings.Contains(err.Error(), expectedErrMsg) {
376+
t.Fatalf("expected error %q, got %v", expectedErrMsg, err)
377+
}
378+
})
379+
}
380+
366381
func TestPluginSigner_SignEnvelope_RunFailed(t *testing.T) {
367382
for _, envelopeType := range signature.RegisteredEnvelopeTypes() {
368383
t.Run(fmt.Sprintf("envelopeType=%v", envelopeType), func(t *testing.T) {

0 commit comments

Comments
 (0)