HPKP(HTTP Public Key Pinning) 헤더 사용하기
Pin 생성
연결하려는 서버(Ex: lesstif.com) 을 openssl 로 연결한 후에 인증서내 SPKI(Subject Public Key Information)를 구함
$ openssl s_client -servername lesstif.com -connect lesstif.com:443 | \ openssl x509 -pubkey -noout | \ openssl rsa -pubin -outform der | \ openssl dgst -sha256 -binary | \ openssl enc -base64
그러면 여러 정보와 함께 SPKI 를 출력함. "writing RSA key" 다음에 있는 문자열이 SPKI
위에서 나온 해시 값을 hash1 이라 정의
이제 Let's encrypt CA 인증서들의 SPKI 값을 추출
$ curl -s https://letsencrypt.org/certs/lets-encrypt-x4-cross-signed.pem | openssl x509 -pubkey | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64 sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis=
$ curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem | openssl x509 -pubkey | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64 YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=
$ curl -s https://letsencrypt.org/certs/isrgrootx1.pem | openssl x509 -pubkey | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64 C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M=
위에서 계산한 hash1 ~ 4를 nginx conf 에 설정. 가독성을 위해 변수를 만들어서 처리
set $PINS "pin-sha256=\"v/IeXD7tDA9WfxCRYSMohd9gHYobKGNznUN0wFT2WTk=\""; set $PINS "${PINS}; pin-sha256=\"sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis=\""; set $PINS "${PINS}; pin-sha256=\"YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=\""; set $PINS "${PINS}; pin-sha256=\"C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M=\""; set $PINS "${PINS}; max-age=60;"; add_header Public-Key-Pins "${PINS}" always;