如何使用 mbedTLS 库或 openssl 检查证书是 CA 还是用户证书

How to check the certificate is a CA or User certificate using mbedTLS library or openssl

我收到了客户发来的证书。在我的服务器应用程序中,我需要检查收到的证书是 CA 还是用户证书。我目前正在使用 mbedTLS 库来实现安全性。在 JAVA 中已经有一个 example 来检查这种情况。同样,我想知道如何使用 mbedTLS 库或 OpenSSL 命令进行检查。

查看 int mbedtls_x509_crt::ca_istrue 字段。即:

Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise.

https://tls.mbed.org/api/structmbedtls__x509__crt.html#a196b3a43dae5a1c0058f46075f832890

编辑:根据您的 example you need to check the if MBEDTLS_X509_KU_KEY_CERT_SIGN (link) of the key_usage (link) 在 mbedtls_x509_crt 结构中设置。