问题原文
原帖链接 · Shelvacu · CC BY-SA 3.0
My first thought was to use something like openssl s_client but this only supports TCP not UDP and it seems there requires some special magic to get TLS over UDP working, how do I interface with that and get a dump of the certficate chain presented? (I specifically need the certificates, not information about them)
社区高分解答
原帖链接 · tomaxuser · CC BY-SA 4.0
Building on the mostly complete solution in this thread by Peter Šurda (see there for some explanation regarding the used openvpn options), this should do the work to get the server certificates.
I assume you have a working OVPN configuration file in config.ovpn and that you are authenticating the client with a username and a password (this can be omitted, depending on your setup).
Prepare working directory:
WD=/tmp/openvpn-cert
mkdir $WD
Prepare the script to extract the server certificates and some fake credentials file (we don't need to get past successful authentication):
echo -e '#!'"/bin/sh\ncp \$peer_cert $WD/server-cert-\$1.pem" >$WD/extract-cert.sh
chmod +x $WD/extract-cert.sh
echo -e "fakeusername\nfakepassword" >$WD/creds.dat
Try to connect with openvpn:
openvpn --config config.ovpn --auth-user-pass $WD/creds.dat --tls-export-cert $WD \
--script-security 2 --tls-verify $WD/extract-cert.sh --log /dev/null
Now you should have the server certificate available in $WD/server-cert-0.pem and can operate on it, e.g. get the notBefore and notAfter dates:
openssl x509 -in $WD/server-cert-0.pem -noout -dates
The other certificates in the chain will be available in $WD/server-cert-1.pem etc. The number comes from the first argument passed to extract-cert.sh, which is the certificate depth. See the --tls-verify documentation in the Script Hooks section of the man page.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
