<?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>TWCA SSL Apache &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/twca-ssl-apache/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Tue, 21 May 2024 02:10:18 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>TWCA SSL Apache &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)</title>
		<link>https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/</link>
					<comments>https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Fri, 07 Oct 2022 12:43:49 +0000</pubDate>
				<category><![CDATA[Web Server]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[TWCA 憑證]]></category>
		<category><![CDATA[TWCA SSL Apache]]></category>
		<category><![CDATA[Ubuntu Apache SSL]]></category>
		<category><![CDATA[TWCA CSR]]></category>
		<category><![CDATA[TWCA CER]]></category>
		<category><![CDATA[產生 TWCA CSR]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[Private Key]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[如何生成 CSR]]></category>
		<category><![CDATA[TWCA]]></category>
		<category><![CDATA[如何生成 private key]]></category>
		<category><![CDATA[SSL 憑證申請]]></category>
		<category><![CDATA[CSR]]></category>
		<category><![CDATA[TWCA 憑證申請教學]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=10420</guid>

					<description><![CDATA[<p>因為某些特殊緣故必須要向 TWCA (臺灣網路認證) 申請 SSL 憑證，已經申請好幾次了，每次做都還要去查資料，這篇文章把向 TWCA 申請 SSL 憑證的流程記下來。</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/" data-wpel-link="internal">向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>因為某些特殊緣故必須要向 <a href="https://www.twca.com.tw/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">TWCA<span class="wpel-icon wpel-image wpel-icon-6"></span></a> (臺灣網路認證) 申請 SSL 憑證，已經申請好幾次了，每次做都還要去查資料，這篇文章把向 TWCA 申請 SSL 憑證的流程記下來。</p>



<span id="more-10420"></span>



<p><a href="https://www.twca.com.tw/service_detail/7d08f851-9415-4dd7-92cc-91ee37fb7b69" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">TWCA 官網<span class="wpel-icon wpel-image wpel-icon-6"></span></a>列出申請 SSL 憑證總共有 6 個步驟，接下來小蛙會著重在第 3 步：<strong>上傳 CSR (WEB)</strong> 以及第 6 步：<strong>安裝與設定 1.電子憑證 2.認證標章</strong> (但不會使用認證標章)</p>



<h2 class="wp-block-heading para">申請 TWCA SSL 憑證：上傳 CSR (WEB)</h2>



<h3 class="wp-block-heading para">產生主機 KEY 及 CSR 憑證請求檔</h3>



<p>首先進到 /etc/ssl/ 產生金鑰 (private key)</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cd /etc/ssl/
openssl genrsa -out server.key 2048</pre>



<p>使用這把金鑰產生 CSR 憑證請求檔</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">openssl req -new -key ./server.key -out server.csr

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]: TW (國家縮寫)
State or Province Name (full name) [Some-State]:Taiwan (國家名稱全名)
Locality Name (eg, city) []:Taichung (城市名稱)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Noter (公司名稱) 
Organizational Unit Name (eg, section) []:IT (部門名稱)
Common Name (e.g. server FQDN or YOUR name) []:noter.tw (網域名稱)
Email Address []:noter.tw@gmail.com (電子郵件)

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:Noter (選用的公司名稱)</pre>



<p>2024-05-21 補充，因為每年都要產生一次，有時候忘記 CSR 要輸入的東西，就可以使用以下指令來看查看之前產生 CSR 時填入的資訊</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">openssl req -in example.csr -noout -text</pre>



<h3 class="wp-block-heading para">上傳 CSR</h3>



<p>經過上述步驟後，在 <code>/etc/ssl/</code> 下會多出 <code>server.key</code> 及 <code>server.csr</code>，回到 <a href="https://www.twca.com.tw/service_detail/7d08f851-9415-4dd7-92cc-91ee37fb7b69" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">TWCA 官網<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 第 3 點的描述</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>請將CSR檔案中的內容複製到下方的空欄中，注意複製的範圍應包括「&#8212;&#8211;BEGIN NEW CERTIFICATE REQUEST&#8212;&#8211;」到「&#8212;&#8211;END NEW CERTIFICATE REQUEST&#8212;&#8211;」的宣告文字。</p>
</blockquote>



<p>透過 cat 印出剛剛產生的 CSR</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cat server.csr

-----BEGIN CERTIFICATE REQUEST-----
...
...
...
-----END CERTIFICATE REQUEST-----</pre>



<p>複製「&#8212;&#8211;BEGIN NEW CERTIFICATE REQUEST&#8212;&#8211;」到「&#8212;&#8211;END NEW CERTIFICATE REQUEST&#8212;&#8211;」範圍的文字，貼到 TWCA 官網中點擊繼續</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEUii6S1K0_-GAxZTQ4PT-RTlxjCuLFkpe0VAvFwfpE3q-pmUMS82NLzMZ2EFsIqYzIdmvBthfhNlrBwzdp4ZaPJ_-EO8dD-UrJXL9i3N8OVr6_0InU84JukzuF3U7-NRe6klxRdVJmd6_Im7_qySb_5=w1045-h542-no?authuser=1" alt="TWCA SSL 憑證：上傳 CSR 1" style="width:784px;height:407px" title="向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)"></figure></div>


<p>確認紅框內的資訊後，輸入密碼、選擇驗證網域的方式、及表單編號</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEUqolhtYlj23TU_asHRoGOkYyLZmY0q1f9IvsjnYS55DsJ6EXJ_g8Id2rfakMgph2jwTvRMeYCobOnt9aFObIzIpfaXtEzkp4FkCwmmLJGGqe2-1o80Rk97cSPzuNNHBsDYtGfHbNsTAObyCkZbefFI=w1108-h1023-no?authuser=1" alt="TWCA SSL 憑證：上傳 CSR 2" title="向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)"></figure></div>


<p>點擊繼續後即上傳完成</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEXQAtelMnZH8S-ITRuLhOr_yzNo6nLJJxRRNiIJO5kY_QpojlFzhT28LG7o6d86OqZO_3UsYZhqy6zzmF-VaMOpcD8rSz11S1rDIGYbdjthRH0dahHm_3d5MOAOdGERglUcxgj85jDs9raoXsL5OK2p=w684-h245-no?authuser=1" alt="TWCA SSL 憑證：上傳 CSR 3" style="width:513px;height:184px" title="向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)"></figure></div>


<h3 class="wp-block-heading para">驗證網域所有權</h3>



<p>小蛙這邊使用的是「網站檔案驗證」(上一步選擇的)，收到操作手冊與驗證檔</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEX4VoKr55HSOfIw9uQM_tnFTnwFi66y-mKKKeoMZ7nGDLhSXbn-W7-zYebDhdnOroC_NaWLwg2WgTPrSsC1szr1c3FyAi8pKZpzme3eZ4uCcSxXKtgjjb28m3z-pcRDHLxPsMiJkWQL8fb62ziSOZEi=w944-h664-no?authuser=1" alt="TWCA SSL 憑證：驗證網域" style="width:708px;height:498px" title="向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)"></figure></div>


<p>在網站根目錄建立對應的資料夾及 <code>whois.txt</code> 檔案，並將 email 附件中的 whois.txt 貼上，也可以直接把附件中的檔案解壓縮後，直接上傳到網站根目錄中。例如小蛙的網站根目錄是 <code>/var/www/html/</code> </p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">mkdir -p /var/www/html/.well-known/pki-validation/
vim /var/www/html/.well-known/pki-validation/whois.txt</pre>



<p>完成後確定從 email 給的連結可以看到剛剛的 whois.txt 檔案，即可與 TWCA 聯繫進行下一步。</p>



<h2 class="wp-block-heading para">安裝與設定 1.電子憑證 2.認證標章</h2>



<p>等待 TWCA 審核完成後收到一封 email 及一個壓縮檔，解壓縮後包含我們前面產生的檔案，共有以下</p>



<ol class="my-li bg-darkblue wp-block-list">
<li>server.key 伺服器金鑰</li>



<li>server.csr TWCA CSR 憑證申請檔</li>



<li>root.cer 根憑證</li>



<li>server.cer 伺服器憑證</li>



<li>uca.cer 中繼憑證</li>
</ol>



<p>這邊會用到的為 1, 4, 5 三個檔案，如果收到的檔案是 <code>uca_1.cer</code> 跟 <code>uca_2.cer</code>，可先透過 <code>cat uca_2.cer uca_1.cer &gt; uca.cer</code> 將檔案合併成一個。</p>



<p>以小蛙自己的環境 Apache2.4 為例，首先複製一份預設的檔案出來改</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default-le-ssl.conf
vim /etc/apache2/sites-available/000-default-le-ssl.conf</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="ini" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;IfModule mod_ssl.c>
&lt;VirtualHost *:443>
        ServerName 改成 TWCA 申請 SSL 的網址
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Include /etc/letsencrypt/options-ssl-apache.conf  # 這個是因為小蛙有使用 letsencrypt
        SSLCertificateFile /etc/ssl/server.cer            # 加上這個
        SSLCertificateKeyFile /etc/ssl/server.key         # 加上這個
        SSLCertificateChainFile /etc/ssl/uca.cer          # 加上這個
&lt;/VirtualHost>
&lt;/IfModule></pre>



<p>儲存後啟用該站點，檢查沒問題後重起 apache 就完成囉！</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">a2ensite 000-default-le-ssl.conf
apache2ctl configtest
Syntax OK
service apache2 graceful</pre>



<p><strong>增加安全性系列：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/10420/向-twca-申請-ssl-憑證-ubuntu-apache/" data-wpel-link="internal">向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)</a></li><li><a href="https://noter.tw/34/ubuntu-16-04-%E5%8D%87%E7%B4%9A-phpmyadmin-%E4%B8%A6%E9%96%8B%E5%95%9F%E4%BA%8C%E9%9A%8E%E6%AE%B5%E9%A9%97%E8%AD%89-2fa/" data-wpel-link="internal">Ubuntu 16.04 升級 phpMyAdmin 並開啟二階段驗證( 2FA )</a></li><li><a href="https://noter.tw/255/ubuntu-16-04-安裝-fail2ban/" data-wpel-link="internal">Ubuntu 16.04 安裝 fail2ban</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/" data-wpel-link="internal">向 TWCA 申請 SSL 憑證 (Ubuntu, Apache)</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/10420/%e5%90%91-twca-%e7%94%b3%e8%ab%8b-ssl-%e6%86%91%e8%ad%89-ubuntu-apache/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
