Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor pluginSigner to support new signature interface #131

Merged
merged 5 commits into from
Sep 27, 2022

Conversation

chloeyin
Copy link
Contributor

@chloeyin chloeyin commented Sep 8, 2022

What

Refactor notation-go to support multiple envelope types.
Background can be checked in notaryproject/notation#278
I wthe whole PR into two PRs to help review, this is the first PR. More unit test cases will be added in the next PR.
The whole picture is here #146

Major Changes

  • Use package github.com/notaryproject/notation-core-go/signature to sign and verify.
  • Combine runner and signer into a provider for pluginSigner to sign and remove the pluginSigProvider.
  • Add builtinProvider to support local signing and externalProvider to support signing by plugin.
  • Move the payload media type and its checks to signature package as mentioned in refactor: refactor envelope and signer to support cose notation-core-go#73
  • Support new keySpec and plugin contract.
  • Get verification plugin and version from extended attributes.
  • Add SpeculateSignatureEnvelopeFormat to inspect signature (This function may change later to better inspect a signature)
  • Add sign/verify from file test cases.
    Signed-off-by: zaihaoyin [email protected]

@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2022

Codecov Report

Merging #131 (3479183) into main (84d4de1) will decrease coverage by 2.16%.
The diff coverage is 49.08%.

@@            Coverage Diff             @@
##             main     #131      +/-   ##
==========================================
- Coverage   72.79%   70.62%   -2.17%     
==========================================
  Files          36       39       +3     
  Lines        2503     2669     +166     
==========================================
+ Hits         1822     1885      +63     
- Misses        544      632      +88     
- Partials      137      152      +15     
Impacted Files Coverage Δ
plugin/algorithm.go 0.00% <0.00%> (ø)
plugin/plugin.go 0.00% <ø> (ø)
verification/verifier.go 82.98% <50.00%> (-4.11%) ⬇️
signature/verifier.go 56.41% <57.14%> (+18.47%) ⬆️
verification/verifier_helpers.go 68.19% <63.01%> (-5.45%) ⬇️
signature/provider.go 71.64% <71.64%> (ø)
signature/plugin.go 79.25% <72.72%> (+10.75%) ⬆️
signature/signer.go 38.23% <80.00%> (-13.58%) ⬇️
signature/envelope.go 100.00% <100.00%> (ø)
verification/helpers.go 92.50% <100.00%> (ø)
... and 5 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@chloeyin chloeyin force-pushed the cose-pr1 branch 2 times, most recently from d232af2 to 2b26389 Compare September 21, 2022 06:32
@chloeyin chloeyin changed the title refactor:refactor pluginSigner to support cose envelope refactor:refactor pluginSigner to support new signature interface Sep 21, 2022
@chloeyin chloeyin force-pushed the cose-pr1 branch 2 times, most recently from db95979 to bfccb79 Compare September 22, 2022 07:40
@yizha1 yizha1 added this to the RC-1 milestone Sep 22, 2022
@dtzar dtzar modified the milestones: RC-1, alpha-4 Sep 22, 2022
@chloeyin chloeyin force-pushed the cose-pr1 branch 2 times, most recently from d8a85f0 to a2f21d6 Compare September 23, 2022 02:44
@@ -146,9 +145,9 @@ func (GenerateSignatureRequest) Command() Command {

// GenerateSignatureResponse is the response of a generate-signature request.
type GenerateSignatureResponse struct {
KeyID string `json:"keyId"`
Signature []byte `json:"signature"`
SigningAlgorithm signer.SignatureAlgorithm `json:"signingAlgorithm"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use algorithm type instead of string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/notaryproject/notaryproject/blob/main/specs/plugin-extensibility.md
I think spec requires a string value as the protocol to communicate with notation plugin.
E.g.

RSASSA-PSS-SHA-256: RSASSA-PSS with SHA-256
RSASSA-PSS-SHA-384: RSASSA-PSS with SHA-384

@shizhMSFT Can we reuse algorithm defined in notation-core-go?

Comment on lines 33 to 40
const (
ECDSA_SHA_256 = "ECDSA-SHA-256"
ECDSA_SHA_384 = "ECDSA-SHA-384"
ECDSA_SHA_512 = "ECDSA-SHA-512"
RSASSA_PSS_SHA_256 = "RSASSA-PSS-SHA-256"
RSASSA_PSS_SHA_384 = "RSASSA-PSS-SHA-384"
RSASSA_PSS_SHA_512 = "RSASSA-PSS-SHA-512"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, spec describe it as a string

var InvalidKeySpec = signature.KeySpec{}

// KeySpecName returns the name of a keySpec according to the spec.
func KeySpecName(k signature.KeySpec) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines 126 to 137
case signature.AlgorithmES256:
return ECDSA_SHA_256
case signature.AlgorithmES384:
return ECDSA_SHA_384
case signature.AlgorithmES512:
return ECDSA_SHA_512
case signature.AlgorithmPS256:
return RSASSA_PSS_SHA_256
case signature.AlgorithmPS384:
return RSASSA_PSS_SHA_384
case signature.AlgorithmPS512:
return RSASSA_PSS_SHA_512
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have different algo for core-go and for notation-go? Can we use one for both packages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keySpec : One of following supported key types - RSA-2048, RSA-3072, RSA-4096, EC-256, EC-384, EC-521. I think plugin spec requires them to be a string.

@shizhMSFT shizhMSFT changed the title refactor:refactor pluginSigner to support new signature interface refactor: refactor pluginSigner to support new signature interface Sep 23, 2022
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with suggestions.

Comment on lines 37 to 38
// TODO: pass media type as a parameter.
envelopeMediaType := jws.MediaTypeEnvelope
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@priteshbandi Let's resolve this TODO in this PR. Although it will be an API change, it will be a small change in notation and will not block the alpha.4 release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, we can defer it to post-alpha.4. It is just weird to have hard-coded envelopeMediaType in the code.

Copy link
Contributor

@priteshbandi priteshbandi Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like @chloeyin has updated the pr with to pass envelopeMediaType as parameter.

Comment on lines 51 to 52
// TODO: pass media type as a parameter
envelopeMediaType := jws.MediaTypeEnvelope
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@priteshbandi same here

Copy link
Contributor

@priteshbandi priteshbandi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subsequent updates in PR are difficult to review because we cannot view diff after the comments/feedbacks were resolved as commits were force pushed the commits which overrides the history.

Comment on lines +140 to +156
func ParseSigningAlgorithm(raw string) (signature.Algorithm, error) {
switch raw {
case ECDSA_SHA_256:
return signature.AlgorithmES256, nil
case ECDSA_SHA_384:
return signature.AlgorithmES384, nil
case ECDSA_SHA_512:
return signature.AlgorithmES512, nil
case RSASSA_PSS_SHA_256:
return signature.AlgorithmPS256, nil
case RSASSA_PSS_SHA_384:
return signature.AlgorithmPS384, nil
case RSASSA_PSS_SHA_512:
return signature.AlgorithmPS512, nil
}
return 0, errors.New("unknown signing algorithm")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse mapping in SigningAlgorithmString function ?

@chloeyin
Copy link
Contributor Author

The subsequent updates in PR are difficult to review because we cannot view diff after the comments/feedbacks were resolved as commits were force pushed the commits which overrides the history.

The force push is rebasing the main branch. The latest change is here. 3479183

Copy link
Contributor

@priteshbandi priteshbandi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some nitpicks.
LGTM

@dtzar
Copy link
Contributor

dtzar commented Sep 26, 2022

@chloeyin @shizhMSFT @yizha1 - this appears ready to merge after updating latest changes from main. I'd click to update it, but then it likely wouldn't be signed and it would then fail DCO.

As this is blocking testing for Alpha 4 release, can we update/merge ASAP? @vaninrao10 @iamsamirzon
Then update notation to use new go library notaryproject/notation#347 and then perhaps
Release new out-of-band "weekly" dev build to test against for alpha.4 release.

@chloeyin chloeyin merged commit 2bcfd34 into notaryproject:main Sep 27, 2022
@chloeyin
Copy link
Contributor Author

@chloeyin @shizhMSFT @yizha1 - this appears ready to merge after updating latest changes from main. I'd click to update it, but then it likely wouldn't be signed and it would then fail DCO.

As this is blocking testing for Alpha 4 release, can we update/merge ASAP? @vaninrao10 @iamsamirzon Then update notation to use new go library notaryproject/notation#347 and then perhaps Release new out-of-band "weekly" dev build to test against for alpha.4 release.

Merged. notaryproject/notation#357 This pr will update dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants