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

Pass presented chain to Verifiers #54

Merged
merged 2 commits into from
May 20, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ type VerifyProcedure interface {
// VerificationOptions contains settings for Verifier.Verify().
// VerificationOptions should be safely copyable.
type VerificationOptions struct {
VerifyTime time.Time
Name string
VerifyTime time.Time
Name string
PresentedChain *x509.CertPool
}

func (opt *VerificationOptions) clean() {
Expand All @@ -127,7 +128,11 @@ type Verifier struct {
func (v *Verifier) convertOptions(opt *VerificationOptions) (out x509.VerifyOptions) {
out.CurrentTime = opt.VerifyTime
out.Roots = v.Roots
out.Intermediates = v.Intermediates
if opt.PresentedChain != nil && opt.PresentedChain.Size() > 0 {
out.Intermediates = v.Intermediates.Sum(opt.PresentedChain)
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear to me that this is the correct approach. What performance impact does this have? Is this better or worse than adding and removing the chain from the cert pool?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't add and remove the chain from the cert pool while being thread safe in the current setup.

Copy link
Member

Choose a reason for hiding this comment

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

Alright. What's the performance impact?

Copy link
Member Author

Choose a reason for hiding this comment

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

Remove logic would have to reindex everything "after" the certificate being removed in two maps. In the common case this would be quick (remove the last certificate), but it's still pretty gnarly. There's a bunch of edge cases in the removal code (what if multiple certs have the same subject and you're removing only one of them) and in it's usage (what if the presented chain certificate was already in the pool and we remove it?)

Copy link
Member Author

Choose a reason for hiding this comment

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

We have no idea what the performance impact of this change is, in the same way we have no idea what the performance of this code before the change is. If we're too slow, we can profile. This feels like optimizing too early.

} else {
out.Intermediates = v.Intermediates
}
out.DNSName = opt.Name
out.KeyUsages = []x509.ExtKeyUsage{x509.ExtKeyUsageAny}
return
Expand Down