System Story/CentOS 5,6
Shell - 다수 Domain SSL 인증서의 인증 기간 조회
helperchoi
2014. 5. 14. 16:45

WEB 서비스를 운영하다 보면 HTTPS SSL 보안 프로토콜을 이용한 서비스를 제공하기 위해 SSL 인증서를 WEB 서버에 설치하여 운용하게 된다.
때문에 다수의 WEB 서버 SSL 인증서를 운용, 관리하다보면, 인증서 인증 만료 일자의 관리를 필요로 하게 된다.
이때 아래와 같이 Linux OS 이하에 설치된 openssl client와 Shell Script를 통해 다수의 인증서의 만료일자 효율적으로 조회 및 확인이 가능하다.
1. 조회할 Domain 및 서비스 Port를 기재한 List 파일 작성
[root@t-node01 shell]# [root@t-node01 shell]# vi ssl.list olleh.com 443 yahoo.com 443 google.com 443 tistory.com 443 [root@t-node01 shell]# |
2. Shell Script 의 실행 예시
[root@t-node01 shell]# [root@t-node01 shell]# ./check_ssl.sh ssl.list
[ Check SSL - olleh.com / Port - 443 ] notBefore=Sep 11 09:36:11 2013 GMT notAfter=Nov 30 05:45:36 2014 GMT
[ Check SSL - yahoo.com / Port - 443 ] notBefore=Apr 9 00:00:00 2014 GMT notAfter=Apr 9 23:59:59 2015 GMT
[ Check SSL - google.com / Port - 443 ] notBefore=Apr 23 12:16:09 2014 GMT notAfter=Jul 22 00:00:00 2014 GMT
[ Check SSL - tistory.com / Port - 443 ] notBefore=Apr 9 00:00:00 2014 GMT notAfter=Jun 8 23:59:59 2015 GMT
[root@t-node01 shell]# |
3. Shell Script Code
[root@t-node01 shell]# [root@t-node01 shell]# cat check_ssl.sh #!/bin/bash
LIST_FILE=$1 TMP_CRT=/tmp/tmp.crt echo
while read LIST do URL=`echo ${LIST} | awk '{print $1}'` PORT=`echo ${LIST} | awk '{print $2}'` echo "[ Check SSL - ${URL} / Port - ${PORT} ]" echo "" | openssl s_client -connect ${URL}:${PORT} > ${TMP_CRT} 2>/dev/null openssl x509 -noout -dates -text -in ${TMP_CRT} | egrep 'notBefore|notAfter' echo done < ${LIST_FILE}
[root@t-node01 shell]# |