MAISTRA-2687 Fix spiffe certificate verification#116
MAISTRA-2687 Fix spiffe certificate verification#116maistra-bot merged 4 commits intomaistra:maistra-2.1from
Conversation
Previously, when copying the X509 store context, the code erroneously copied the output certificate chain instead of the input (untrusted) chain to the new context. As the output certificate chain is set only after you run X509_verify_cert(), this chain was always empty. Thus, the code only worked properly when the leaf certificate was signed by one of the certificates in the trust bundle (e.g. when the leaf certificate was signed directly by the root certificate). In cases involving intermediate certificates, the leaf certificate was only trusted if all the intermediate certificates were in the trust bundle. Intermediate certificates sent by the client were ignored. When copying the X509 store context, the input intermediate certificates should be retrieved by calling X509_STORE_CTX_get0_untrusted(), not X509_STORE_CTX_get0_chain().
oschaaf
left a comment
There was a problem hiding this comment.
Nice catch! I wonder would it be hard to add a test in test/extensions/transport_sockets/tls/cert_validator/spiffe/spiffe_validator_test.cc?
|
/retest |
1 similar comment
|
/retest |
|
/test envoy-unit |
|
really good catch. I wonder if our copying/re-init of a fresh x509 store is actually necessary? |
twghu
left a comment
There was a problem hiding this comment.
Checking the validity of this change in relation to previous upstream commit.
|
/retest |
test/extensions/transport_sockets/tls/cert_validator/spiffe/spiffe_validator_test.cc
Show resolved
Hide resolved
|
There appears to be a problem with the spiffe_san_signed_by_intermediate_cert_chain.pem cert, the ca cert included does not match the ca cert using as an anchor in the envoy configuration in the test. If we run the openssl/demos/certs/mkcerts.sh script (openssl source) and then run |
|
/retest |
Thanks. Yeah, I built the certs by running |
test/extensions/transport_sockets/tls/cert_validator/spiffe/spiffe_validator_test.cc
Show resolved
Hide resolved
|
/test unit |
|
Looks good to me. Builds and tests pass. |
|
Dumb question: Does this affects only our fork? Or upstream too? |
|
@jwendell good call, so after comparing the upstream code, I think you are right: it looks like this affects upstream as well. |
|
@jwendell @oschaaf As far as I can tell, this issue in only in our code, because we clone |
|
It would make sense to add the BoringSSL version of this chain validation test to upstream. |
A fly-by comment: BoringSSL exposes store_ctx/context_ctx data structures and makes all their fields directly accessible. OpenSSL hides details of those and only allows access and modification for some of the fields (and only via api), hence all these hoops... Sorry about the bug! |
|
@twghu Here's the upstream PR: envoyproxy/envoy#18914 @dmitri-d Thanks for the explanation. No worries about the bug. |
Signed-off-by: Marko Lukša <marko.luksa@gmail.com>
|
/test unit |
* MAISTRA-2687 Fix spiffe certificate verification Previously, when copying the X509 store context, the code erroneously copied the output certificate chain instead of the input (untrusted) chain to the new context. As the output certificate chain is set only after you run X509_verify_cert(), this chain was always empty. Thus, the code only worked properly when the leaf certificate was signed by one of the certificates in the trust bundle (e.g. when the leaf certificate was signed directly by the root certificate). In cases involving intermediate certificates, the leaf certificate was only trusted if all the intermediate certificates were in the trust bundle. Intermediate certificates sent by the client were ignored. When copying the X509 store context, the input intermediate certificates should be retrieved by calling X509_STORE_CTX_get0_untrusted(), not X509_STORE_CTX_get0_chain(). * Add test * Fix test * Release references to certs Signed-off-by: Marko Lukša <marko.luksa@gmail.com>
* MAISTRA-2687 Fix spiffe certificate verification Previously, when copying the X509 store context, the code erroneously copied the output certificate chain instead of the input (untrusted) chain to the new context. As the output certificate chain is set only after you run X509_verify_cert(), this chain was always empty. Thus, the code only worked properly when the leaf certificate was signed by one of the certificates in the trust bundle (e.g. when the leaf certificate was signed directly by the root certificate). In cases involving intermediate certificates, the leaf certificate was only trusted if all the intermediate certificates were in the trust bundle. Intermediate certificates sent by the client were ignored. When copying the X509 store context, the input intermediate certificates should be retrieved by calling X509_STORE_CTX_get0_untrusted(), not X509_STORE_CTX_get0_chain(). * Add test * Fix test * Release references to certs Conflicts: source/extensions/transport_sockets/tls/cert_validator/spiffe/spiffe_validator.cc Signed-off-by: Marko Lukša <marko.luksa@gmail.com>
Previously, when copying the X509 store context, the code erroneously copied the output certificate chain instead of the input (untrusted) chain to the new context. As the output certificate chain is set only after you run X509_verify_cert(), this chain was always empty. Thus, the code only worked properly when the leaf certificate was signed by one of the certificates in the trust bundle (e.g. when the leaf certificate was signed directly by the root certificate). In cases involving intermediate certificates, the leaf certificate was only trusted if all the intermediate certificates were in the trust bundle. Intermediate certificates sent by the client were ignored.
When copying the X509 store context, the input intermediate certificates should be retrieved by calling X509_STORE_CTX_get0_untrusted(), not X509_STORE_CTX_get0_chain().