LoginSignup
3
2

More than 5 years have passed since last update.

余ってるドメインで証明書作れないかな?

Last updated at Posted at 2017-10-30

概要

無料でSSL証明書が使えるということで個人で使ったり、
ローカルの開発環境にSSLを入れられると便利だなと思い、調べてみる。

<検証環境>
* 余っているドメインがある(どこにも使ってない)
* 主にローカル環境で開発をしている

最近HTTPSのサイトが多くなってきたので、オレオレ証明書ではなく正規の証明書を使いたい。

Let's Encryptの認証方法

Let’s Encryptで証明書の取得を行う場合、以下の方法などで、
ドメインを認証する必要があるようです。

  • HTTPによるドメイン認証 (HTTP-01)
  • HTTPSによるドメイン認証 (TLS-SNI-01)
  • DNSによるドメイン認証 (DNS-01)

今回は、公開しているサイトではないので、以下の方法を検討する。

<DNSによるドメインを認証を方法 (DNS-01)>
認証対象のドメインのサブドメインのTXTレコードにトークンが設定されているかで認証する。
( 2016年01月20日に、DNSによる認証チャレンジをサポート )

例)example.comの証明書を取得する場合
※「 _acme-challenge.example.com 」というサブドメインを追加
※ そのドメインの「 TXTレコード 」にトークンを設定する

certbotインストール

今回は、CentOS7なので以下のコマンドを実行します。

ターミナル
$ sudo yum install -y epel-release
$ sudo yum install -y certbot python-certbot-apache

※ その他のOSの場合は、letsencrypt.jp を参照

certbotコマンドでの設定

コマンド実行
DNSでの認証を試してみる。
※「--preferred-challenges」オプションで「dns-01」を指定。

ターミナル
$ sudo certbot certonly \
    --manual \
    --domain www.example.com \
    --email hoge@example.com \
    --agree-tos \
    --manual-public-ip-logging-ok \
    --preferred-challenges dns-01

       ・
       ・
       ・

-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.www.example.com with the following value:

testiKfugafugaqW2-qF_W3doiJhogehogehogeyNCRkY

Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue

コマンドを実行したらトークンが表示されるのでDNSを登録する
※ DNSの設定が反映されるまで、そのまま放置(約1時間ぐらい?)

DNS設定情報

DNS設定
・Host : _acme-challenge.example.com
・Type : TXTレコード
・Value: testiKfugafugaqW2-qF_W3doiJhogehogehogeyNCRkY

DNS設定の反映確認
DNS設定が反映されているか下記コマンドなどで確認する

ターミナル
$ dig -t txt _acme-challenge.example.com

DNS設定が反映されたら
実行中のコマンドで「Enter」を押して進む。

Press Enter to Continue
Waiting for verification...
Resetting dropped connection: acme-v01.api.letsencrypt.org
Resetting dropped connection: acme-v01.api.letsencrypt.org
Cleaning up challenges

Failed authorization procedure. www.example.com (dns-01): 
urn:acme:error:connection :: 
The server could not connect to the client to verify the domain :: 
DNS problem: NXDOMAIN looking up TXT for _acme-challenge.www.example.com

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: www.example.com
   Type:   connection
   Detail: DNS problem: NXDOMAIN looking up TXT for
   _acme-challenge.www.example.com

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address. Additionally, please check that
   your computer has a publicly routable IP address and that no
   firewalls are preventing the server from communicating with the
   client. If you're using the webroot plugin, you should also verify
   that you are serving files from the webroot path you provided.

TXTレコードだけ設定したのではエラーになるみたい...

<エラー内容>

ドメイン名が正しく入力され、
そのドメインのDNSにAレコードに正しいIPアドレスが含まれていることを確認してください。

ドメインは持っているが勉強用のローカル環境なのでAレコードを指定するサーバがない・・・

さすがにドメイン持っているだけでは、証明書の発行は難しそうですね。
時間のある時に、また調べてみます。

参考サイト

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2