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

Fix package name and add DER parsing support #3

Merged
merged 2 commits into from
Jun 2, 2022

Conversation

rgnote
Copy link
Contributor

@rgnote rgnote commented May 27, 2022

Signed-off-by: rgnote [email protected]

x509/cert.go Outdated
Comment on lines 26 to 28
if err == nil {
certs = append(certs, cert)
}
Copy link

Choose a reason for hiding this comment

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

Missing else condition where it return an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is nothing to do in the else condition. This function returns a list of certs that are parsable in the input. If no certs are found, it returns an empty list (not an error).

Copy link

Choose a reason for hiding this comment

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

I guess if a user had malformed a DER, the error message from ParseCertificate would have been useful. Similar to line 33 where we return an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Addressed it.

if err != nil {
return nil, err
if block == nil {
// data may be in DER format
Copy link

Choose a reason for hiding this comment

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

Suggested change
// data may be in DER format
// data may be in DER format, data contains a single DER encoded certificate.

Copy link

Choose a reason for hiding this comment

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

Is the intent to parse a single DER cert, should we use x509.ParseCertificates instead? Multiple PEM in a file are common, not sure about DER though, how common it it. Either ways, this code is called to load trust store which should support PEM bundles at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK, DER bundles are not common. It requires people to follow some conventions. For example, x509.ParseCertificates() works only if the certs are concatenated with no intermediate padding.

That being said, there is no reason to not use x509.ParseCertificates though. I will fix this. We are already handle the PEM bundles.

func ParseCertificatePEM(data []byte) ([]*x509.Certificate, error) {
// parseCertificates parses certificates from either PEM or DER data
// returns an empty list if no certificates are found
func parseCertificates(data []byte) ([]*x509.Certificate, error) {
Copy link

Choose a reason for hiding this comment

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

Can we add test cases for ReadCertificateFile if not present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should add tests here. Some of the existing code in notation-go and core-go is missing test cases. Will address this separately. This code is being tested through trust-store parsing though.

Copy link

Choose a reason for hiding this comment

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

Sounds good, can you track this with an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests for cert utilities in this PR

Signed-off-by: rgnote <[email protected]>
@gokarnm gokarnm merged commit b5b4119 into notaryproject:main Jun 2, 2022
@rgnote rgnote deleted the main branch June 22, 2022 00:15
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