自己署名証明書は使用できません。ローカルホストから

自己署名証明書は使用できません。ローカルホストから

次のように、テスト目的でlocalhostの自己署名証明書を作成しました。

openssl genrsa -out key.pem 2048
openssl req -new -key key.pem -out certificate.csr
openssl x509 -req -in certificate.csr -signkey key.pem -out certificate.pem

FQDNに「localhost」を指定しました。それはすべてです。私は他のことをしたり、どこにもコピーしたりしませんでした。 3つのファイルすべてが私のアプリケーションディレクトリにあります。

localhostでapacheやnginx以外のWebサーバーを実行すると、次のエラーが発生します。

$ curl -v https://localhost:3345
* Rebuilt URL to: https://localhost:3345/
*   Trying ::1...
* connect to ::1 port 3345 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3345 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS alert, Server hello (2):
* SSL certificate problem: self signed certificate
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

これが重要な場合、私のコードは次のようになります。

startApp = do
  let port = 3345
  print $ "Listening the port " ++ (show port) ++ " ..."
  let tls = tlsSettings "certificate.pem" "key.pem"
  runTLS tls (setPort port defaultSettings) app

ご覧のとおり、私は「csr」とポート3345の代わりに「pem」と「pem」を使用しています。

私はArchを使用していますが、Ubuntu用のソリューションも必要です。

このエラーをどのように解決できますか?

ブラウザでもエラーが発生します。特にFFでは:

The owner of localhost has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website.

ベストアンサー1

デフォルトでは、Curlはシステムのトラストストアを使用して証明書チェーンの信頼を決定します。このトラストストアには、信頼できるCA証明書のリストが含まれています。自己署名し、トラストストアのCA証明書にチェーンを使用しないため、Callはチェーンを信頼していないため、要求は失敗します。

誰でも:

  1. 自己署名ではなく信頼できる認証局でCSRに署名します(暗号化しよう接続されたルート証明書により、ほぼすべてのトラストストアで無料で信頼できます。
  2. システムトラストストアに証明書を追加する
  3. --cacert <your cert>この証明書のみを信頼する
  4. 使用curl -k(検証が行われていないため推奨されません)

おすすめ記事