Azure Web Appsの拡張機能を使わずにLet’s Encryptで証明書を発行してOpenSSLでPFX形式へ変換してみた

App Service,Azure

Let’s EncryptのSSL証明書作成をAzure Web Appsで試してみようとして調べてみた所、Azure Web Appsの拡張機能を使う方法が多く紹介されていました。
Azure Web AppsをLinux+PHPの構成で試していたのですが、Web Appsの拡張機能が有効になってませんでした。

どうしようか?と途方に暮れていたのですが、よく考えたらAzure Web Apps(Linux)ってUbuntuだから普通にできるのでは?と気づき試してみました。
結果、Ubuntuで実施する手順で証明書の作成からOpen SSLを使ったPFX形式への変換までできました。
今回実施した作業内容をメモとして記しておきます。

スポンサーリンク

Lets Encryptを使ってSSL証明書発行

最初にAzure Portal上からAzure Web AppsへSSHで接続します。
SSH接続後のLets Encrypt証明書発行手順は以下の通りです。

    • aptアップデート
    • certbotのインストール
    • certbotコマンドで証明書の発行

※最初にapt updateしてからでないとcertbotインストール時にエラーになりました。
※Azure Web Appsの再起動等を実施するとcertbotのパッケージがなくなります。インストールから再度実施する必要があります。
※メールアドレス等の入力が表示されずにそのまま作成される場合もあります。

#updateを実施する

[root@ホスト名 tmp]# apt -y update

#certbotをインストールします

[root@ホスト名 tmp]# apt -y install certbot

#証明書を発行する(ドメインは自分のサイトに合わせて設定します。)

[root@ホスト名 tmp]# certbot certonly –webroot -w /home/site/wwwroot -d ドメイン名

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c’ to
cancel):メールアドレスを入力

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
(A)gree/(C)ancel: A    (承諾の確認です。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 our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
(Y)es/(N)o: N    (案内メール送信の確認です。必要ならYを選択します)

作成されたメッセージが表示されます。

Let’s Encryptで発行された証明書は/etc/letsencrypt/live/ドメイン名/ 配下に生成されます。

OpenSSLを使ってpem形式からpfx形式へ変換する

Azure Web Apps等で独自ドメインの証明書を使う場合はpfx形式になります。
opensslコマンドでpfx形式へ変換します。

opensslはデフォルトで入っていた為インストールの必要はありませんでした。

ノーパスワードで証明書作成時はパスワードに何も入力せずそのままEnterします。

#証明書が作成されているディレクトリに移動します

[root@ホスト名 tmp]# cd /etc/letsencrypt/live/ドメイン名/

#opensslコマンドでpem形式からpfx形式に変換する

[root@ホスト名 tmp]# openssl pkcs12 -export -inkey privkey.pem -in cert.pem -out 証明書名.pfx

Enter Export Password:パスワード
Verifying – Enter Export Password:パスワード

pfx形式の証明書が作成されたメッセージが表示されます

作成されたpfx形式の証明書ファイルをダウンロード可能な場所(/home配下等)に移動します。
FTPS等でサーバからダウンロードすれば作業完了です。

作業後は念のため/etc/letsencrypt/live配下やサーバ上の証明書は削除しておきましょう。

App ServiceでのSSL証明書設定についてはこちら。

Azure Key Vaultの証明書期限切れ前のメール通知についてはこちら。