Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Jul 22, 2024
1 parent 5c177c0 commit 7c44b3e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/notation/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/notaryproject/notation/internal/cmd"
"github.com/notaryproject/notation/internal/envelope"
"github.com/notaryproject/notation/internal/httputil"
nx509 "github.com/notaryproject/notation/internal/x509"
"github.com/notaryproject/tspclient-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -230,13 +231,22 @@ func prepareSigningOpts(ctx context.Context, opts *signOpts) (notation.SignOptio
return notation.SignOptions{}, err
}
if len(rootCerts) == 0 {
return notation.SignOptions{}, fmt.Errorf("cannot find any certificate from %q. Expecting one x509 certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
return notation.SignOptions{}, fmt.Errorf("cannot find any certificate from %q. Expecting one x509 root CA certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
}
if len(rootCerts) > 1 {
return notation.SignOptions{}, fmt.Errorf("find more than one certificates from %q. Expecting one x509 certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
return notation.SignOptions{}, fmt.Errorf("find more than one certificates from %q. Expecting one x509 root CA certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
}
tsaRootCert := rootCerts[0]
isRoot, err := nx509.IsRootCertificate(tsaRootCert)
if err != nil {
return notation.SignOptions{}, fmt.Errorf("failed to check root certificate with error: %w", err)
}
if !isRoot {
return notation.SignOptions{}, fmt.Errorf("cannot find root CA certificate from %q. Expecting one x509 root CA certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)

}
rootCAs := x509.NewCertPool()
rootCAs.AddCert(rootCerts[0])
rootCAs.AddCert(tsaRootCert)
signOpts.TSARootCAs = rootCAs
}
return signOpts, nil
Expand Down

0 comments on commit 7c44b3e

Please sign in to comment.