2017년 5월 19일 금요일

무료 HTTPS 인증서 만들기


기본적인 보안을 위해서 https 의 적용은 기본이다.

인증기관을 통해서 유료로 받을수도 있지만, 무료로 받을수도 있다.
(startssl 이라는 곳에서도 무료로 받을수 있다.)

Let's Encrypt 를 이용한 무료 인증서를 받는 방법을 설명한다.

적용할 사이트는 test.yangchigi.com 이다.

준비사항

git, python


certbot 을 설치한다.
- letsencrypt 가 2016 년 5월 기준으로 certbot 으로 이름이 바뀌었다. 하지만 내부적으로 아직도 letsencrpyt 명령들이 존재한다.

https://certbot.eff.org 에서 서버와 OS를 선택하면 적당한 certbot 의 설치방법을 알려준다.

macOS 기준으로 설명한다.

brew install certbot

설치후 certbot 명령을 내리면 아래와 같이 su 권한이 있어야 된다고 나온다.

파일들을 모아두기 위해서 폴더를 만든후 해당 폴더 안에서 작업을 진행한다.


mkdir certbot
cd certbot
certbot --config-dir=./ --work-dir=./ --logs-dir=./

등록할 이메일을 요구한다.


Saving debug log to /Users/user/accounts/certbot/letsencrypt.log
Enter email address (used for urgent renewal and security notices) (Enter 'c' to

이메일을 입력한후 약관동의

Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A

메일 기타기관들과 공유한다는 동의

Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: 

도메인명을 입력한다.


No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel):

오류가 발생한다.

Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for yangchigi.com
No vhost exists with servername or alias of: yangchigi.com (or it's in a file with multiple vhosts, which Certbot can't parse yet). No vhost was selected. Please specify ServerName or ServerAlias in the Apache config, or split vhosts into separate files.
Falling back to default vhost *:443...
Cleaning up challenges
File: 
 - Could not be found to be deleted /etc/apache2/other/le_tls_sni_01_cert_challenge.conf - LE probably shut down unexpectedly
Error while running apachectl graceful.
This operation requires root.


Encountered exception during recovery
Error while running apachectl graceful.
This operation requires root.

Traceback (most recent call last):
  File "/usr/local/Cellar/certbot/0.13.0_1/libexec/lib/python2.7/site-packages/certbot/error_handler.py", line 99, in _call_registered
    self.funcs[-1]()
  File "/usr/local/Cellar/certbot/0.13.0_1/libexec/lib/python2.7/site-packages/certbot/auth_handler.py", line 284, in _cleanup_challenges
    self.auth.cleanup(achalls)
  File "/usr/local/Cellar/certbot/0.13.0_1/libexec/lib/python2.7/site-packages/certbot_apache/configurator.py", line 1788, in cleanup
    self.restart()
  File "/usr/local/Cellar/certbot/0.13.0_1/libexec/lib/python2.7/site-packages/certbot_apache/configurator.py", line 1677, in restart
    self._reload()
  File "/usr/local/Cellar/certbot/0.13.0_1/libexec/lib/python2.7/site-packages/certbot_apache/configurator.py", line 1688, in _reload
    raise errors.MisconfigurationError(str(err))
MisconfigurationError: Error while running apachectl graceful.
This operation requires root.


An unexpected error occurred:
IOError: [Errno 13] Permission denied: '/etc/apache2/other/le_tls_sni_01_cert_challenge.conf'
Please see the logfiles in /Users/user/accounts/certbot for more details.

IMPORTANT NOTES:
 - Your account credentials have been saved in your Certbot
   configuration directory at /Users/user/accounts/certbot. You should
   make a secure backup of this folder now. This configuration
   directory will also contain certificates and private keys obtained
   by Certbot so making regular backups of this folder is ideal.



아파치 설정값에 접근을 하지못해서 문제가 발생한다.
- 사용자 권한이므로 당연히 접근하지 못한다.
- 아파치가 설치되어 있지만, 난 nginx  를 이용할거기 때문에 다시 작업을 진행한다.

인증만 받기로 한다. (certonly 옵션을 준다.)
사용자 이메일과 약관동의등은 다시 물어 보지 않는다.

certbot --config-dir=./ --work-dir=./ --logs-dir=./ certonly

ACME CA 를 어떻게 확인 할건지 물어 본다.

How would you like to authenticate with the ACME CA?
-------------------------------------------------------------------------------
1: Apache Web Server plugin - Beta (apache)
2: Place files in webroot directory (webroot)
3: Spin up a temporary webserver (standalone)
-------------------------------------------------------------------------------
Select the appropriate number [1-3] then [enter] (press 'c' to cancel): 

웹루트를 선택한다.


Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel):

도메인명을 물어 본다. yangchigi.com  을 입력후... 1번선택한다.


Obtaining a new certificate
Performing the following challenges:
http-01 challenge for yangchigi.com

Select the webroot for yangchigi.com:
-------------------------------------------------------------------------------
1: Enter a new webroot
-------------------------------------------------------------------------------
Press 1 [enter] to confirm the selection (press 'c' to cancel): 


Input the webroot for yangchigi.com: (Enter 'c' to cancel):

웹루트가 어디냐고 물어 본다.
그냥 현재폴더의 www 라고 한다.(혹시 몰라서 www폴더를 생성한다.)

오류발생한다.
인증서를 생성하는게 아니라, 소유권을 확인하는 작업이다.
호스팅서버에서 운영이 되어야 가능한데, 내가 사용하는 호스팅서버에서 python 을 설치할수 없다.

다시...

내 로컬서버를 도메인에 연결한다.
wo.yangchigi.com 을 회사 ip 에 연결한다.

로컬 웹서버를 종료후 단독모드로 인증을 요청한다.


certbot --config-dir=./ --work-dir=./ --logs-dir=./ certonly --standalone -d yangchigi.com -d wo.yangchigi.com

방화벽에 443 포트도 함께 열려 있어야 한다.


certbot --config-dir=./ --work-dir=./ --logs-dir=./ certonly --standalone -d wo.yangchigi.com
Saving debug log to /Users/user/cert/letsencrypt.log
Obtaining a new certificate
An unexpected error occurred:
The server experienced an internal error :: Failed to get registration by key
Please see the logfiles in /Users/user/cert for more details.

오류발생한다.

이전에 작업한게 문제가 발생한듯 싶다. 폴더도 이상한 폴더를 가리키고 있다. 해당 폴더를 삭제한다.

결론 실패...

실제 운영되는 서버에서 인증을 받아야 되거나, macOS 의 문제일듯 싶다.



댓글 없음:

댓글 쓰기

참고: 블로그의 회원만 댓글을 작성할 수 있습니다.

렛츠인크립트 - certbot CentOS 6 에 설치하기

운영중인 서버가 오래된 CentOS 6 이다. 해당서버에 certbot 을 설치하기 위한 설차를 설명한다. 기본적인 설명은 공식사이트 https://certbot.eff.org/#centos6-apache  에 보면 자세히 설명되어 있다. 1...