2017年9月21日 星期四

[研究] SQL Server 2016使用 SSL 加密連線

[研究] SQL Server 2016使用 SSL 加密連線

2017-09-21

(一) 建立 SQL Server 2016 用的 SSL 憑證

[研究] makecert.exe 憑證建立工具 安裝
http://shaurong.blogspot.tw/2017/07/makecertexe.html



SQL Server 使用的 SSL 憑證,必須使用 makecert.exe 去建立,而且有一定的規範,用 IIS 去建立的自我簽署憑證是不能用的。

makecert -r -pe -n "CN=FQDN名稱或主機名稱" -e 01/01/2036 -eku 1.3.6.1.5.5.7.3.1 -ss my -len 2048 -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12

其中
-e : 憑證結束日期,可變更
-eku: 指定伺服器驗證(1.3.6.1.5.5.7.3.1),此為固定值
-n: fully qualified domain name (FQDN)
-sp: 加密library




(二) 設定啟動 SQL Server 的帳號,也有讀取此憑證的權限







(下圖) 變更 or 確認憑證授權情況

PS:如果 Web.Config 那邊變更後無法正常運作,憑證可能要拷貝一份到「受信任的根憑證授權單位」


(下圖) 要去找一下 SQL Server 的啟動帳號是甚麼?
此處按下「進階」按鈕去尋找,會找不到某些特別的帳號



(下圖) 啟動 SQL Server 的帳號是 NT Service\MSSQLServer



(下圖) 名稱自動從 NT Service\MSSQLServer 變成 MSSQLServer,而且有底線 ( 但是手動輸入時,不可以只輸入 MSSQLServer )


(三) 設定 SQLServer 2016 使用 SSL連線






(下圖) 上面如果「重新啟動」成功,會看到 SQL Server 在啟動執行狀態,如果失敗,會看到下面錯誤訊息

(四) SQL Server Management Studio (SSMS) 用 SSL 連線 SQL Server 2016






(五) ASP.NET 網站使用 SSL 加密連線存取 SQL Server 2016

客戶端Web.config連線字串加上;Encrypt=yes

<connectionStrings>
<add name="PlaygroundConnectionString" connectionString="Data Source=(local);Initial Catalog=Playground;Integrated Security=True; Encrypt=yes"
 providerName="System.Data.SqlClient" />
</connectionStrings> 

PS:如果 Web.Config 那邊變更後無法正常運作,Data Source 可能需要改成實際的主機名稱 or FQDN 名稱。

PS:如果 Data Source 原本是 IP,可能要在 hosts 檔案設定 名稱和IP對應,然後設定名稱。

(完)

相關

如何使用 Microsoft 管理主控台來啟用 SSL 加密,SQL Server 執行個體
https://support.microsoft.com/zh-tw/kb/316898

Encrypting Connections to SQL Server 2008 R2
https://technet.microsoft.com/en-us/library/ms189067(v=sql.105).aspx

How to configure SSL encryption in SQL Server 2008 R2
https://www.mssqltips.com/sqlservertip/3299/how-to-configure-ssl-encryption-in-sql-server/

如何啟用SQL Server 2012 的SSL加密
http://caryhsu.blogspot.tw/2012/03/sql-serverssl.html
(SQL Server 2012 和 2014畫面不同)

https://www.ssl.com.tw/Products/ssl-certificate-products/SGCSSL.html
增強型密鑰用法(EKU)就是定義該證書的用途,由一串十進位數字字組成,也稱 Object ID或OID,常見的OID有:伺服器驗證: 1.3.6.1.5.5.7.3.1 (serverAuth),用戶端驗證: 1.3.6.1.5.5.7.3.2 (clientAuth),代碼簽名: 1.3.6.1.5.5.7.3.3 (codeSigning),電子郵件加密: 1.3.6.1.5.5.7.3.4 (emailProtection)等等。

逐步解說:使用受保護的組態加密組態資訊
https://msdn.microsoft.com/zh-tw/library/dtkwfdky(v=vs.100).aspx

加密和解密組態區段
https://msdn.microsoft.com/zh-tw/library/zhhddkxy(v=vs.100).aspx

HOW TO:使用資料來源控制項時保護連接字串
https://msdn.microsoft.com/zh-tw/library/dx0f3cf2(v=vs.80).aspx

ASP.NET 組態概觀
https://msdn.microsoft.com/zh-tw/library/ms178683(v=vs.100).aspx

ASP.NET 組態檔階層架構和繼承
https://msdn.microsoft.com/zh-tw/library/ms178685(v=vs.100).aspx

https://dotblogs.com.tw/rockchang/2014/04/07/144650
http://caryhsu.blogspot.tw/2012/03/sql-serverssl.html

Enabling Certificate for SSL on a SQL Server(利用憑證啟動SQL SSL加密連線)
https://dotblogs.com.tw/rockchang/2014/04/07/144650

如何使用 Microsoft Management Console (MMC) 針對 SQL Server 實例啟用 SSL 加密
https://knowledge.symantec.com/tw/support/ssl-certificates-support/index?vproductcat=V_C_S&vdomain=VERISIGN_COM_TW&page=content&id=SO11837&viewlocale=zh_TW&locale=zh_TW&redirected=true

SQL2012 SSL加密連線
http://hoolihome.blogspot.tw/2013/03/sql2012-ssl.html

沒有留言:

張貼留言