$ uname -or FreeBSD 10.3-STABLE $ openssl version OpenSSL 1.0.2h 3 May 2016 $ `echo $SHELL` --version tcsh 6.18.01 (Astron) 2012-02-14 (x86_64-amd-FreeBSD) options wide,nls,dl,al,kan,sm,rh,color,filec $ /usr/local/bin/bash --version GNU bash, version 4.3.25(1)-release (amd64-portbld-freebsd10.0)
$ echo | openssl s_client -connect ya.ru:443 | openssl x509 -certopt ca_default -out ya.pem -outform PEM
$ openssl x509 -in ./ya.pem -noout -text | grep 'Authority Information Access' -A 2 Authority Information Access: OCSP - URI:http://yandex.ocsp-responder.com CA Issuers - URI:http://repository.certum.pl/ycasha2.cer
$ fetch http://repository.certum.pl/ycasha2.cer
$ openssl x509 -inform der -in ./ycasha2.cer -out ./ycasha2.pem
$ openssl x509 -in ./ycasha2.pem -noout -text | grep 'Authority Information Access' -A 2 Authority Information Access: OCSP - URI:http://subca.ocsp-certum.com CA Issuers - URI:http://repository.certum.pl/ctnca.cer
$ fetch http://repository.certum.pl/ctnca.cer
$ openssl x509 -inform der -in ./ctnca.cer -out ./ctnca.pem
$ openssl x509 -in ./ctnca.pem -noout -text | grep 'X509v3 extensions' -A 6 X509v3 extensions: X509v3 Basic Constraints: critical CA:TRUE X509v3 Subject Key Identifier: 08:76:CD:CB:07:FF:24:F6:C5:CD:ED:BB:90:BC:E2:84:37:46:75:F7 X509v3 Key Usage: critical Certificate Sign, CRL Sign
$ cat ya.pem ycasha2.pem ctnca.pem > chain0.pem
$ echo | openssl s_client -connect ya.ru:443 | grep Verify Verify return code: 0 (ok)
$ echo | openssl s_client -connect ya.ru:443 -CApath . | grep Verify Verify return code: 20 (unable to get local issuer certificate)
$ openssl x509 -noout -hash -in ./ctnca.pem 48bec511
$ ln -s `pwd`/ctnca.pem `pwd`/48bec511.0
$ echo | openssl s_client -connect ya.ru:443 -CApath . | grep Verify DONE Verify return code: 0 (ok)
#!/usr/local/bin/bash cmd_grep='/usr/bin/grep ' cmd_openssl='/usr/bin/openssl ' cmd_cut='/usr/bin/cut ' cmd_fetch='/usr/bin/fetch ' tmp_der='tmp.der' tmp_cert='tmp.cert' #------------------------------------------------------------------------------ usage () { #printf "function ${FUNCNAME}\n" printf "Error!\nUsage:\t\"$0 certificate.pem\"\n" exit 1 } #------------------------------------------------------------------------------ if [ "X$1" = "X" ] then usage else cp $1 $tmp_cert chain_cert="chain.pem" fi i=0 while : do issuer=`$cmd_openssl x509 -in $tmp_cert -noout -text | $cmd_grep 'CA Issuers' | $cmd_cut -d : -f 2,3` if [ "X$issuer" != "X" ] then echo $i echo $issuer tmp_pem=$1$i.pem $cmd_fetch $issuer --output=$tmp_der is_pem=`$cmd_grep -c CERTIFICATE $tmp_der` printf "IS PEM:\t[$is_pem]\n" #echo "$tmp_der -> $tmp_pem" if [ $is_pem -ne 0 ] then echo "PEM($tmp_der) -> PEM($tmp_pem)" cp -f $tmp_der $tmp_pem else echo "DER($tmp_der) -> PEM($tmp_pem)" echo "$cmd_openssl x509 -inform der -in $tmp_der -out $tmp_pem" $cmd_openssl x509 -inform der -in $tmp_der -out $tmp_pem fi cp $tmp_pem $tmp_cert let "i+=1" #sleep 2 else break fi done if [ $i -gt 0 ] then echo "cat ./$1* > $chain_cert" cat ./$1* > $chain_cert printf "Certificate chain:\n" ls -l $chain_cert #ls | grep -Ev ^ya.pem$ | xargs rm fi
$ ./issuers.sh ./ya.pem 0 http://repository.certum.pl/ycasha2.cer tmp.der 100% of 1196 B 16 MBps 00m00s IS PEM: [0] DER(tmp.der) -> PEM(./ya.pem0.pem) /usr/bin/openssl x509 -inform der -in tmp.der -out ./ya.pem0.pem 1 http://repository.certum.pl/ctnca.cer tmp.der 100% of 959 B 13 MBps 00m00s IS PEM: [0] DER(tmp.der) -> PEM(./ya.pem1.pem) /usr/bin/openssl x509 -inform der -in tmp.der -out ./ya.pem1.pem cat ././ya.pem* > chain.pem Certificate chain: -rw-r--r-- 1 root wheel 5842 Jun 30 15:46 chain.pem
$ md5 chain0.pem ; md5 chain.pem MD5 (chain0.pem) = 6d32b0798d48d14764cd26cc4f730444 MD5 (chain.pem) = 6d32b0798d48d14764cd26cc4f730444
Source: https://habr.com/ru/post/304458/
All Articles