2017년 12월 30일 토요일

openssl 또는 curl 로 인증서 체크 (만료기간 체크)

curl 로 인증서등 여러가지 체크를 할때 간단히 아래 명령어로 가능합니다.
$ curl --insecure -v https://www.google.com

openssl 명령어로 간단히 인증서 상태 체크 및 만료 체크를 할수 있습니다.

openssl s_client 옵션에는 많은 기능이 있습니다. -connect 단순 기능만으로 인증서 상태들을 덤프해주죠

$ openssl s_client -connect localhost:443 

아래와 같이 응용을 하여  google.com 의 인증서 체크를 해볼까요?

$ echo | openssl s_client -connect www.google.com:443 2>/dev/null | openssl x509 -noout -dates
notBefore=Nov 29 09:47:51 2017 GMT
notAfter=Feb 21 09:37:00 2018 GMT 

$ echo | openssl s_client -connect www.google.com:443 2>/dev/null | openssl x509 -noout -enddate
notAfter=Feb 21 09:37:00 2018 GMT


아래 명령어로 간단히 인증서 상태를 알수 있습니다. 
openssl x509 -in ./your.crt  -noout -text  |more
openssl x509 -in ./your.crt  -noout -dates

s_client 옵션과 응용을 한다면 아래와 같이 인증서를 덤프뜨거나 추출 확인 할수 있겠습니다.

$ openssl s_client -connect www.google.com:443   > cert 
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify error:num=20:unable to get local issuer certificate
verify return:0

위의 상태에서 quit 입력 하면 cert 파일에 저장됨 
아래명령어로 인증서를 PEM 형태로 저장

$ openssl x509 -inform PEM -in cert -text -out cert.crt 

저장된 PEM 형태 인증서는 아래와 같이 확인 가능합니다.
$ openssl x509 -in cert.crt  -noout -text

댓글 없음: