【问题标题】:How to get https certificate working on local Laravel Homestead site如何在本地 Laravel Homestead 站点上获取 https 证书
【发布时间】:2018-08-04 18:18:51
【问题描述】:

我遇到了这个问题:

我在 Windows 10 Chrome 版本 65.0.3325.181(官方版本)(64 位)中看到的错误是:

您的连接不是私密的

攻击者可能试图窃取您的 来自 ((mysite)) 的信息(例如,密码、 信息或信用卡)。了解更多 NET::ERR_CERT_AUTHORITY_INVALID

此页面不安全(HTTPS 损坏)。

证书 - 丢失

这个 站点缺少有效的、受信任的证书 (net::ERR_CERT_AUTHORITY_INVALID)。

Firefox Quantum 59.0.2(64 位)说:

您的连接不安全

((mysite)) 的所有者已经配置了他们的网站 不当。为了保护您的信息不被窃取,Firefox 已 没有连接到这个网站。

连接不安全

无法验证此证书,因为 发行人未知。

我已经试过了:https://stackoverflow.com/a/47755133/470749

vboxmanage --version
5.2.6r120293

vagrant -v
Vagrant 2.0.2

git branch
* (HEAD detached at v7.3.0)

vagrant box list
laravel/homestead (virtualbox, 5.2.0)

vagrant box update
==> vboxHomestead: Checking for updates to 'laravel/homestead'
    vboxHomestead: Latest installed version: 5.2.0
    vboxHomestead: Version constraints: >= 5.2.0
    vboxHomestead: Provider: virtualbox
==> vboxHomestead: Box 'laravel/homestead' (v5.2.0) is running the latest version.

我想知道这是否意味着我还没有使用release 7.1.0(在其更改日志中“使用自定义根证书签署 SSL 证书”),我想知道这是否就是我遇到此 SSL HTTPS 问题的原因。

我现在应该尝试哪些后续步骤才能使证书正常工作?

【问题讨论】:

  • Homestead 5.1.0 似乎是最新可用的:app.vagrantup.com/laravel/boxes/homestead。我很困惑。 7.1.2 指的是什么?
  • 你能给我们提供echo | openssl s_client -connect localhost:443 -servername localhost的输出吗?此外,echo | openssl s_client -connect localhost:443 -servername localhost | openssl x509 -text -noout 的输出可能会派上用场。如果需要,请更正域和端口。
  • @x-yuri 是的,但是输出很长。我应该寻找什么? echo | openssl s_client -connect kvb.test:443 -servername kvb.test CONNECTED(000001A0) --- Certificate chain 0 s:/O=Vagrant/C=UN/CN=kvb.test i:/O=Vagrant/C=UN/CN=Homestead vboxHomestead Root CA --- Server certificate -----BEGIN CERTIFICATE----- MIIE7TCCA (... and much more...)
  • “我应该寻找什么?”尚未确定。你能用输出创建一个gist 并给我一个链接吗?还是使用一些 pastebin?

标签: laravel ssl https ssl-certificate homestead


【解决方案1】:

不幸的是,我没有在 Windows 上检查它的简单方法,所以我将在这里使用在 Linux 上运行的 VirtualBox。安装vagrant,然后:

$ vagrant box add laravel/homestead
$ git clone https://github.com/laravel/homestead.git
$ cd homestead
$ git checkout v7.3.0
$ bash init.sh

我稍微简化了Homestead.yaml(您可能更愿意坚持使用默认值):

---
ip: "192.168.10.10"
provider: virtualbox
folders:
    - map: /home/yuri/_/la1
      to: /home/vagrant/code
sites:
    - map: homestead.test
      to: /home/vagrant/code/public

然后:

$ mkdir -p ~/_/la1/public
$ echo '<?php echo "it works";' > ~/_/la1/public/index.php

$ vagrant up

$ vagrant ssh -c 'ls /etc/nginx/sites-enabled'
homestead.test

$ vagrant ssh -c 'cat /etc/nginx/sites-enabled/homestead.test'
server {
    listen 80;
    listen 443 ssl http2;
    server_name .homestead.test;
    root "/home/vagrant/code/public";
    ...
    ssl_certificate     /etc/nginx/ssl/homestead.test.crt;
    ssl_certificate_key /etc/nginx/ssl/homestead.test.key;
}

我们可以看到它在/etc/nginx/ssl 中有证书:

$ vagrant ssh -c 'ls -1 /etc/nginx/ssl'
ca.homestead.homestead.cnf
ca.homestead.homestead.crt
ca.homestead.homestead.key
ca.srl
homestead.test.cnf
homestead.test.crt
homestead.test.csr
homestead.test.key

我尝试在系统范围内信任服务器证书,但没有成功。它出现在 Firefox 证书管理器的服务器选项卡上,但这并没有让 Firefox 信任它。我可能已经添加了一个例外,但信任 CA 证书看起来是一个更好的选择。信任 CA 证书使浏览器信任它们颁发的任何证书(在 Homestead 下运行的新站点)。所以我们要在这里使用 CA 证书:

$ vagrant ssh -c 'cat /etc/nginx/ssl/ca.homestead.homestead.crt' > ca.homestead.homestead.crt

$ sudo trust anchor ca.homestead.homestead.crt

$ trust list | head -n 5
pkcs11:id=%4c%f9%25%11%e5%8d%ad%5c%2a%f3%63%b6%9e%53%c4%70%fa%90%4d%77;type=cert
    type: certificate
    label: Homestead homestead Root CA
    trust: anchor
    category: authority

然后,我将192.168.10.10 homestead.test 添加到/etc/hosts,重新启动 Chromium,它就可以工作了:

附:我正在运行 Chromium 65.0.3325.162 和 Firefox 59.0。

窗口

显然,Windows 没有trust 实用程序。在 Windows 下,有two stores:本地机器和当前用户证书存储。使用本地机器证书存储毫无意义,因为我们让它只为我们当前的用户工作。然后,有子商店。其中两个预定义是最受关注的:受信任的根证书颁发机构和中间证书颁发机构存储。在命令行中通常称为root and CA

您可以通过 chrome://settings/?search=Manage%20certificates 访问 Chrome 的证书管理器,然后点击管理证书。最受关注的是受信任的根证书颁发机构和中间证书颁发机构选项卡。

管理证书的一种方法是通过command line

>rem list Current User > Trusted Root Certification Authorities store
>certutil.exe -store -user root

>rem list Local Machine > Intermediate Certification Authorities store
>certutil.exe -store -enterprise CA

>rem GUI version of -store command
>certutil.exe -viewstore -user CA

>rem add certificate to Current User > Trusted Root Certification Authorities store
>certutil.exe -addstore -user root path\to\file.crt

>rem delete certificate from Current User > Trusted Root Certification Authorities store by serial number
>certutil.exe -delstore -user root 03259fa1

>rem GUI version of -delstore command
>certutil.exe -viewdelstore -user CA

结果如下(本地机器和当前用户证书存储):

root
    homestead.test.crt
        error
    ca.homestead.homestead.crt
        appears in Trusted Root Certification Authorities tab
CA
    homestead.test.crt
        doesn't work, appears in Other People tab
    ca.homestead.homestead.crt
        doesn't work, appears in Intermediate Certification Authorities tab

其他选项包括在资源管理器中双击证书、从 Chrome 的证书管理器导入证书、使用证书 MMC 管理单元(运行 certmgr.msc)或使用 CertMgr.exe

对于那些安装了grep的人,这里是快速检查证书在哪里的方法:

>certutil.exe -store -user root | grep "homestead\|^root\|^CA" ^
& certutil.exe -store -user CA | grep "homestead\|^root\|^CA" ^
& certutil.exe -store -enterprise root | grep "homestead\|^root\|^CA" ^
& certutil.exe -store -enterprise CA | grep "homestead\|^root\|^CA"

因此,将 CA 证书安装到 Current User > Trusted Root Certification Authorities 存储似乎是最佳选择。并且确保不要忘记restart your browser

更深入的解释它的工作原理

Vagrantfile 中,它需要scripts/homestead.rb,然后运行Homestead.configure。这就是配置vagrant 以进行所有必要准备的方法。

我们可以在那里see:

if settings.include? 'sites'
    settings["sites"].each do |site|

        # Create SSL certificate
        config.vm.provision "shell" do |s|
            s.name = "Creating Certificate: " + site["map"]
            s.path = scriptDir + "/create-certificate.sh"
            s.args = [site["map"]]
        end

        ...

        config.vm.provision "shell" do |s|
            ...
            s.path = scriptDir + "/serve-#{type}.sh"
            ...
        end

        ...
    end
end

所以,这些two files 分别创建证书和nginx 配置。

进一步阅读

How to make browser trust localhost SSL certificate?

【讨论】:

  • 在地址栏中看到https://homestead.test 旁边的绿色锁的屏幕截图真是太棒了。但是,唯一相关的步骤是首先将 /etc/nginx/ssl/ca.homestead.homestead.crt 从我的 Homestead Vagrant 框中复制到 Windows 上可访问的路径,然后运行 ​​sudo trust anchor ca.homestead.homestead.crt 的等效项。所以这就是我现在卡住的地方:
  • 当我以管理员身份运行 Windows 命令提示符并尝试运行 trust anchor 命令时,我收到此错误:p11-kit: couldn't complete writing file: C:/Program Files/Git/mingw64/etc/pki/ca-trust/source\Homestead_vboxHomestead_Root_CA.p11-kit: No such file or directory p11-kit: couldn't create object: The operation failed
  • 啊,我们可能越来越近了。我以管理员身份从 Windows 命令提示符运行 certutil -addstore -enterprise -f "Root" ca.homestead.vboxHomestead.crt,现在 Chrome 的错误有所不同:This page is not secure (broken HTTPS). Resources - active content with certificate errors You have recently allowed content loaded with certificate errors (such as scripts or iframes) to run on this site.
  • @Ryan 尝试使用CertMgrCertMgr /s /r localMachineCertMgr /s /r currentUser 列出证书。 CertMgr /add homestead.test.crt /s /r currentUser root 添加证书。 More info。不确定浏览器是否会咨询这些商店。如果他们这样做,您很可能会在浏览器证书管理器的“权限”选项卡下找到 CA 证书。
  • 我会因为你的努力而奖励赏金(尤其是你的绿锁截图,这让我希望它是可能的)。我认为最终我缺少的步骤是:使用 Windows 命令提示符作为管理员运行certutil -addstore -enterprise -f "Root" ca.homestead.vboxHomestead.crt。然后它仍然没有工作,但我去吃午饭,当我回来唤醒我的电脑时,它工作了。即使我使用的是使用 xip.io 服务的 URL,它也适用于我的本地站点。我很兴奋。也许剩下的唯一挑战是:如何让其他设备(例如 iPhone)信任该证书。
【解决方案2】:

显然您必须将您的证书添加到受信任的 CA 存储中。我让它自动决定,但没有奏效。我也将它添加到我的个人商店中,但它也不起作用。

因此,步骤(如果您在 Windows 上)是按 Windows 键并输入“Internet 选项”并打开您的 Internet 选项。然后单击“内容”选项卡。从这里点击中间按钮“证书”。

然后单击导入和下一步。浏览到您保存证书的位置。

然后单击“将所有证书放入以下存储”并单击浏览并选择“受信任的根证书颁发机构”。

你应该得到一个弹出窗口,要求你确认并警告你和所有爵士乐。

然后确保重新启动浏览器。在 chrome 上,您可以在 URL 栏中输入:chrome://restart。繁荣,我希望这对你有帮助!

【讨论】:

【解决方案3】:

您的问题是发行人未知。正如您在错误中提到的那样; “此站点缺少有效的、受信任的证书” 要么 "此站点缺少有效的可信证书 (net::ERR_CERT_AUTHORITY_INVALID)"

让我们首先了解为什么会发生此错误。浏览器具有受信任的证书颁发机构列表。您可以从不同浏览器的设置/首选项部分看到此列表。如果您的证书不是由这些机构之一颁发,那么您将收到上述错误。

在本地主机上修复它 我可以想到两种可能的解决方案;

  1. 手动将证书添加到浏览器,它将以 https 开始打开。

  1. 使用已受信任的机构签署证书。在本地服务器上安装证书。在 /etc/hosts 文件中使用与您签署证书的域相同的名称配置主机。

我希望它能解决这个问题。

【讨论】:

  • 我想我已经尝试过 #1(但我不是 100% 确定您推荐了哪些步骤)并且也不清楚 #2 的步骤。
  • 我同意@Ryan 关于第 1 步的看法。我已尝试手动添加证书,但仍然没有显示绿色图标。
猜你喜欢
  • 2012-12-01
  • 2015-03-04
  • 2011-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多