openSSL 自發憑證
簡介
以下範例中,A為傳送資料的人,B為接收資料的人,C為試圖攔截資料的人
-
對稱式加密(Symmetric Encryption):傳送方與接收方使用同一把金鑰,傳送時使用這把密鑰加密,接收時使用這把密鑰解密。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
優點:計算量小,因此加密速度快
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
缺點:當金鑰被知道後,其他人便可以透過金鑰輕鬆破譯加密訊息
<流程>
傳送者A(server)
與接收者B(browser)
先進行金鑰的握手(Handshake),讓雙方知道金鑰
- A將要傳資料的明文用金鑰加密
- B將收到的密文用金鑰解密
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
非對稱式加密(Asymmetric Encryption):每個使用者都擁有一份私鑰(Private key)、公鑰(Public key)。私鑰本人自行留存,公鑰公開發布發給其他人,私鑰、公鑰皆可以加密或解密。當A傳送檔案給B時,A先獲得B發布的公鑰將檔案加密,傳送給B後B再用私鑰解密,即使中間被C竊取道檔案,沒有B的私鑰也無法閱讀。(當A將檔案加密後,若原檔案遺失,沒有B的私鑰,A也無法透過密文得知原文)
<流程>
- A先使用B的公鑰將要傳送的明文加密
- B獲得密文後使用自己的私鑰解密
- 同時為確保傳送者身分不是假冒的,A要將數位簽章用自己的私鑰加密發給B
- B收到加密的數位簽章後用A的公鑰解密
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
ssl安全協議(Secure Socket Layer):
讓web application能夠加密傳輸。
測試時可使用自簽憑證,若是要等第三方簽發有效憑證,很耗時。
主要功能:
- 加密解密在網路中傳輸的資料包,同時保護這些資料不被修改和偽造。
- 驗證網路對話中雙方的身份。
-
數位憑證認證機構CA(Certificate Authority):權威單位發給A(個人或組織)一對公鑰和私鑰,並對外宣稱此公鑰確實代表A本人。CA除了負責發行數位憑證外,也需隨時提供使用者查詢數位憑證真偽的責任。
-
數位簽章(Digital Signature):當A透過自己發布的公鑰傳送檔案給B,B要如何判斷檔案真的是A傳過來,而不是C假冒A傳送病毒檔?此時A使用他的私鑰加密數位簽章的明文並傳給B,B透過A發布的公鑰即可解密數位簽章,由於私鑰只由該使用者自己持有,故可以肯定該檔案必定出自於該使用者,主要用於陌生環境與陌生人溝通。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
X509:國際標準證書結構
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
數位簽章與驗簽流程(CA 與 需要簽章的server之間)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
簽名
- CA機構對要簽屬的資料(傳送者提供的Data)進行雜湊運算生成摘要
- CA用CA的私鑰將結果加密形成簽章
- 將憑證(憑證有效期限、發行者、公鑰…等資訊)與簽章形成數位簽章
驗簽
- 接收者將數位簽證中資料進行雜湊運算得雜湊值H
- 簽章用CA的公鑰解密後得雜湊值H'
- 若H=H',表示此數位簽證有效
ssl常用語法
rsa
:對密鑰進行管理,如從私鑰提取公鑰、查看密鑰信息
req
:CSR 文件的生成、查看、驗證、自簽名等功能
x509
:證書處理功能,顯示憑證的內容,轉換其格式,給CSR簽名…等等
openssl設定實例(網頁伺服器獲得憑證)
rootCA
– 所有網站憑證的源頭,rootCA自身的憑證就叫根憑證(root certificate)。本次範例為CA伺服器,正式環境為第三方機構,測試時由本機擔任
hostCA
– 本次範例為提供自發簽憑證的CA
CSR (Certificate Signing Request)
– 憑證請求檔,檔名使用域名較好判別。CA要完成簽屬但發送者的私鑰不能交給其他人時,就要透過CSR,內容包括發送者公鑰、關於公司/個人資料的文件。
CRT
– 憑證格式
PEM or CRT
– 中繼憑證(intermediate certificate)格式
1.產生rootCA私鑰
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
2.用設定檔req.conf及ca.key產rootCA 憑證ca.crt
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
3.檢查剛產生的憑證ca.crt
4.host產私鑰host.key
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
5.host產生憑證申請檔host.csr,要交給CA伺服器產生對應的憑證檔用
6.host產生自簽憑證檔host.crt (#這一步給第三方或組織的rootCA執行就不是自簽憑證,而是實際對外網頁服務)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7.檢查剛產生的憑證host.crt
參考連結
基本概念
非對稱式加密wiki
https連線圖解
數位簽證詳解
數位簽證詳解(英文)
密碼學原理
常用ssl指令
ssl命令詳解
rsa參數詳解
申請ssl過程
根憑證解釋