티스토리 뷰

발생일: 2019.05.13

 

키워드: 인증서, https, ssl, letsencrypt, cordova, phonegap, 코르도바, 폰갭, certbot, 자가 서명 인증서, self-signed certificate

 

문제:

 

로컬 환경에서 https 를 구성하기 위해 자가 서명 인증서를 만들어 적용했다. (자가 서명 인증서는 https://ohgyun.com/429 참고)

브라우저에서는 잘 테스트했는데, 시뮬레이터에서는 동작하지 않는다.

 

왜 그럴까?

 

 

해결책:

 

우리 서비스는 코르도바 기반의 하이브리드 앱으로 구현되어 있다.

코르도바 보안 가이드에 따르면, 자체 서명된 인증서는 보안에 취약하기 때문에 기본적으로는 허용하지 않는다고 한다.

 

디버깅 옵션을 주면 된다고 하는데, 실제 환경과 비슷하게 테스트할 수 있게 신뢰할 수 있는 인증 기간의 인증서를 사용하는 쪽으로 해결했다.

 

LetsEncrypt 에서 무료로 인증서를 제공하며, OS에 따라 certbot 모듈을 이용해 생성하면 된다.

 

certbot으로 각 서버에 자동으로 인증서 설정을 할 수 있지만, 우린 기존 환경을 미리 구성해둬서 인증서만 생성하면 되는 상황이었다.

 

아래 명령으로 수동으로 인증서를 생성했다. -d 옵션에 할당한 dev.example.com을 본인의 도메인에 맞게 넣어주면 된다.

 

    $ sudo certbot -d dev.example.com --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns certonly

 

 

위 명령어를 실행하면, 아래와 같이 DNS TXT를 설정하라고 한다.

 

    Please deploy a DNS TXT record under the name

    _acme-challenge.dev.example.com with the following value:

 

    m61ycxBWXXKIt8ws2LJEelAYSt5wITUCyHxzHw9Slys

 

 

해당 도메인의 소유 여부를 확인하려는 목적이다.

도메인 제공 서비스에서 _acme-challenge.dev.example.com 의 레코드 셋을 만들고, 타입을 TXT로 Value 에 출력된 값을 넣어주면 된다.

 

우리는 AWS의 Route53을 사용하고 있어서, 아래와 같이 추가해줬다.

 

 

 

다음 단계로 진행하면, OS 환경에 따라 특정 경로에 인증서가 생성된다.

 

인증서는 3개월마다 갱신해줘야 한다.

`sudo certbot renew` 커맨드로 실행하면 되고, 젠킨스에 배치로 걸어둘 예정이다.

 

 

논의:

 

# API 호출 제한

 

테스트로 계속 호출했더니, API 호출 제한에 걸렸다.

테스트 목적으로는 --dry-run 플래그로 API 스테이징 서버를 호출하면 된다.

 

    $ sudo certbot -d dev.example.com --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns certonly --dry-run

 

 

# AWS Linux에서의 설치 

 

AWS Linux 에서 certbot이 yum 으로 설치되지 않는다.

가이드가 있어서 따라해봤는데, 여전히 안된다.

 

certbot-auto 파일을 별도로 받아 설정하는 방식으로 해결했다.

https://certbot.eff.org/lets-encrypt/pip-other

 

    $ sudo /usr/local/bin/certbot-auto -d dev.example.com --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns certonly

 

 

# 관련 모듈을 찾을 수 없다는 오류

 

아래와 같이 관련 파이썬 모듈을 찾을 수 없다고 나오는 경우:

 

    [ec2-user@admin ~]$ /usr/local/bin/certbot-auto renew
    Requesting to rerun /usr/local/bin/certbot-auto with root privileges...
    Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt:
    Traceback (most recent call last):
      File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in 
        from certbot.main import main
    ... 중략
      File "/opt/eff.org/certbot/venv/local/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in 
        from OpenSSL import crypto, SSL
    ... 중략
    ImportError: No module named cryptography

 

sitecustomize.py 파일을 생성한 후에, 아래와 같이 패스를 추가해주면 된다.

 

    $ sudo vi /opt/eff.org/certbot/venv/lib64/python2.7/site-packages/sitecustomize.py

 

    import site

    site.addsitedir('/opt/eff.org/certbot/venv/lib64/python2.7/dist-packages')

 

 

# TXT record 가 제대로 업데이트 되었는지 확인하고 싶을 땐, txt type으로 nslookup 하면 된다,

 

  $ nslookup -type=txt _acme-challenge.dev.example.com

 

 

참고:

 

Certbot:

https://certbot.eff.org/

 

Guide: Using Let's Encrypt SSL Certificates for a local or network server

https://r.je/ adguide-lets-encrypt-certificate-for-local-development#vjecerts

 

LetsEncrypt Staging Environment

https://letsencrypt.org/docs/staging-environment/

 

Amazon Linux AMI 에서 letencrypt certbot 으로 SSL 인증서 발급 에러

https://www.lesstif.com/pages/viewpage.action?pageId=54952117

반응형
댓글
공지사항