I am looking for ways to use revocation list with OpenSSL library, and according to this statement (https://www.ibm.com/docs/en/ztpf/2020?topic=apis-ssl-ctx-load-verify-locations) I should use SSL_CTX_load_verify_locations(...).
You can use this function to verify certificates that are received from remote applications. Certificate revocation lists (CRLs) are also loaded if any exist.
However, when I read the man page of SSL_CTX_load_verify_locations, there is no mentioning of revocation list (https://www.openssl.org/docs/man3.2/man3/SSL_CTX_load_verify_locations.html). I am wondering how to use this function with revocation list, preferably some sample code to get started.
Below is the sample code I come up with according to the answer.
SSL_CTX* ssl_ctx = SSL_CTX_new(TLS_server_method());
SSL_CTX_use_certificate_chain_file(ssl_ctx, ...);
SSL_CTX_use_PrivateKey_file(ssl_ctx, ...);
SSL_CTX_load_verify_locations(ssl_ctx, ...);
SSL_CTX_set_verify(ssl_ctx, ...);
SSL* ssl = SSL_new(ssl_ctx);
X509_STORE* store = SSL_CTX_get_cert_store(ssl_ctx);
X509_STORE_CTX* store_ctx = X509_STORE_CTX_new();
X509_STORE_CTX_init(store_ctx, store, NULL, NULL);
X509_VERIFY_PARAM* param = X509_STORE_CTX_get0_param(store_ctx);
X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
SSL_set1_param(ssl, param);
For CAfile, just include relevant CRL(s) in the file, along with the certificate(s), each as a PEM block.
For CApath, each CRL must be in a file named (usually by a symlink) with the truncated hash of the CA name plus a suffix, as described (now) in its own manpage (formerly this was in the manpage for the verify subcommand originally as just verify(1ssl) and then openssl-verify(1ssl)) -- except that for CRL the suffix is .r0 .r1
etc not just .0 .1
; this is documented, or at least mentioned, in the man page for rehash.
Remember OpenSSL cert verification by default doesn't do any CRL checking. For checking the SSL/TLS peer's cert/chain, you need to set flag(s) in a X509_VERIFY_PARAM
object and pass it to SSL_[CTX_]set1_param
; for a cert verified elsewhere in your program, you need to set this param in the applicable X509_STORE
or X509_STORE_CTX
.