Files
My-Blog/public/network-ssl/index.html
2025-07-05 15:03:43 +08:00

258 lines
13 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Dich&#x27;blog</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<meta name="robots" content="noodp"/>
<link rel="stylesheet" href="https://blog.dich.bid/style.css">
<link rel="stylesheet" href="https://blog.dich.bid/color/blue.css">
<link rel="stylesheet" href="https://blog.dich.bid/color/background_dark.css">
<link rel="stylesheet" href="https://blog.dich.bid/font-hack-subset.css">
<meta name="description" content="">
<meta property="og:description" content="">
<meta property="og:title" content="Dich'blog">
<meta property="og:type" content="article">
<meta property="og:url" content="https://blog.dich.bid/network-ssl/">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:description" content="">
<meta name="twitter:title" content="Dich'blog">
<meta property="twitter:domain" content="blog.dich.bid">
<meta property="twitter:url" content="https://blog.dich.bid/network-ssl/">
<link rel="alternate" type="application/atom+xml" title="Dich&#x27;blog Atom Feed" href="https://blog.dich.bid/atom.xml" />
<link rel="icon" type="image/png" href=&#x2F;dich.webp />
<!-- ✅ Added center alignment styles -->
<style>
.footer {
text-align: center;
padding: 1rem 0;
}
.footer__inner {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.copyright {
text-align: center;
}
</style>
</head>
<body class="">
<div class="container">
<header class="header">
<div class="header__inner">
<div class="header__logo">
<a href="https://blog.dich.bid" style="text-decoration: none;">
<div class="logo">
Dich&#x27;blog
</div>
</a>
</div>
</div>
<nav class="menu">
<ul class="menu__inner">
<li class="active"><a href="https://blog.dich.bid">blog</a></li>
<li><a href="https://blog.dich.bid/archive">archive</a></li>
<li><a href="https://blog.dich.bid/tags">tags</a></li>
<li><a href="https://blog.dich.bid/weekly">weekly</a></li>
<li><a href="https://blog.dich.bid/search">search</a></li>
<li><a href="https://blog.dich.bid/about">about me</a></li>
<li><a href="https://blog.dich.bid/links">links</a></li>
<li><a href="https://blog.dich.bid/atom.xml">rss</a></li>
<li><a href="https://github.com/Dichgrem" target="_blank" rel="noopener noreferrer">github</a></li>
</ul>
</nav>
</header>
<div class="content">
<div class="post">
<h1 class="post-title"><a href="https://blog.dich.bid/network-ssl/">网络艺术:SSL&#x2F;TLS证书</a></h1>
<div class="post-meta-inline">
<span class="post-date">
2024-02-15
</span>
</div>
<span class="post-tags-inline">
:: tags:&nbsp;
<a class="post-tag" href="https://blog.dich.bid/tags/network/">#Network</a></span>
<div class="post-content">
<p>前言 什么是SSL/TLS证书它有什么作用如何部署</p>
<span id="continue-reading"></span><h2 id="shen-me-shi-ssl-tlszheng-shu">什么是SSL/TLS证书</h2>
<p>SSL 的全称是 <code>Secure Sockets Layer</code>(安全套接字层),而 TLS 的全称是 <code>Transport Layer Security</code>(传输层安全协议)。最初由 Netscape 开发的 SSL 协议用于保护网络通信,但由于其存在的安全漏洞,后来被更新、更安全的 TLS 协议所取代。</p>
<p>如今当我们谈论“SSL 证书”时,实际上指的是支持 TLS 协议的数字证书,<code>两者在功能上没有本质区别,只是在命名上沿用了历史传统</code>。该证书是由受信任的数字证书颁发机构 CA在验证服务器身份后颁发且具有服务器身份验证和数据传输加密功能。简单来说就是<code>HTTP+SSL/TLS证书=HTTPS.</code></p>
<h2 id="sslzheng-shu-shi-ru-he-gong-zuo-de">SSL证书是如何工作的</h2>
<ul>
<li>当我们点击一个超链接HTTP浏览器帮我们跳转到新标签页</li>
<li>通过DNSDomain name system查询找到该域名地址栏中的如www.xxx.com之类的字符对应的IP地址可能是某个CDN的地址</li>
<li>服务器上已经配置好certificate.crt公钥和private.key私钥</li>
<li>CDN随后与真正的服务器建立连接服务器上的反向代理可能是nginx或者caddy检测连接并用配置好的证书将连接升级为HTTPS</li>
<li>HTTPS握手并将内容显示在浏览器上。</li>
</ul>
<h2 id="ssl-tlszheng-shu-de-wo-shou-guo-cheng">SSL/TLS证书的握手过程</h2>
<ul>
<li>客户端发送"ClientHello"消息包含支持的加密算法和TLS版本</li>
<li>服务器回应"ServerHello"消息选择加密算法并发送SSL/TLS证书</li>
<li>客户端验证证书的有效性(通过内置的CA根证书)</li>
<li>客户端使用服务器公钥加密一个"预主密钥"并发送给服务器;</li>
<li>双方根据预主密钥生成会话密钥;</li>
<li>使用会话密钥进行加密通信;</li>
<li>加密通信:握手完成后,所有数据传输都使用协商好的对称密钥加密。</li>
</ul>
<blockquote>
<p>使用公钥加密的数据只能用对应的私钥解密,使用私钥加密(签名)的数据可以用对应的公钥验证。</p>
</blockquote>
<blockquote>
<p>客户端和服务器都支持非常多的密码套件比如“ECDHE-RSA-AES256-GCM-SHA384”。格式是“密钥交换算法 + 签名算法 + 对称加密算法 + 摘要算法”,这个密码套件的意思就是:“握手时使用 ECDHE 算法进行密钥交换,用 RSA 签名和身份认证,握手后的通信使用 AES 对称算法,密钥长度 256 位,分组模式是 GCM摘要算法 SHA384 用于消息认证和产生随机数。”</p>
</blockquote>
<h2 id="cazheng-shu">CA证书</h2>
<p>可以看到验证证书的有效性需要通过CA证书由CA机构如DigiCert
Let's Encrypt等颁布CA证书的层级结构如下</p>
<ul>
<li>根CA证书最高级别的证书自签名是整个信任链的起点.</li>
<li>中间CA证书由根CA签发可以签发终端实体证书或其他中间CA证书.</li>
<li>终端实体证书由根CA或中间CA签发给网站、服务器等实体使用.</li>
</ul>
<p>操作系统和浏览器<code>内置了受信任的根CA证书列表</code>,当验证网站证书时系统会沿着证书链向上追溯至根CA;如果能找到一个受信任的根CA且证书链上所有签名有效则验证通过.这就是保护我们上网安全的<code>信任链</code>的基础。</p>
<p>当我们访问网页时,往往会看到左上角的<code></code>图标,里面是<code>Google Trust Services</code>或者<code>DigiCert Inc</code>等等代表证书的颁发来源。如果锁提示不安全可能是证书过期或者找不到CA证书即有可能是自签名证书。<code>什么是自签名证书?</code></p>
<h2 id="zheng-shu-ban-fa">证书颁发</h2>
<p>我们先来看证书颁发的流程。</p>
<ul>
<li>证书申请:网站所有者向证书颁发机构(CA)申请SSL/TLS证书提供域名和组织信息。</li>
<li>身份验证CA验证申请者的身份和域名所有权。验证方式包括域名验证(DV)、组织验证(OV)或扩展验证(EV)。</li>
<li>证书签发验证通过后CA使用其私钥为申请者签发数字证书包含公钥、域名信息、颁发者信息和有效期等。</li>
<li>安装部署网站管理员将证书安装到Web服务器上。</li>
</ul>
<p>可以看到过程有点麻烦,个人建站的话往往使用自签名证书,即<code>ssh-keygen</code>生成的公钥和私钥由于没有CA所以会显示不安全。</p>
<h2 id="shen-qing-zheng-shu">申请证书</h2>
<ul>
<li>
<p><a href="https://www.sslforfree.com/">sslforfree</a>由 ZeroSSL 支持颁发的免费SSL证书.</p>
</li>
<li>
<p>通过<a href="https://amh.sh/ssl.htm">AMH</a>提供的自助在线申请服务申请SSL通配符证书.需要注册AMH账号.</p>
</li>
<li>
<p><a href="https://letsencrypt.osfipin.com/">letsencrypt</a>支持申请多渠道SSL证书.</p>
</li>
<li>
<p>借助<a href="https://punchsalad.com/ssl-certificate-generator/">Punchsalad</a>提供的在线服务申请SSL证书无需登录仅需邮箱即可完成SSL通配符证书申请和签发.</p>
</li>
</ul>
<h2 id="dv-ov-ev-sslzheng-shu-de-qu-bie">DV/OV/EV SSL证书的区别</h2>
<p>以下是三种主要SSL证书验证类型的对比</p>
<table><thead><tr><th>特性</th><th>域名型SSL (DV SSL)</th><th>企业型SSL (OV SSL)</th><th>增强型SSL (EV SSL)</th></tr></thead><tbody>
<tr><td><strong>验证级别</strong></td><td>最低</td><td>中等</td><td>最高</td></tr>
<tr><td><strong>验证内容</strong></td><td>仅验证域名所有权</td><td>验证域名所有权和组织信息</td><td>最严格的验证,包括法律、物理和运营存在的全面验证</td></tr>
<tr><td><strong>验证流程</strong></td><td>自动化验证邮件、DNS记录等</td><td>半自动验证</td><td>人工审核为主</td></tr>
<tr><td><strong>签发时间</strong></td><td>几分钟到数小时</td><td>1-3个工作日</td><td>5-7个工作日</td></tr>
<tr><td><strong>浏览器显示</strong></td><td>普通锁图标</td><td>普通锁图标</td><td>地址栏绿色显示(部分浏览器已取消)</td></tr>
<tr><td><strong>适用场景</strong></td><td>个人博客、信息网站</td><td>企业网站、电子商务</td><td>银行、金融机构、大型电商</td></tr>
<tr><td><strong>成本</strong></td><td></td><td>中等</td><td></td></tr>
<tr><td><strong>信任度</strong></td><td>基本</td><td>中等</td><td>最高</td></tr>
<tr><td><strong>证书信息</strong></td><td>只包含域名信息</td><td>包含组织名称和域名</td><td>包含完整的组织详细信息</td></tr>
<tr><td><strong>安全加密强度</strong></td><td>相同</td><td>相同</td><td>相同</td></tr>
</tbody></table>
<h2 id="zheng-shu-lei-xing">证书类型</h2>
<p>有时候可以购买如<code>*.xxx.com</code>的通配符证书即一个证书通用与所有子域名。以及还有其他如多域名证书和上面提到的DV/OV/EV证书的类型。</p>
<table><thead><tr><th>证书类型</th><th>覆盖范围</th><th>安全级别</th><th>验证过程</th><th>适用场景</th><th>价格范围</th></tr></thead><tbody>
<tr><td>单域名证书</td><td>仅一个特定域名</td><td>基本到高</td><td>DV/OV/EV</td><td>个人网站或小型企业</td><td>低到高</td></tr>
<tr><td>通配符证书</td><td>主域名及其所有一级子域名</td><td>基本到中等</td><td>DV/OV</td><td>拥有多个子域名的网站</td><td>中等到高</td></tr>
<tr><td>多域名证书(SAN)</td><td>多个不同域名</td><td>基本到高</td><td>DV/OV/EV</td><td>管理多个不相关域名的企业</td><td>中等到高</td></tr>
<tr><td>自签名证书</td><td>任意</td><td></td><td>无需验证</td><td>测试环境、内部网络</td><td>免费</td></tr>
</tbody></table>
<hr />
<p><strong>Done.</strong></p>
</div>
<div class="pagination">
<div class="pagination__title">
<span class="pagination__title-h">Thanks for reading! Read other posts?</span>
<hr />
</div>
<div class="pagination__buttons">
<span class="button previous">
<a href="https://blog.dich.bid/network-isps/">
<span class="button__icon"></span>&nbsp;
<span class="button__text">网络艺术:国内&#x2F;国际骨干ISP线路整理</span>
</a>
</span>
<span class="button next">
<a href="https://blog.dich.bid/network-cdn/">
<span class="button__text">网络艺术:CDN技术与应用</span>&nbsp;
<span class="button__icon"></span>
</a>
</span>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="footer__inner">
<div class="copyright">
<span>©
2025
Dichgrem</span>
<span class="copyright-theme">
<span class="copyright-theme-sep"> :: CC BY-SA 4.0 :: A friend comes from distant lands</span>
</a>
</span>
</div>
</div>
</footer>
</div>
</body>
</html>