当前位置

尝试Let's Encrypt的免费SSL证书

James Qi 在 2016年12月12日 - 16:34 提交

  了解StartCom与WoSign(沃通)及母公司奇虎360的瓜葛后,对其能否在2017年1月份Mozilla FireFox 51和Google Chrome 56正式版推出之前拿出根证书被吊销的解决方案不敢报太大希望,周末就开始尝试获取Let's Encrypt这家的免费SSL证书,折腾一番后也终于获得了来自这家的第一份可用证书,现在记录一下一些要点。

一、背景介绍:

  这是一家非盈利机构,由电子前哨基金会、Mozilla基金会、密歇根大学2014年发起,属于互联网安全研究小组的一个项目,维基百科中的介绍:Let' s Encrypt (English), Let's Encrypt (中文)

  还有Google, Cisco, Facebook, Ford Foundation, HP等知名公司和机构赞助支持,可信度很高。

  2015年开始测试发放证书,2016年正式发放证书。采用ACME协议(Automated Certificate Management Environment)。

二、获取证书:

  其官方网站上介绍是通过服务器上运行脚本来获取的,我也是这样尝试成功的,不过确实还是有点麻烦。还有一个办法,第一次获取可以通过一个网站SSL for Free来进行,这个过程中的帮助就看得明显一些,类似从其它收费的证书提供商那里购买、下载的流程,建议新手试一试。

  对于拥有服务器Shell权限的用户,官方推荐使用Certbot来验证、下载、更新证书,对于我们用CentOS 6和Apache的用户,其推荐使用certbot-auto软件,可以自动进行运行环境检查升级、配置修改、域名验证、记录日志、下载证书、更新证书等工作,详细介绍请看Certbot文档

  不过我还是花了好些时间来摸索使用的,碰到的一些问题:

  • 这个软件依赖很多环境才能运行,需要安装或升级python、open-ssl等10个以上软件,如果服务器在国内,下载这些安装包有可能很慢或者报错,可以反复多运行几次看,或者在国外服务器上安装,另外可以创建或者修改~/.pip/pip.conf使用国内的镜像来解决;
    vim ~/.pip/pip.conf
    [global]
    index-url = http://mirrors.aliyun.com/pypi/simple/
    [install]
    trusted-host=mirrors.aliyun.com
    或
    cat > ~/.pip/pip.conf <<EOF
    [global]
    index-url = https://pypi.doubanio.com/simple/
    
    [install]
    trusted-host=pypi.doubanio.com
    EOF
    或
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  • 下载后修改运行权限,然后./path/to/certbot-auto 可以帮助修改apache配置,但如果不想这个软件来修改配置,可以运行./path/to/certbot-auto certonly 只获取证书,然后自己来修改apache配置,命令行帮助信息:
      certbot-auto [SUBCOMMAND] [options] [-d domain] [-d domain] ...
    
    Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
    it will attempt to use a webserver both for obtaining and installing the
    cert. Major SUBCOMMANDS are:
    
      (default) run        Obtain & install a cert in your current webserver
      certonly             Obtain cert, but do not install it (aka "auth")
      install              Install a previously obtained cert in a server
      renew                Renew previously obtained certs that are near expiry
      revoke               Revoke a previously obtained certificate
      register             Perform tasks related to registering with the CA
      rollback             Rollback server configuration changes made during install
      config_changes       Show changes made to server config during installation
      plugins              Display information about installed plugins
    
    Choice of server plugins for obtaining and installing cert:
    
      --apache          Use the Apache plugin for authentication & installation
      --standalone      Run a standalone webserver for authentication
      --nginx           Use the Nginx plugin for authentication & installation
      --webroot         Place files in a server's webroot folder for authentication
    
    OR use different plugins to obtain (authenticate) the cert and then install it:
    
      --authenticator standalone --installer apache
    
    More detailed help:
    
      -h, --help [topic]    print this message, or detailed help on a topic;
                            the available topics are:
    
       all, automation, paths, security, testing, or any of the subcommands or
       plugins (certonly, renew, install, register, nginx, apache, standalone,
       webroot, etc.)
  • 屏幕上出现apache、webroot、nginx、standalone、manual等几种插件选择的时候,
    • apache:生成证书并自动修改apache相关conf配置文件;
    • webroot:在本机的web目录中创建验证目录和文件;
    • nginx:适合nginx
    • standalone:适合本机还没有web服务的情况用一个单独的web服务
    • manual:需要另外进行域名验证、适合网站不在本机的情况
  • 我们用的一般命令:
    ./certbot-auto certonly --webroot -w /usr/local/apache/htdocs/example1.com/ -d ar.example1.com -d ar.m.example1.com -w /usr/local/apache/htdocs/wiki.example2.com/ -d ar.example2.com -d ar.m.example2.com
    
  • 验证成功后软件会下载证书文件,放在/etc/letencrypt/live目录下,自己再修改httpd-ssl.conf来进行配置指向这些证书文件就可以;
    SSLCertificateFile "/etc/letsencrypt/live/en.18dao.net-0001/cert.pem"
    SSLCertificateKeyFile "/etc/letsencrypt/live/en.18dao.net-0001/privkey.pem"
    SSLCertificateChainFile "/etc/letsencrypt/live/en.18dao.net-0001/fullchain.pem"
  • 软件的运行日志放在/var/log/letsencrypt/letsencrypt.log中。

三、优点缺点:

  优点:

  • 免费,自然是最大的优点;
  • 可信,基本不用担心根证书被废等问题;
  • 便捷,只提供域名验证,如果熟悉的话,几分钟就可以搞定一张证书;

  缺点:

  • 目前没有通配符域名证书,不过每张证书可以包含100个域名(可以包含多级域名、多个根域名),一般够了,我们个别网站有超过100个子域名的情况可以做成多张证书,就是麻烦一些,目前只支持A记录验证,不支持CNAME;
  • 不提供个人认证、企业认证、扩展认证等,但对于我们现在多数网站来说,只需要https实现加密以及符合搜索引擎优化需要,不进行那些认证是可以的;
  • 每张证书只有90天有效期,需要到期前续期,官方推荐设法进行配置成自动运行续期(在linux的crontab中设置每天两次定期运行./certbot-auto renew --post-hook "service httpd restart"会自动检查已经生成的证书,如果距离到期还早就跳过更新)。

  先记录到这里,以后补充。


  补充:Drupal多站点设置的时候,域名验证时有报错404或者403,需要添加一个webroot/.well-known/.htaccess,放入:

RewriteEngine On
Satisfy Any

  还可以在webroot/.htaccess中这样加一句:

RewriteRule "^.well-known/acme-challenge" - [L](新加的一行)
RewriteRule "(^|/)." - [F](原来的一行)

  这样就不会报错了,这个小问题花了我好几个小时!


  2016-12-29再补充:Windows XP中,IE6, IE7, IE8都不支持SNI,一个服务器配置了多个HTTPS站点时,只有第一个能正常访问,另外的会报SSL证书有问题(都使用第一个虚拟主机的证书),为了兼容,可以重新生成一个包含该服务器上所有域名的总的证书放在第一个虚拟主机设置中,Lets Encrypt一张证书最多可以放置100个域名,生成新证书的时候certbot-auto提示你是否要扩展以前存在的证书,可以选中扩展,也可以放弃,然后加上--duplicate参数重新运行生成一个单独的证书。


  2017-1-19补充:打电话去问了startcom的客服,现在还没有与mozilla达成解决办法,而1月20日firefox将推出更新版本从而让startssl失效,我等不及只好全部都更换为let's encrypt证书了。把在godaddy注册的国内网站用的域名dns改为了dnspod(cname有10个的限制,但a记录没有限制),国外网站用的域名dns依然用godaddy自带的(有100项子域名的限制,又购买了premium尊享dns解析服务,才可能添加无限数量的子域名),全部重新生成证书(超过100个子域名的情况就分成多个证书,例如330个子域名就生成4个证书)。在部分域名解析从godaddy改为dnspod又改回godaddy的过程中,产生了2个多余的ds记录,导致certbot-auto报错,查了几天才从一篇老外的问答中看到,删除这2个ds记录后解决。

添加新评论

Plain text

  • 不允许使用HTML标签。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。