!!!OpenBSD Webサーバ の SSL(TSL) 接続 (httpd on OpenBSD ==6.8== 7.0) {{category OpenBSD,nolink}}OpenBSD の Webサーバ httpd(relayd) で、SSL(TSL) 接続する。 自己証明書(オレオレ証明書) と ACME client を用いての Let's Encrypt の証明書の取得と更新をする。 httpd 自体を動かす設定は、[[OpenBSD/httpd/68(relayd)]] を参照。 * 関連 man → [httpd(8)|https://man.openbsd.org/httpd.8], [httpd.conf(5)|https://man.openbsd.org/httpd.conf.5], [openssl(1)|https://man.openbsd.org/openssl.1], [acme-client(1)|https://man.openbsd.org/acme-client.1] !!!自己証明書で SSL(TSL) 接続 !!秘密鍵と証明書の作成 LibreSSL の openssl コマンドを使って、サーバの秘密鍵と証明書(自己署名証明書)を作成する。 !秘密鍵の作成 bbb# openssl genrsa -out /etc/ssl/private/server.key 2048 Generating RSA private key, 2048 bit long modulus ..........................+++++ ..............+++++ e is 65537 (0x10001) !証明書署名要求(CSR)の作成 -subj オプションの内容は、対象のサーバに合わせて変える。指定しなければ、対話形式で入力となる。 特に CN については、実際のホスト名(URL の FDQN)に合わせる。 bbb# openssl req -new -key /etc/ssl/private/server.key -out /etc/ssl/private/server.csr -subj "/C=JP/ST=Tokyo/L=Chuo-Ku/CN=example.com" !証明書(CRT)の作成 bbb# openssl x509 -days 3650 -req -signkey /etc/ssl/private/server.key -in /etc/ssl/private/server.csr -out /etc/ssl/server.crt Signature ok subject=/C=JP/ST=Tokyo/L=Chuo-Ku/CN=example.com Getting Private key !秘密鍵ファイルの内容を確認 bbb# openssl rsa -text -noout -in /etc/ssl/private/server.key RSA Private-Key: (2048 bit) modulus:   :以下略 !証明書署名要求の内容を確認 bbb# openssl req -text -noout -in /etc/ssl/private/server.csr Certificate Request: Data: Version: 0 (0x0) Subject: C=JP, ST=Tokyo, L=Chuo-Ku, CN=example.com Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus:   :以下略 !証明書ファイルの内容を確認 bbb# openssl x509 -text -noout -in /etc/ssl/server.crt Certificate: Data: Version: 1 (0x0) Serial Number: ac:fd:4f:7d:d5:52:9b:a0 Signature Algorithm: sha256WithRSAEncryption Issuer: C=JP, ST=Tokyo, L=Chuo-Ku, CN=example.com Validity Not Before: Dec 5 11:02:41 2021 GMT Not After : Dec 3 11:02:41 2031 GMT Subject: C=JP, ST=Tokyo, L=Chuo-Ku, CN=example.com Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus:   :以下略 !! Webサーバ(httpd) の設定 '''/etc/httpd.conf''' に設定する。 TSL(HTTP over SSL/TLS)接続で待つポート番号と、作成したキーファイル /etc/ssl/private/server.key 、証明書 /etc/ssl/server.crt を指定する。 server "default" { listen on * port 80 listen on * tls port 443 tls { certificate "/etc/ssl/server.crt" key "/etc/ssl/private/server.key" } # :中略 } !! HTTPS通信の疎通確認 まぁ、ブラウザでアクセスして、期待するページが表示されれば OK なんだけど。 ! curl 自己証明書なので '''-k''' (--insecure) オプションをつけて、安全でないSSL接続も許可するようにする。 bbb$ curl -svk https://localhost:443/ 1> /dev/null * Trying 127.0.0.1:443... * Connected to localhost (127.0.0.1) port 8443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/cert.pem CApath: none * (304) (OUT), TLS handshake, Client hello (1): } [314 bytes data] * (304) (IN), TLS handshake, Server hello (2): { [122 bytes data] * (304) (IN), TLS handshake, Unknown (8): { [10 bytes data] * (304) (IN), TLS handshake, Certificate (11): { [795 bytes data] * (304) (IN), TLS handshake, CERT verify (15): { [264 bytes data] * (304) (IN), TLS handshake, Finished (20): { [36 bytes data] * (304) (OUT), TLS handshake, Finished (20): } [36 bytes data] * SSL connection using unknown / AEAD-CHACHA20-POLY1305-SHA256 * ALPN, server did not agree to a protocol * Server certificate: * subject: C=JP; ST=Tokyo; L=Chuo-Ku; CN=example.com * start date: Dec 5 11:02:41 2021 GMT * expire date: Dec 3 11:02:41 2031 GMT * issuer: C=JP; ST=Tokyo; L=Chuo-Ku; CN=example.com * SSL certificate verify result: self signed certificate (18), continuing anyway. > GET / HTTP/1.1 > Host: localhost:443 > User-Agent: curl/7.72.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Connection: keep-alive < Content-Length: 170 < Content-Type: text/html < Date: Fri, 14 Jan 2022 23:49:29 GMT < Last-Modified: Wed, 13 Jan 2021 15:54:49 GMT < Server: OpenBSD httpd < { [170 bytes data] * Connection #0 to host localhost left intact また、'''--tlsv1'''(-1) または、'''--sslv2'''(-2)、'''--sslv3'''(-3) を指定することで、 TLSv1.0 以上 または、SSLv2、SSLv3 で接続する。もっとも、LibreSSL は SSLv2 および SSLv3 をサポートしない。 さらに、'''--tlsv1.0''' や '''--tlsv1.1'''、'''--tlsv1.2'''、'''--tlsv1.3''' で、TLSv1.0 以上、TLSv1.1 以上… となる。 bbb$ curl -svk -ssl3 https://localhost:443/ 1> /dev/null * Trying 127.0.0.1:443... * Connected to localhost (127.0.0.1) port 443 (#0) * LibreSSL was built without SSLv3 support * Closing connection 0 bbb$ bbb$ curl -svk -tsl1 https://localhost:443/ 1> /dev/null * Trying 127.0.0.1:443... * Connected to localhost (127.0.0.1) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/cert.pem   :後略 bbb$ bbb$ curl -svk -tsl1.3 https://localhost:443/ 1> /dev/null * Trying 127.0.0.1:443... * Connected to localhost (127.0.0.1) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/cert.pem   :後略