[toc]
Certbot(æ§Let's Encrypt)ã¯ç¡æã§SSL/TLS証ææ¸ãçºè¡ã§ããèªè¨¼å±(CA)ã§ããæå¹æéã90æ¥(ç´3ã¶æ)ã¨çãã§ãããã³ãã³ãã«ããèªååãå¯è½ã§å®æçã«å®è¡ãããã¨ã§å¸¸ã«è¨¼ææ¸ãæ´æ°ãç¶ãããã¨ãã§ãã¾ãã
証ææ¸ãåå¾ããã«ãããããã¡ã¤ã³ãèªåã§ç®¡çãã¦ãããã®èªè¨¼æ¹å¼ã以ä¸ã®ä¸ã¤ããµãã¼ãããã¦ãã¾ãã
- HTTP-01
Let's Encryptã®èªè¨¼å±ããã¯ã³ã¿ã¤ã ãã¼ã¯ã³ãçºè¡ãã¦ããããWebãµã¼ãã«èªè¨¼ç¨ãã¡ã¤ã«ãè¨ç½®ããã èªè¨¼å±ããHTTP(80çªãã¼ã)ã§ã¢ã¯ã»ã¹ãã¦ããããã¯ã³ã¿ã¤ã ãã¼ã¯ã³ã¨èªè¨¼ç¨ãã¡ã¤ã«ã¨ã®å¦¥å½æ§ãæ¤è¨¼ããã TLS-SNI-01
HTTP-01ã¨åãæ¹æ³ã ããHTTPS(443ãã¼ã)ã使ç¨ãããDNS-01
Let's Encryptã®èªè¨¼å±ããçºè¡ãã¦ããã£ãã¯ã³ã¿ã¤ã ãã¼ã¯ã³ã対象ãã¡ã¤ã³ã®TXTã¬ã³ã¼ãã«ç»é²ãããã¨ã§æ¤è¨¼ããã
ã¢ã¯ã»ã¹ãå¶éããã¦ãããµã¼ãã«å¯¾ãã¦è¨¼ææ¸ãåå¾ããå ´åã¯DNS-01æ¹å¼ãæ¡ç¨ãããã¨èããã¯ãã§ãã Certbotã³ãã³ãã§ä»ã¾ã§ã§ããªãã£ãããããµã¼ããã¼ãã£è£½ã®ã¹ã¯ãªããã§ããdehydrated(æ§letsencrypt.sh)ã使ã£ã¦ãã¾ããããv0.9.0ããCertbotã§ããµãã¼ããããããã«ãªãã¾ããã
https://github.com/certbot/certbot/pull/2061 https://github.com/certbot/certbot/milestone/22
ããã§ãCertbotã§DNS-01æ¹å¼ã«ããSSL/TLS証ææ¸ãåå¾ããæ¹æ³ããç´¹ä»ãã¾ãã
å®è¡ç°å¢
- CentOS 7.2.1511
- 対象ãã¡ã¤ã³: jicoman.info
Certbotã®ã¤ã³ã¹ãã¼ã«
epelãªãã¸ããªãæã£ã¦ãã¦Yumã§ã¤ã³ã¹ãã¼ã«ãã¾ãã
$ sudo su -
% rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
% yum install certbot
æåã«ãã証ææ¸ã®åå¾
ååã®ã¿æåã§è¡ãã¾ãã ã³ãã³ãã®ãªãã·ã§ã³ãªã©ã¯ããã¥ã¡ã³ãããåç §ãã ããã
% certbot certonly \
--manual \
--domain jicoman.info \
--email <ã¡ã¼ã«ã¢ãã¬ã¹> \
--agree-tos \
--manual-public-ip-logging-ok \
--preferred-challenges dns
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
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: N # Nã§ãï½
Obtaining a new certificate
Performing the following challenges:
DNS-01 challenge for jicoman.info
Please deploy a DNS TXT record under the name
_acme-challenge.jicoman.info with the following value:
pWQR1O6Qrp8_aajNVXuu5bIdo9nv6SLvpzzTrdviTG8
Once this is deployed,
Press Enter to Continue
ããã§ä¸è¨ã®ãããªã¯ã³ã¿ã¤ã ãã¼ã¯ã³ãçºè¡ããã¾ãã®ã§ãacme-challenge.<対象ãã¡ã¤ã³>
(ä»åã¯acme-challenge.jicoman.info)ã®TXTã¬ã³ã¼ãã«ã¯ã³ã¿ã¤ã ãã¼ã¯ã³ãç»é²ãã¦ãã ããã
ç»é²å¾ãã¨ã³ã¿ã¼ãæ¼ãã¨åéãã¾ããã¬ã³ã¼ãç»é²å¾ããã ã¨åæ ããã¦ããªãã®ã§å°ãå¾
ã¡ã¾ãããã
æåããã¨ä»¥ä¸ã®ããã«è¡¨ç¤ºããã¾ãã
Waiting for verification...
Resetting dropped connection: acme-v01.api.letsencrypt.org
Cleaning up challenges
Generating key (2048 bits): /etc/letsencrypt/keys/0000_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0000_csr-certbot.pem
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/jicoman.info/fullchain.pem. Your cert will
expire on 2017-07-11. To obtain a new or tweaked version of this
certificate in the future, simply run certbot again. To
non-interactively renew all of your certificates, run "certbot
renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. 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.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let\'s Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
証ææ¸ã®ç¢ºèª
åå¾ãã証ææ¸ãè¦ã¦ã¿ã¾ãã 証ææ¸ãæ´æ°ããã¦åå¾ãã度ã«ããã¡ã¤ã«åã®æ°åãã¤ã³ã¯ãªã¡ã³ãããããã¡ã¤ã«ãçæããã¾ãã ä¾ãã°ã次ã«æ´æ°ãããå ´åã¯ãxxx2.pem ãæ°ãã«çæããã¾ãã
% ls -la /etc/letsencrypt/archive/jicoman.info/
total 16
-rw-r--r--. 1 root root 1789 Apr 12 11:36 cert1.pem # SSL/TLS ãµã¼ã証ææ¸ (å
¬ééµãå«ã)
-rw-r--r--. 1 root root 1647 Apr 12 11:36 chain1.pem # ä¸é証ææ¸
-rw-r--r--. 1 root root 3436 Apr 12 11:36 fullchain1.pem # ãµã¼ã証ææ¸ã¨ä¸é証ææ¸ãçµåããããã®
-rw-r--r--. 1 root root 1704 Apr 12 11:36 privkey1.pem # ç§å¯éµ
ããããããã ã¨æ´æ°ã®åº¦ã«Webãµã¼ã(Apache, nginxãªã©)ã®è¨å®ãæ¸ãæããªããã°ãªãã大å¤é¢åã§ãã ããã§æ¬¡ã®è¨¼ææ¸ãè¦ã¦ã¿ã¾ãããã
% ls -la /etc/letsencrypt/live/jicoman.info/
total 4
drwxr-xr-x. 2 root root 88 Apr 12 11:36 .
drwx------. 3 root root 25 Apr 12 11:36 ..
lrwxrwxrwx. 1 root root 36 Apr 12 11:36 cert.pem -> ../../archive/jicoman.info/cert1.pem
lrwxrwxrwx. 1 root root 37 Apr 12 11:36 chain.pem -> ../../archive/jicoman.info/chain1.pem
lrwxrwxrwx. 1 root root 41 Apr 12 11:36 fullchain.pem -> ../../archive/jicoman.info/fullchain1.pem
lrwxrwxrwx. 1 root root 39 Apr 12 11:36 privkey.pem -> ../../archive/jicoman.info/privkey1.pem
-rw-r--r--. 1 root root 543 Apr 12 11:36 README
ã·ã³ããªãã¯ãªã³ã¯ãå¼µããã¦ãããã¨ããããã¾ãã æ°ããªè¨¼ææ¸ãåå¾ããã度ã«ã·ã³ããªãã¯ãªã³ã¯ã®åãå ãæ´æ°ãã¦ããããããApacheãNginxã®è¨å®ã§ã¯ãã¡ãã®ãã¹ãæå®ãããã¨ã§ãæ´æ°ãããã¨ãã¦ãè¨å®ãå¤æ´ããªãã¦ãæ¸ã¿ã¾ãã
次ã«è¨¼ææ¸ã®å¦¥å½æ§ã確èªãã¾ãã
% /etc/letsencrypt/live/jicoman.info
% wget http://pastebin.com/raw.php?i=z7SP4pb9 -O ca.crt
% printf "\n" >> ca.crt
% cat chain.pem >> ca.crt
% openssl verify -CAfile ca.crt fullchain.pem
fullchain.pem: OK
% openssl verify -CAfile ca.crt chain.pem
chain.pem: OK
OKã¨åºã¦ããã®ã§å¦¥å½æ§ã¯åé¡ãªãããã§ãã
証ææ¸ã®åå¾ã®èªåå
äºåç®ä»¥éã¯èªåçã«è¨¼ææ¸ãæ´æ°ãããã¨ãã§ãã¾ãã
ããã¯ã¹ã¯ãªãã
dehydrated(æ§letsencrypt.sh)ã®å ´åã¨åæ§ã«èªè¨¼ãã£ã¬ã³ã¸ããããã¯ã¹ã¯ãªãããç¨æããå¿ è¦ãããã¾ããDNSãµã¼ãã¹ã¯Route53ãå©ç¨ãã¦ãããããRoute53ã¨é£æºãã¦ããã¹ã¯ãªãã(Python製)ã使ç¨ãããã¨ã«ãã¾ãã
# pipã³ãã³ããã¤ã³ã¹ãã¼ã«ããã¦ããªãå ´å
% curl https://bootstrap.pypa.io/get-pip.py | python
% pip install certbot-external-auth
% wget https://gist.githubusercontent.com/rmarchei/98489c05f0898abe612eec916508f2bf/raw/a7f51af111c98544c0cee8739ebd0b88c39b3afa/route53.py
% pip install boto
% chmod +x route53.py
% mv route53.py /usr/local/bin/
Route53ã¸ã¬ã³ã¼ãç»é²ã»åé¤ããAWSã¢ã¯ã»ã¹æ¨©éãè¨å®
EC2ã¤ã³ã¹ã¿ã³ã¹ã§ããã°IAMãã¼ã«ãããã§ãªããã°AWSã¢ã¯ã»ã¹ãã¼ãçºè¡ãã¾ãã IAMããªã·ã¼ã¯ AmazonRoute53DomainsFullAccess ããªã·ã¼ãã¢ã¿ãããã¦ãã ããã
AWS CLIã®ã¤ã³ã¹ãã¼ã«ã¨è¨å®ãè¡ãã¾ãã
% pip install awscli
% aws configure
AWS Access Key ID [None]: xxxxxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxxxxxxxxxxxxxx
Default region name [None]: ap-northeast-1
Default output format [None]: json
% aws --version
aws-cli/1.11.76 Python/2.7.5 Linux/3.10.0-327.el7.x86_64 botocore/1.5.39
å®è¡
% certbot certonly \
--domain jicoman.info \
--email <ã¡ã¼ã«ã¢ãã¬ã¹> \
--agree-tos \
--preferred-challenges dns \
--renew-by-default \
--text \
--configurator certbot-external-auth:out \
--certbot-external-auth:out-public-ip-logging-ok \
--certbot-external-auth:out-handler /usr/local/bin/route53.py
å
ã»ã©æåã§åå¾ããå ´åã¨ããã¤ããªãã·ã§ã³ãç°ãªã£ã¦ãã¾ãã
--renew-by-default
ãæå®ãã¦ãããããæ¢åã®è¨¼ææ¸ã®æéé¢ä¿ãªã証ææ¸ãæ´æ°ãã¾ãã
å®è¡ããã¨ä»¥ä¸ã®ãããªå®è¡çµæã«ãªãã¾ãã
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Renewing an existing certificate
Performing the following challenges:
DNS-01 challenge for jicoman.info
Handler output (pre-perform):
- Stdout:
hook: pre-perform
domain: None
txt_challenge: None
- Stderr:
{"cmd": "perform_challenge", "type": "DNS-01", "domain": "jicoman.info", "token": "lBaIBOfClJNCtbaJemzZEy4V7Sy4x0eNdo_MGHVjYoc", "validation": "pWQR1O6Qrp9_aajNVXuJ5bIyo9nv6SLvpzzTrkviTG8", "txt_domain": "_acme-challenge.jicoman.info", "key_auth": "lBaIBOfClJNCtbaJemzZEy4V7Sy4x0eNdo_MGHVjYoc.vmmEovcNYjx_TQDf5enLiwHclrCqxjfIx8OxEK82_w8"}
Handler output (perform):
- Stdout:
hook: perform
domain: None
txt_challenge: None
- Stderr:
Handler output (post-perform):
- Stdout:
hook: post-perform
domain: None
txt_challenge: None
- Stderr:
Waiting for verification...
Cleaning up challenges
Handler output (pre-cleanup):
- Stdout:
hook: pre-cleanup
domain: None
txt_challenge: None
- Stderr:
{"cmd": "cleanup", "type": "DNS-01", "status": "valid", "domain": "jicoman.info", "token": "lBaIBOfClJNCtbaJemzZEy4V7Sy4x0eNdo_MGHVjYoc", "validation": "pWQR1O6Qrp9_aajNVXuJ5bIyo9nv6SLvpzzTrkviTG8", "key_auth": "lBaIBOfClJNCtbaJemzZEy4V7Sy4x0eNdo_MGHVjYoc.vmmEovcNYjx_TQDf5enLiwHclrCqxjfIx8OxEK82_w8", "validated": null, "error": null}
Handler output (cleanup):
- Stdout:
hook: cleanup
domain: None
txt_challenge: None
- Stderr:
Handler output (post-cleanup):
- Stdout:
hook: post-cleanup
domain: None
txt_challenge: None
- Stderr:
Generating key (2048 bits): /etc/letsencrypt/keys/0001_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0001_csr-certbot.pem
{"cmd": "report", "messages": [{"priority": 1, "on_crash": true, "lines": ["Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/jicoman.info/fullchain.pem. Your cert will expire on 2017-07-11. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew all of your certificates, run \"certbot renew\""]}, {"priority": 2, "on_crash": true, "lines": ["If you like Certbot, please consider supporting our work by:", "", "Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate", "Donating to EFF: https://eff.org/donate-le", ""]}]}
çæããããã¡ã¤ã«ç¾¤ãè¦ã¦ãæ´æ°ããã¦ãããã¨ããããã¾ãã
% ls -la /etc/letsencrypt/live/jicoman.info/
total 8
drwxr-xr-x. 2 root root 101 Apr 12 12:40 .
drwx------. 3 root root 25 Apr 12 11:36 ..
-rw-r--r--. 1 root root 2866 Apr 12 11:57 ca.crt
lrwxrwxrwx. 1 root root 36 Apr 12 12:40 cert.pem -> ../../archive/jicoman.info/cert2.pem
lrwxrwxrwx. 1 root root 37 Apr 12 12:40 chain.pem -> ../../archive/jicoman.info/chain2.pem
lrwxrwxrwx. 1 root root 41 Apr 12 12:40 fullchain.pem -> ../../archive/jicoman.info/fullchain2.pem
lrwxrwxrwx. 1 root root 39 Apr 12 12:40 privkey.pem -> ../../archive/jicoman.info/privkey2.pem
-rw-r--r--. 1 root root 543 Apr 12 11:36 README
å®æçã«å®è¡ããå ´å
Cronãªã©ã§å®æçã«å®è¡ããæéãè¿ã¥ãããæ´æ°ããããã«ãã¾ãã
% certbot certonly \
--domain jicoman.info \
--email <ã¡ã¼ã«ã¢ãã¬ã¹> \
--agree-tos \
--preferred-challenges dns \
--keep-until-expiring \
--expand \
--text \
--configurator certbot-external-auth:out \
--certbot-external-auth:out-public-ip-logging-ok \
--certbot-external-auth:out-handler /usr/local/bin/route53.py 2> /dev/null
{"cmd": "report", "messages": []}
--keep-until-expiring
ãªãã·ã§ã³ãæå®ãããã¨ã§ãç¾è¨¼ææ¸ã®æå¹æéãè¿ã¥ãã¾ã§ã¯æ´æ°ãã¾ããã
æå¾ã«
Certbotã§DNS-01æ¹å¼ã«ããSSL/TLS証ææ¸ãæåã»èªåã»å®æå®è¡ã§åå¾ããæ¹æ³ãç´¹ä»ãã¾ããã Certbotã¯ãªãã·ã§ã³ãããªãå¤ãã§ãããããã¥ã¡ã³ããè¦ãªããããã°æ³å以ä¸ã«ç°¡åã«ã§ãã¾ãã ç¡æã§SSL/TLS証ææ¸ã使ããã®ã§å人ãµã¼ãã¹ãæã£ã¦ãã人ã¯ãã²å°å ¥ãæ¤è¨ããæ¹ããããã¨æãã¾ãã
æ´æ°ããããSlackéç¥ããããWindowsã®IIS対å¿ãªã©ã¯å¥è¨äºã§æ¸ããã¨æãã¾ãã
åè
- Certbotæ¬å®¶
- Let's Encryptç·åãã¼ã¿ã«(æ¥æ¬èª)
- Let's Encryptã®DNS-01ã使ç¨ãã¦ç¡æã®SSL証ææ¸ãWebãµã¼ããªãã§åå¾ãã -- ãºãã¿ãã
- Let's Encryptã§DNS-01æ¹å¼ã使ã£ãéã«ã¯ã¨ã¦ããä¸è©±ã«ãªãã¾ãã(ä¼ç¤¾ã®ååã§ãããã¾ã)
- How to use Let's Encrypt DNS challenge validation? - Server Fault
- github.com/EnigmaBridge/certbot-external-auth
- èªåã§DNS-01æ¹å¼ã§èªè¨¼ãã§ããããã«ãªããµã¼ããã¼ãã£è£½ãã©ã°ã¤ã³
- Examples for DNS 01 hooks
- DNS-01æ¹å¼ã®èªè¨¼ãã£ã¬ã³ã¸ãããããã¯ã¹ã¯ãªããã®ãªã³ã¯é