<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>openssl &#8211; wqh博客</title>
	<atom:link href="https://wangqianhong.com/tag/openssl/feed/" rel="self" type="application/rss+xml" />
	<link>https://wangqianhong.com</link>
	<description>和而不同</description>
	<lastBuildDate>Wed, 25 Sep 2024 12:51:07 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wangqianhong.com/wp-content/uploads/2020/09/cropped-1-1-1-32x32.png</url>
	<title>openssl &#8211; wqh博客</title>
	<link>https://wangqianhong.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>OpenSSL 自签名证书</title>
		<link>https://wangqianhong.com/2022/08/openssl-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/</link>
					<comments>https://wangqianhong.com/2022/08/openssl-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Thu, 25 Aug 2022 12:47:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[openssl]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=3705</guid>

					<description><![CDATA[<p>使用 OpenSSL 生成 TLS 自签名证书和自签名 CA 通常包括以下几个步骤： 生成自签名 C&#8230; <a href="https://wangqianhong.com/2022/08/openssl-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">OpenSSL 自签名证书</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/08/openssl-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/">OpenSSL 自签名证书</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>使用 OpenSSL 生成 TLS 自签名证书和自签名 CA 通常包括以下几个步骤：</p>



<h3>生成自签名 CA 证书</h3>



<p>首先，生成 CA 私钥和 CA 自签名证书。CA 证书用于签署 TLS 服务器证书</p>



<pre class="wp-block-code"><code>openssl genrsa -out ca.key 4096</code></pre>



<p>这将生成一个 4096 位的 RSA 私钥并保存为 <code>ca.key</code> 文件。</p>



<pre class="wp-block-code"><code>openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.crt</code></pre>



<ul><li>-x509 表示生成自签名证书</li><li>-new 表示创建一个新的证书请求</li><li>-nodes 表示不对私钥加密</li><li>-key ca.key 表示使用之前生成的 ca.key 私钥</li><li>-days 3650 表示证书有效期为 3650 天（约 10 年）</li><li>-out ca.crt 表示将证书保存为 ca.crt</li></ul>



<p>提示填写证书的信息（如国家代码、组织名、域名等），这些信息会包含在 CA 证书中。</p>



<h3>生成服务器的私钥和证书请求 (CSR)</h3>



<p>接下来，为服务器生成私钥和证书签名请求 (CSR)：</p>



<pre class="wp-block-code"><code>openssl genrsa -out server.key 2048</code></pre>



<p>这将生成一个 2048 位的 RSA 私钥并保存为 server.key。</p>



<pre class="wp-block-code"><code>openssl req -new -key server.key -out server.csr</code></pre>



<ul><li>-new 表示生成一个新的证书请求</li><li>-key server.key 表示使用刚才生成的服务器私钥</li><li>-out server.csr 表示生成的 CSR 文件名为 server.csr</li></ul>



<p>在此过程中，需要填写有关服务器的信息，最重要的是 Common Name (CN)，应填写服务器域名或 IP 地址。</p>



<h3>用 CA 签署服务器证书</h3>



<p>现在，使用之前生成的自签名 CA 证书和私钥来签署服务器证书请求。</p>



<pre class="wp-block-code"><code>openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 825 -sha256</code></pre>



<ul><li>-req 表示基于证书请求 (CSR) 生成证书</li><li>-CA ca.crt 表示使用 CA 证书来签署服务器证书</li><li>-CAkey ca.key 表示使用 CA 的私钥来签署证书</li><li>-CAcreateserial 表示自动生成一个 ca.srl 文件，保存 CA 的序列号</li><li>-out server.crt 表示将生成的服务器证书保存为 server.crt</li><li>-days 825 表示证书的有效期为 825 天</li><li>-sha256 表示使用 SHA256 进行签名</li></ul>



<h3>验证生成的证书</h3>



<p>可以使用以下命令来检查生成的证书是否有效：</p>



<pre class="wp-block-code"><code>openssl x509 -in server.crt -text -noout</code></pre>



<p>这将显示 server.crt 的详细信息。</p>



<h3>配置 TLS</h3>



<ul><li>ca.crt 是自签名 CA 证书，可以分发给客户端，供其信任</li><li>server.crt 是服务器证书，用于配置在你的服务器上</li><li>server.key 是服务器私钥，用于安全连接</li></ul>



<p>你可以将这些文件用于设置 HTTPS 服务器或其他 TLS 应用。</p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/08/openssl-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/">OpenSSL 自签名证书</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2022/08/openssl-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
