Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Support certificate chains in headers #178

Merged
merged 4 commits into from Mar 29, 2018
Merged

Support certificate chains in headers #178

merged 4 commits into from Mar 29, 2018

Conversation

csstaub
Copy link
Collaborator

@csstaub csstaub commented Mar 28, 2018

Add support for parsing certificate chains from x5c headers in messages, and expose a function to verify & read them. The API here is that we expose a new function jose.Header#Certificates(opts x509.VerifyOptions) that both reads, verifies & returns the certificate chain a header if present. This forces callers to verify the certificates, which I think is a nice property.

leaf := h.certificates[0]
if opts.Intermediates == nil {
opts.Intermediates = x509.NewCertPool()
for _, intermediate := range h.certificates[1:] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there definitely >=1 intermediate? otherwise this might panic at runtime

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Excellent point I should fix that, there could definitely be zero here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, actually it's fine: there's at least one element and c[1:] will just be an empty slice:

❯❯❯ gore
gore version 0.2.6  :help for help
gore> c := []string{"test"}
[]string{
  "test",
}
gore> c[1:]
[]string{}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added some extra test cases to cover this

@csstaub csstaub merged commit 76dd097 into v2 Mar 29, 2018
@csstaub csstaub deleted the cs/x5c branch March 29, 2018 00:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants