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

Add method to verify certificate chain #2

Merged
merged 1 commit into from
Jun 2, 2022

Conversation

jondonas
Copy link
Contributor

Signed-off-by: Jonathan Donas [email protected]

x509/cert.go Outdated Show resolved Hide resolved
x509/cert.go Outdated Show resolved Hide resolved
// Returns the full ordered chain: [leaf, intermediates..., root]
func buildAndValidateCertChain(certChain []*x509.Certificate) error {
if len(certChain) < 2 {
return errors.New("certificate chain must contain at least two certificates")
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for rejecting self-signed certificates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the constraints for a valid chain, specified here under "Other Constraints"

A valid certificate chain MUST contain a minimum of two certificates - a leaf and a root

Copy link
Contributor

Choose a reason for hiding this comment

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

@gokarnm @priteshbandi
It is not clear why we are not supporting self-signed certificates, which may be easier for testing purposes.

Choose a reason for hiding this comment

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

@rgnote - I too think the implementation should support self signed certificates. The most common use case will be testing. We should also document ( or link to existing document) how someone can generate a self signed certificate.

x509/cert.go Outdated Show resolved Hide resolved
x509/cert.go Outdated Show resolved Hide resolved
x509/cert.go Outdated Show resolved Hide resolved
x509/cert.go Outdated Show resolved Hide resolved
x509/cert.go Outdated Show resolved Hide resolved
x509/cert.go Outdated Show resolved Hide resolved
x509/cert.go Outdated Show resolved Hide resolved
x509/cert.go Outdated Show resolved Hide resolved
@@ -30,3 +33,35 @@ func ParseCertificatePEM(data []byte) ([]*x509.Certificate, error) {
}
return certs, nil
}

// ValidateCertChain takes an ordered certificate chain and validates issuance from leaf to root
func ValidateCertChain(certChain []*x509.Certificate) error {
Copy link

@gokarnm gokarnm Jun 1, 2022

Choose a reason for hiding this comment

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

This method only check if the cert chain is correctly formed, not that it chains to an trusted root certificate in trust store correct? Where will we have that logic. Also is this the method where we will add additional cert chain constraint check (KU, EKU, path len)?

We should create an issue to track that work and add TODO with the issue link, if that logic will be included here.

@priteshbandi , any feedback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we will have a separate method to check if chain ends in a specific root. Also I think the cert constraint checks belong in a separate method. We already have some of those validations here. I'll track the remaining work, it's not much

@@ -30,3 +33,35 @@ func ParseCertificatePEM(data []byte) ([]*x509.Certificate, error) {
}
return certs, nil
}

// ValidateCertChain takes an ordered certificate chain and validates issuance from leaf to root
func ValidateCertChain(certChain []*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.

I'd rename this to ValidateSigningCertChain if this is going to be distinct from TSA cert chain validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method works for general cert validation, tsa or signing chain. I think specific validations should be in separate methods

@gokarnm
Copy link

gokarnm commented Jun 2, 2022

@shizhMSFT @dtzar merging this PR as per the new review criteria.

@gokarnm gokarnm merged commit a7b7255 into notaryproject:main Jun 2, 2022
@iamsamirzon iamsamirzon added this to the RC-1 milestone Jul 14, 2022
@dtzar dtzar modified the milestones: RC-1, alpha-3 Jul 28, 2022
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.

5 participants