목표
fullchain.pem을 갖고 있을 때 curl https 성공하기
환경
Ubuntu 20.04.6 LTS
우선 curl https를 해 보면 아래와 같이 출력된다.
ubuntu@ubuntu:~$ curl https://api.motrader.co.kr/terms/list curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.haxx.se/docs/sslcerts.html curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above. |
따라서 api.motrader.co.kr의 인증서를 따로 설치해줘야 한다.
내 경우 certbot으로 만든 fullchain.pem을 가지고 있었다. 타 사이트의 인증서를 가지고 오는 방법은 모르겠다.
sudo certbot certificates로 Certificate Path를 알아낸다.
ubuntu@ubuntu:~$ sudo certbot certificates Saving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Found the following certs: Certificate Name: api.motrader.co.kr Domains: api.motrader.co.kr Expiry Date: 2025-02-13 19:03:41+00:00 (VALID: 54 days) Certificate Path: /etc/letsencrypt/live/api.motrader.co.kr/fullchain.pem Private Key Path: /etc/letsencrypt/live/api.motrader.co.kr/privkey.pem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
이제 cp 명령어로 fullchain.pem을 /usr/share/ca-certificates 폴더에 복사해준다. 이름은 마음대로 정한다.
sudo cp /etc/letsencrypt/live/api.motrader.co.kr/fullchain.pem /usr/share/ca-certificates/apimot.pem
폴더에 복사만 해서는 업데이트가 안 된다. ca-certificates.conf를 수정해줘야 한다. vim 명령어로 /etc/ca-certificates.conf를 연 다음, 맨 아래 줄에 apimot.pem(위에 썼던 이름)을 적어준다.
sudo vim /etc/ca-certificates.conf
마지막으로 update-ca-certificates 명령어를 입력하면 성공적으로 업데이트가 된다.
sudo update-ca-certificates Updating certificates in /etc/ssl/certs... rehash: warning: skipping apimot.pem.pem,it does not contain exactly one certificate or CRL rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL rehash: warning: skipping apimot.pem,it does not contain exactly one certificate or CRL 1 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d... Adding debian:apimot.pem.pem done. done. |
이제 curl https가 잘 동작하는 것을 확인할 수 있다.
ubuntu@ubuntu:~$ curl https://api.motrader.co.kr/terms/list {"list":[{"termsId":1,"title":"개인정보 수집 및 이용 동의","context":"<p>개인정보 처리방침</p><p>주식회사... |
Reference
https://askubuntu.com/a/649463/1767589 이 사이트에서 명령어를 알아냈다.
https://incomplete-chain.badssl.com 이 사이트로 타 사이트 인증서 설치를 실습해 볼 수도 있다.