How to list certificates, trusted by OpenSSL?

前端 未结 4 720
天涯浪人
天涯浪人 2020-12-13 14:34

As I understand, any software working with X.509 certificates may have own basis to decide, whether a certificate is trusted or not.

AFAIK OpenSSL just consults a l

4条回答
  •  没有蜡笔的小新
    2020-12-13 15:12

    I recently looked into this, and found no way to get OpenSSL to list the certificates in its trusted set. The best way I found was to, as you point out, "consult that file [/etc/ssl/certs] myself (on my particular installation of OpenSSL)".

    You can be more installation-independent about finding the directory which OpenSSL consults. openssl version -d prints the path to it.

    % openssl version -d
    OPENSSLDIR: "/opt/local/etc/openssl"
    

    OpenSSL looks here for a file named cert.pem and a subdirectory certs/. Certificates it finds there are treated as trusted by openssl s_client and openssl verify (source: the article, What certificate authorities does OpenSSL recognize?).

    So, you can do something like:

    % find -H `openssl version -d | sed -E 's/OPENSSLDIR: "([^"]*)"/\1/'`/(cert.pem|certs) \ 
    -type f -exec cat {} \+  
    

    This prints out the entire contents of the files which OpenSSL expects to contain certificates. If you want less than the entire file, then replace cat with the appropriate commands.

提交回复
热议问题