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

feat: blob sign command #1128

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

Two-Hearts
Copy link
Contributor

@Two-Hearts Two-Hearts commented Dec 27, 2024

This PR adds notation blob sign command with E2E tests.

It's an implementation of spec: https://github.com/notaryproject/notation/blob/main/specs/commandline/blob.md#notation-blob-sign

Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Copy link

codecov bot commented Dec 27, 2024

Codecov Report

Attention: Patch coverage is 90.95477% with 18 lines in your changes missing coverage. Please review.

Project coverage is 72.50%. Comparing base (fd00032) to head (bc8f710).

Files with missing lines Patch % Lines
cmd/notation/blob/sign.go 90.05% 14 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1128      +/-   ##
==========================================
+ Coverage   70.79%   72.50%   +1.70%     
==========================================
  Files          48       50       +2     
  Lines        2945     3139     +194     
==========================================
+ Hits         2085     2276     +191     
- Misses        668      670       +2     
- Partials      192      193       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
specs/commandline/blob.md Outdated Show resolved Hide resolved
specs/commandline/blob.md Outdated Show resolved Hide resolved
internal/cmd/signer.go Outdated Show resolved Hide resolved
@Two-Hearts Two-Hearts requested a review from shizhMSFT December 31, 2024 03:21
Signed-off-by: Patrick Zheng <[email protected]>
Signed-off-by: Patrick Zheng <[email protected]>
@Two-Hearts Two-Hearts reopened this Jan 6, 2025
Signed-off-by: Patrick Zheng <[email protected]>
return err
}
signaturePath := signatureFilepath(cmdOpts.signatureDirectory, cmdOpts.blobPath, cmdOpts.SignatureFormat)
fmt.Printf("Writing signature to file %s\n", signaturePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to be a debug log?

}
if !isRoot {
return notation.SignBlobOptions{}, fmt.Errorf("certificate from %q is not a root certificate. Expecting single x509 root certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)

Copy link
Contributor

Choose a reason for hiding this comment

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

empty line.

Suggested change

Comment on lines +220 to +240
rootCerts, err := corex509.ReadCertificateFile(opts.tsaRootCertificatePath)
if err != nil {
return notation.SignBlobOptions{}, err
}
if len(rootCerts) == 0 {
return notation.SignBlobOptions{}, fmt.Errorf("cannot find any certificate from %q. Expecting single x509 root certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
}
if len(rootCerts) > 1 {
return notation.SignBlobOptions{}, fmt.Errorf("found more than one certificates from %q. Expecting single x509 root certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
}
tsaRootCert := rootCerts[0]
isRoot, err := nx509.IsRootCertificate(tsaRootCert)
if err != nil {
return notation.SignBlobOptions{}, fmt.Errorf("failed to check root certificate with error: %w", err)
}
if !isRoot {
return notation.SignBlobOptions{}, fmt.Errorf("certificate from %q is not a root certificate. Expecting single x509 root certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)

}
rootCAs := x509.NewCertPool()
rootCAs.AddCert(tsaRootCert)
Copy link
Contributor

Choose a reason for hiding this comment

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

We may need to function for preparing TSA root cert and can be shared in both OCI signing and blob signing command to reduce repeated code.

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

Successfully merging this pull request may close these issues.

3 participants