Using openssl to check if root certificate in PKCS#7 is revoked
Here's pkcs7_verify signature taken from C/C++ library:
int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
BIO *indata, BIO *out, int flags);
It can be used with PKCS7 block (p7) and the section that it suppose to sign (in data).
I wonder how does this check detect if one of the certificate in the chain is revoked...
From what I know, revocation check can be made only if matching against another certificate outside the pkcs7 block, which is marked as revoked.
I checked the function arguments and found one that represent the list of store trusted certificates.
This arg should hold the certificate which is the issuer of the lower-most certificate in the pkcs7 chain. So my guess is that if this certificate is marked as revoked, we fail the check on revocation reason...
But what if another certificate higher in the chain is revoked ? how do I provide this piece of information to pkcs7_verify ?
Or perhaps there's another openssl method that decide if a certificate in the chain is revoked or not ?
UPDATE:
I've found an alternative way to check whether a certificate is revoked. In the example below we can see that revoked_test.pem is identified as revoked by matching against the list in crl_chain.pem. How can I do it programmatically ?
openssl verify -crl_check -CAfile crl_chain.pem revoked-test.pem
revoked-test.pem: OU = Domain Control Validated, OU = PositiveSSL, CN = xs4all.nl
error 23 at 0 depth lookup:certificate revoked
thanks
c++ c openssl x509certificate pkcs#7
add a comment |
Here's pkcs7_verify signature taken from C/C++ library:
int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
BIO *indata, BIO *out, int flags);
It can be used with PKCS7 block (p7) and the section that it suppose to sign (in data).
I wonder how does this check detect if one of the certificate in the chain is revoked...
From what I know, revocation check can be made only if matching against another certificate outside the pkcs7 block, which is marked as revoked.
I checked the function arguments and found one that represent the list of store trusted certificates.
This arg should hold the certificate which is the issuer of the lower-most certificate in the pkcs7 chain. So my guess is that if this certificate is marked as revoked, we fail the check on revocation reason...
But what if another certificate higher in the chain is revoked ? how do I provide this piece of information to pkcs7_verify ?
Or perhaps there's another openssl method that decide if a certificate in the chain is revoked or not ?
UPDATE:
I've found an alternative way to check whether a certificate is revoked. In the example below we can see that revoked_test.pem is identified as revoked by matching against the list in crl_chain.pem. How can I do it programmatically ?
openssl verify -crl_check -CAfile crl_chain.pem revoked-test.pem
revoked-test.pem: OU = Domain Control Validated, OU = PositiveSSL, CN = xs4all.nl
error 23 at 0 depth lookup:certificate revoked
thanks
c++ c openssl x509certificate pkcs#7
add a comment |
Here's pkcs7_verify signature taken from C/C++ library:
int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
BIO *indata, BIO *out, int flags);
It can be used with PKCS7 block (p7) and the section that it suppose to sign (in data).
I wonder how does this check detect if one of the certificate in the chain is revoked...
From what I know, revocation check can be made only if matching against another certificate outside the pkcs7 block, which is marked as revoked.
I checked the function arguments and found one that represent the list of store trusted certificates.
This arg should hold the certificate which is the issuer of the lower-most certificate in the pkcs7 chain. So my guess is that if this certificate is marked as revoked, we fail the check on revocation reason...
But what if another certificate higher in the chain is revoked ? how do I provide this piece of information to pkcs7_verify ?
Or perhaps there's another openssl method that decide if a certificate in the chain is revoked or not ?
UPDATE:
I've found an alternative way to check whether a certificate is revoked. In the example below we can see that revoked_test.pem is identified as revoked by matching against the list in crl_chain.pem. How can I do it programmatically ?
openssl verify -crl_check -CAfile crl_chain.pem revoked-test.pem
revoked-test.pem: OU = Domain Control Validated, OU = PositiveSSL, CN = xs4all.nl
error 23 at 0 depth lookup:certificate revoked
thanks
c++ c openssl x509certificate pkcs#7
Here's pkcs7_verify signature taken from C/C++ library:
int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
BIO *indata, BIO *out, int flags);
It can be used with PKCS7 block (p7) and the section that it suppose to sign (in data).
I wonder how does this check detect if one of the certificate in the chain is revoked...
From what I know, revocation check can be made only if matching against another certificate outside the pkcs7 block, which is marked as revoked.
I checked the function arguments and found one that represent the list of store trusted certificates.
This arg should hold the certificate which is the issuer of the lower-most certificate in the pkcs7 chain. So my guess is that if this certificate is marked as revoked, we fail the check on revocation reason...
But what if another certificate higher in the chain is revoked ? how do I provide this piece of information to pkcs7_verify ?
Or perhaps there's another openssl method that decide if a certificate in the chain is revoked or not ?
UPDATE:
I've found an alternative way to check whether a certificate is revoked. In the example below we can see that revoked_test.pem is identified as revoked by matching against the list in crl_chain.pem. How can I do it programmatically ?
openssl verify -crl_check -CAfile crl_chain.pem revoked-test.pem
revoked-test.pem: OU = Domain Control Validated, OU = PositiveSSL, CN = xs4all.nl
error 23 at 0 depth lookup:certificate revoked
thanks
c++ c openssl x509certificate pkcs#7
c++ c openssl x509certificate pkcs#7
edited Nov 22 '18 at 18:24
Zohar81
asked Nov 21 '18 at 9:07
Zohar81Zohar81
2,1221832
2,1221832
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Most of the rules of the certification path validation is set in the X509_STORE structure you are passing to the PKCS7_verify function.
This example show how to build a complete X509_STORE and explain how to activate the CRL validation in the X509_STORE. (the example is good for setting up the crl validation but not for the certificate chain handling)
The core functions are:
X509_STORE_set_flags
X509_STORE_add_crlX509_STORE_add_lookup
You use the X509_STORE_set_flags to tell the certificate store to perform CRL validation. The flags you need are: X509_V_FLAG_CRL_CHECK_ALL | X509_V_FLAG_CRL_CHECK. You can find all flags here.
You use theX509_STORE_add_crl to add CRLs for the validation. The CRL doesn't need to be from a root CA.
As an option to theX509_STORE_add_crl, you have the X509_STORE_add_lookup, to add a function to lookup for CRLs in any place (e.g.: file system, database, urls, etc.).
When performing the chain validation, OpenSSl will use the CRLs and lookup functions in the X509_STORE to validate all certificates in the chain. If any certificate in the chain is revoked, an error is returned.
It's important to add that the X.509 certification path validation specification doesn't include the validation of trust anchors (usually root certificates). All certificates in the chain under the trust anchor have to be verified, but the trust anchor is trusted because the verifier set it as so (i.e.: the trust anchor validation is made out-of-bounds by the verifier).
Hi and thanks a lot for you response. I've read carefully throw the article you provided, but I still cannot figure out how should we detect if one of the certificates in the chain is revoked (not the root one). The store contains only list of root certificates, so it must be that the pkcs7_verify get this information otherwise ... perhaps you can elaborate some theoretically explanation as well ? thanks again !
– Zohar81
Nov 25 '18 at 7:08
The X509_STORE also contains the CRLs to be used in the validation and the lookup functions to look up for CRLs. I updated the answer to point that.
– Lucas Martins
Nov 25 '18 at 11:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408547%2fusing-openssl-to-check-if-root-certificate-in-pkcs7-is-revoked%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Most of the rules of the certification path validation is set in the X509_STORE structure you are passing to the PKCS7_verify function.
This example show how to build a complete X509_STORE and explain how to activate the CRL validation in the X509_STORE. (the example is good for setting up the crl validation but not for the certificate chain handling)
The core functions are:
X509_STORE_set_flags
X509_STORE_add_crlX509_STORE_add_lookup
You use the X509_STORE_set_flags to tell the certificate store to perform CRL validation. The flags you need are: X509_V_FLAG_CRL_CHECK_ALL | X509_V_FLAG_CRL_CHECK. You can find all flags here.
You use theX509_STORE_add_crl to add CRLs for the validation. The CRL doesn't need to be from a root CA.
As an option to theX509_STORE_add_crl, you have the X509_STORE_add_lookup, to add a function to lookup for CRLs in any place (e.g.: file system, database, urls, etc.).
When performing the chain validation, OpenSSl will use the CRLs and lookup functions in the X509_STORE to validate all certificates in the chain. If any certificate in the chain is revoked, an error is returned.
It's important to add that the X.509 certification path validation specification doesn't include the validation of trust anchors (usually root certificates). All certificates in the chain under the trust anchor have to be verified, but the trust anchor is trusted because the verifier set it as so (i.e.: the trust anchor validation is made out-of-bounds by the verifier).
Hi and thanks a lot for you response. I've read carefully throw the article you provided, but I still cannot figure out how should we detect if one of the certificates in the chain is revoked (not the root one). The store contains only list of root certificates, so it must be that the pkcs7_verify get this information otherwise ... perhaps you can elaborate some theoretically explanation as well ? thanks again !
– Zohar81
Nov 25 '18 at 7:08
The X509_STORE also contains the CRLs to be used in the validation and the lookup functions to look up for CRLs. I updated the answer to point that.
– Lucas Martins
Nov 25 '18 at 11:29
add a comment |
Most of the rules of the certification path validation is set in the X509_STORE structure you are passing to the PKCS7_verify function.
This example show how to build a complete X509_STORE and explain how to activate the CRL validation in the X509_STORE. (the example is good for setting up the crl validation but not for the certificate chain handling)
The core functions are:
X509_STORE_set_flags
X509_STORE_add_crlX509_STORE_add_lookup
You use the X509_STORE_set_flags to tell the certificate store to perform CRL validation. The flags you need are: X509_V_FLAG_CRL_CHECK_ALL | X509_V_FLAG_CRL_CHECK. You can find all flags here.
You use theX509_STORE_add_crl to add CRLs for the validation. The CRL doesn't need to be from a root CA.
As an option to theX509_STORE_add_crl, you have the X509_STORE_add_lookup, to add a function to lookup for CRLs in any place (e.g.: file system, database, urls, etc.).
When performing the chain validation, OpenSSl will use the CRLs and lookup functions in the X509_STORE to validate all certificates in the chain. If any certificate in the chain is revoked, an error is returned.
It's important to add that the X.509 certification path validation specification doesn't include the validation of trust anchors (usually root certificates). All certificates in the chain under the trust anchor have to be verified, but the trust anchor is trusted because the verifier set it as so (i.e.: the trust anchor validation is made out-of-bounds by the verifier).
Hi and thanks a lot for you response. I've read carefully throw the article you provided, but I still cannot figure out how should we detect if one of the certificates in the chain is revoked (not the root one). The store contains only list of root certificates, so it must be that the pkcs7_verify get this information otherwise ... perhaps you can elaborate some theoretically explanation as well ? thanks again !
– Zohar81
Nov 25 '18 at 7:08
The X509_STORE also contains the CRLs to be used in the validation and the lookup functions to look up for CRLs. I updated the answer to point that.
– Lucas Martins
Nov 25 '18 at 11:29
add a comment |
Most of the rules of the certification path validation is set in the X509_STORE structure you are passing to the PKCS7_verify function.
This example show how to build a complete X509_STORE and explain how to activate the CRL validation in the X509_STORE. (the example is good for setting up the crl validation but not for the certificate chain handling)
The core functions are:
X509_STORE_set_flags
X509_STORE_add_crlX509_STORE_add_lookup
You use the X509_STORE_set_flags to tell the certificate store to perform CRL validation. The flags you need are: X509_V_FLAG_CRL_CHECK_ALL | X509_V_FLAG_CRL_CHECK. You can find all flags here.
You use theX509_STORE_add_crl to add CRLs for the validation. The CRL doesn't need to be from a root CA.
As an option to theX509_STORE_add_crl, you have the X509_STORE_add_lookup, to add a function to lookup for CRLs in any place (e.g.: file system, database, urls, etc.).
When performing the chain validation, OpenSSl will use the CRLs and lookup functions in the X509_STORE to validate all certificates in the chain. If any certificate in the chain is revoked, an error is returned.
It's important to add that the X.509 certification path validation specification doesn't include the validation of trust anchors (usually root certificates). All certificates in the chain under the trust anchor have to be verified, but the trust anchor is trusted because the verifier set it as so (i.e.: the trust anchor validation is made out-of-bounds by the verifier).
Most of the rules of the certification path validation is set in the X509_STORE structure you are passing to the PKCS7_verify function.
This example show how to build a complete X509_STORE and explain how to activate the CRL validation in the X509_STORE. (the example is good for setting up the crl validation but not for the certificate chain handling)
The core functions are:
X509_STORE_set_flags
X509_STORE_add_crlX509_STORE_add_lookup
You use the X509_STORE_set_flags to tell the certificate store to perform CRL validation. The flags you need are: X509_V_FLAG_CRL_CHECK_ALL | X509_V_FLAG_CRL_CHECK. You can find all flags here.
You use theX509_STORE_add_crl to add CRLs for the validation. The CRL doesn't need to be from a root CA.
As an option to theX509_STORE_add_crl, you have the X509_STORE_add_lookup, to add a function to lookup for CRLs in any place (e.g.: file system, database, urls, etc.).
When performing the chain validation, OpenSSl will use the CRLs and lookup functions in the X509_STORE to validate all certificates in the chain. If any certificate in the chain is revoked, an error is returned.
It's important to add that the X.509 certification path validation specification doesn't include the validation of trust anchors (usually root certificates). All certificates in the chain under the trust anchor have to be verified, but the trust anchor is trusted because the verifier set it as so (i.e.: the trust anchor validation is made out-of-bounds by the verifier).
edited Nov 25 '18 at 11:09
answered Nov 23 '18 at 22:39
Lucas MartinsLucas Martins
586
586
Hi and thanks a lot for you response. I've read carefully throw the article you provided, but I still cannot figure out how should we detect if one of the certificates in the chain is revoked (not the root one). The store contains only list of root certificates, so it must be that the pkcs7_verify get this information otherwise ... perhaps you can elaborate some theoretically explanation as well ? thanks again !
– Zohar81
Nov 25 '18 at 7:08
The X509_STORE also contains the CRLs to be used in the validation and the lookup functions to look up for CRLs. I updated the answer to point that.
– Lucas Martins
Nov 25 '18 at 11:29
add a comment |
Hi and thanks a lot for you response. I've read carefully throw the article you provided, but I still cannot figure out how should we detect if one of the certificates in the chain is revoked (not the root one). The store contains only list of root certificates, so it must be that the pkcs7_verify get this information otherwise ... perhaps you can elaborate some theoretically explanation as well ? thanks again !
– Zohar81
Nov 25 '18 at 7:08
The X509_STORE also contains the CRLs to be used in the validation and the lookup functions to look up for CRLs. I updated the answer to point that.
– Lucas Martins
Nov 25 '18 at 11:29
Hi and thanks a lot for you response. I've read carefully throw the article you provided, but I still cannot figure out how should we detect if one of the certificates in the chain is revoked (not the root one). The store contains only list of root certificates, so it must be that the pkcs7_verify get this information otherwise ... perhaps you can elaborate some theoretically explanation as well ? thanks again !
– Zohar81
Nov 25 '18 at 7:08
Hi and thanks a lot for you response. I've read carefully throw the article you provided, but I still cannot figure out how should we detect if one of the certificates in the chain is revoked (not the root one). The store contains only list of root certificates, so it must be that the pkcs7_verify get this information otherwise ... perhaps you can elaborate some theoretically explanation as well ? thanks again !
– Zohar81
Nov 25 '18 at 7:08
The X509_STORE also contains the CRLs to be used in the validation and the lookup functions to look up for CRLs. I updated the answer to point that.
– Lucas Martins
Nov 25 '18 at 11:29
The X509_STORE also contains the CRLs to be used in the validation and the lookup functions to look up for CRLs. I updated the answer to point that.
– Lucas Martins
Nov 25 '18 at 11:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408547%2fusing-openssl-to-check-if-root-certificate-in-pkcs7-is-revoked%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown