Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Stop using public key sent from Autograph #1890

Closed
mythmon opened this issue May 23, 2019 · 2 comments
Closed

Stop using public key sent from Autograph #1890

mythmon opened this issue May 23, 2019 · 2 comments
Assignees
Labels

Comments

@mythmon
Copy link
Contributor

mythmon commented May 23, 2019

Currently, Normandy stores and validates the public_key field returned by autograph when signing objects. This is not used by Normandy Client when verifying recipe signatures. Instead the x5u is used to retrieve a certificate chain, which is a more sound verification process.

The server on the other hand is attempting to validate these signatures, which isn't good. To quote @jvehent on slack:

ok so the public key field returned by autograph here isn't good
the way to verify the signature is to use the chain from the x5u
we'll need to remove it from autograph
it should stop using the public key returned by autograph, and autograph should stop returning that value

We should remove the public key field from our database, and ignore it if Autograph sends it. We should stop validating it, and stop sending it to Normandy Client. None of this is a security problem, it is just not an optimal way of handling certificates and signatures.

@jaredlockhart jaredlockhart added this to the Backlog milestone Aug 9, 2019
@shell1
Copy link
Collaborator

shell1 commented Aug 9, 2019

we query it - so if they remove from their API we break.

@glasserc glasserc self-assigned this Oct 2, 2019
bors bot added a commit that referenced this issue Oct 4, 2019
2009: Verify with x5u instead of public_key r=jaredkerim a=glasserc

This is meant to address #1890, at least partially. I tried to re-use the existing signature verification logic but I had to jump through a bunch of hoops to get the data back into the form the pubkey check uses. (See commit comments for details.) The test is equally ugly -- this doesn't actually ensure that data is in the right format or anything, it's basically just a restatement of the implementation as a test. @mythmon, how did you get the data for the existing pubkey test? Maybe I can do something similar to generate a real x5u.

With this change, I was able to `update_recipe_signatures`, `update_product_details`, and `update_actions` without crashes.

Co-authored-by: Ethan Glasser-Camp <[email protected]>
@glasserc
Copy link
Contributor

glasserc commented Oct 8, 2019

I'm not sure what to do with this issue. We currently now verify signatures using x5u. However, this signature verification is kind of slapdash -- we don't actually verify the cert chain. There are other places around Mozilla where we do this kind of verification -- see mozilla-services/telescope#106 -- and hopefully we should be able to standardize on a single solution. @g-k's comment on that issue links to three libraries claiming to implement this algorithm, but two are clearly marked as "work in progress" and the third doesn't inspire confidence either (new bugs older than a year).

Besides this, there's one other outstanding concern with Autograph in dev, which is that certs are served as file:// URLs, which we don't support. See mozilla-services/autograph#350. In the meantime, I've been developing against autograph 2.7.0 using docker run -p 8765:8000 -it mozilla/autograph:2.7.0.

The stated purpose of this issue is to stop using the public-key field of the Autograph response, but it seems to me that for old recipes, that may be the only way we have available to validate them (since public_key predates x5u). Absent any compelling certificate-chain-validation library to use, I don't think there's anything more that can be done on the Normandy side of this issue, so I'm closing it.

@glasserc glasserc closed this as completed Oct 8, 2019
bors bot added a commit that referenced this issue Oct 15, 2019
2027: Encode only the public key information r=jaredkerim a=glasserc

Refs #1890. Fixes #2021.

In #2009 I hacked up generation of a public key by serializing a complete certificate. However, `fastecdsa` expects only a public key, which is just one part of the certificate. That the code in #2009 ever worked at all is accidental and almost miraculous. It seems that `fastecdsa` doesn't really do full parsing of the ASN.1 in its input -- it just kind of does a "good enough" job (probably for speed?) and plucks the last vaguely-parametric-looking things out of the file. This means that depending on the other contents of the certificate, it might actually grab the correct `x` and `y` and function correctly. But it can also grab other bit strings and fail catastrophically.

I was able to reproduce this failure by running the contract tests against stage. This patch fixes the tests. However, we've come to this point because I committed code that merely "seemed to work", so I wanted to be much more thorough in my work this time. The cert that we have is an X.509 certificate, described in [RFC 5280](https://tools.ietf.org/html/rfc5280). RFC 7468 [explains](https://tools.ietf.org/html/rfc7468#section-13) that a PEM-encoded public key corresponds to the subject public key information field from RFC 5280, so retrieving this field from the cert and serializing it is correct.

Just to confirm, we can also see that `fastecdsa` specifies in https://github.com/AntonKueltz/fastecdsa/blob/master/fastecdsa/encoding/pem.py#L109 that it accepts elliptic-curve key data in  [RFC 5480](https://tools.ietf.org/html/rfc5480) format. This RFC is the one that adds a format for encoding elliptic-curve keys to RFC 3279, which is the RFC referred to by RFC 5280 as defining the methods for encoding public key materials in X.509 certificates. So again, the public key data from the certificate should be the format that this library expects.

/cc @mozbhearsum @jvehent

Co-authored-by: Ethan Glasser-Camp <[email protected]>
bors bot added a commit that referenced this issue Oct 15, 2019
2017: Fix contract tests r=jaredkerim a=glasserc

Refs #1890. Update the contract tests to pass x5us instead of public keys.

Co-authored-by: Ethan Glasser-Camp <[email protected]>
bors bot added a commit that referenced this issue Oct 15, 2019
2017: Fix contract tests r=jaredkerim a=glasserc

Refs #1890. Update the contract tests to pass x5us instead of public keys.

Co-authored-by: Ethan Glasser-Camp <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants