LoginSignup
3
2

More than 5 years have passed since last update.

仮設メールサーバでSSL証明書の認証メールを受信する

Posted at

こんにちは、ひろかずです。
検証のために3ヶ月くらいSSL証明書を使いたくなったので、仮のメールサーバを立てて認証メールを受け取れるようにした時のメモです。

ちなみに、こちらから3ヶ月のテスト用SSL証明書を取得できます。

前提

  • Publicに引けるドメインを所有していること。
  • ドメインの管理をRoute53で行っていること。
  • ドメインを管理しているRoute53の管理権を有していること。
  • 証明書取得用のCSRを用意していること。

工程

  1. 仮のメールサーバ設定
  2. AWS側の設定
  3. 動作確認
  4. 認証メール取得
  5. 後片付け

1. 仮のメールサーバ設定

1-1. Instance起動

今回は、suz-lab_centos-core-6.5.1(ami-99107d98)を使いました。
Postfixが既にインストールされてて楽ちんです。

1-2. main.cfの設定

外からのメールを受信できる用にmain.cfに以下変更を加えます。
※ mydomain.comを実際のドメインに置き換えてください。

 83 #mydomain = domain.tld
 84 mydomain = mydomain.com
 :
114 #inet_interfaces = all
115 inet_interfaces = all
 :
166 #mydestination = $myhostname, localhost.$mydomain, localhost
167 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
 :
421 home_mailbox = Maildir/

postfixを再起動して、ポートのListen状況を確認します。

# service postfix restart
postfix を停止中:                                          [  OK  ]
postfix を起動中:                                          [  OK  ]

# netstat -luntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
:
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      9109/master
:

1-3. 受信ユーザの作成

承認メールアドレスは、 admin@mydomain.com 宛に送信するので、 admin ユーザを作成します。

# useradd -s /sbin/nologin admin

ユーザが作成されてますね。

# getent passwd | grep admin
admin:x:500:500::/home/admin:/sbin/nologin

2. AWS側の設定

2-1. Aレコード、MXレコードの作成

以下のようにAレコードとMXレコードを作成します。
IPアドレスは、1-1で起動したInstanceのEIPを設定して下さい。
route53_a_mx.png

2-2. Security Groupの開放(動作確認用)

送信元IPアドレスを絞って開放します。
sg_limit.png

3. 動作確認

telnetコマンドでメールを送って、届くことを確認します。

$ telnet mydomain.com 25
Trying xxx.xxx.xxx.xxx...
Connected to mydomain.com.
Escape character is '^]'.
220 ip-xxx-xxx-xxx-xxx.mydomain.com ESMTP
helo fnifni
250 ip-xxx-xxx-xxx-xxx.mydomain.com
mail from:<test@test.com>
250 2.1.0 Ok
rcpt to:<admin@mydomain.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Subject: smpt test
Hi! This is test.
.
250 2.0.0 Ok: queued as 874C9103B
quit
221 2.0.0 Bye
Connection closed by foreign host.

送信メールは、adminユーザの配下に着信してます。

# pwd
/home/admin/Maildir/new

# ll
合計 4
-rw------- 1 admin admin 312  1月 17 13:28 2016 1453004889.Vca41I6021aM742403.ip-xxx-xxx-xxx-xxx

# cat 1453004889.Vca41I6021aM742403.ip-xxx-xxx-xxx-xxx
Return-Path: <test@test.com>
X-Original-To: admin@mydomain.com
Delivered-To: admin@mydomain.com
Received: from fnifni (unknown [xxx.xxx.xxx.xxx])
    by ip-xxx-xxx-xxx-xxx.mydomain.com (Postfix) with SMTP id 874C9103B
    for <admin@mydomain.com>; Sun, 17 Jan 2016 13:27:46 +0900 (JST)
Subject: smpt test

Hi! This is test.

4. 認証メール取得

4-1. Security Groupの開放(承認メール取得用)

ポート25を一時的に開放します。
sg_open.png

今回は、こちらからSSL証明書を取得しました。

CSRを設定してメールの宛先に admin@mydomain.com を指定すると、
メールが届きましたね。

# ll
合計 12
-rw------- 1 admin admin  312  1月 17 13:28 2016 1453004889.Vca41I6021aM742403.ip-xxx-xxx-xxx-xxx
-rw------- 1 admin admin 7330  1月 17 14:57 2016 1453010242.Vca41I6021dM133810.ip-xxx-xxx-xxx-xxx

中身を見ると以下箇所がありました。

# cat 1453010242.Vca41I6021dM133810.ip-xxx-xxx-xxx-xxx
Return-Path: <no_reply_support@trust-provider.com>
X-Original-To: admin@mydomain.com
Delivered-To: admin@mydomain.com
:
To permit the issuance of the certificate please browse to
https://secure.comodo.net/products/EnterDCVCode?orderNumber=xxxxxxxx
and enter the following "validation code":

        hogehoge...
:

承認URLアドレスにアクセスして、validation codeを入力すると、承認完了です。

5. 後片付け

以下設定を削除して、完了です。

  • 開放したSecurity Group設定
  • 追加したAレコード、MXレコード
  • 仮設Instanceのterminate

最後に

この手法は、認証方式が メール認証 のみ(主に激安SSL)で、SSL証明書を取得対象ドメインでメールサーバを保有していないケースでも使える手法です。
激安SSLは管理や保守、サポートの観点で かなりの割り切り が必要ですで、商用サイトで激安SSLを取得する時は、信頼できるところから購入することをお勧めします。

以上で作業は完了です。
お疲れ様でした。

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