我正在 macOS 平臺上開發基于 boost::beast 的應用程式,我想知道如何提供客戶端證書來對服務器進行身份驗證?
基本上,在 macOS 中,證書存盤在鑰匙串中,不能匯出(由稱為安全飛地的專用硬體支持,以提高安全性)......
所以我想知道是否有任何回呼適合使用本機 macOS 本機代碼手動簽署服務器質詢,這些本機代碼將質詢發送到鑰匙串/安全飛地進行簽名。
基本上,我正在尋找一個大致具有以下簽名的回呼:
bool validate_client_side_certificate(const std::string& challenge)
所以基本上我做對的不是從檔案中提供證書 私鑰的能力
boost::asio::ssl::context ctx_;
std::string client_cert_ = read_pem_file(client_cert_path);
std::string client_cert_private_key_ = read_pem_file(private_key_path);
ctx_.use_certificate(
boost::asio::buffer(client_cert_.c_str(), client_cert_.length()),
boost::asio::ssl::context::pem);
ctx_.use_private_key(
boost::asio::buffer(client_cert_key_.c_str(), client_cert_key_.length()),
boost::asio::ssl::context::pem);
此流程完美運行,但如果我想使用鑰匙串內的證書(用于加密資料的 macOS 存盤),我無法獲得私鑰,只能獲得參考(因為它受到保護)。
因此,在 macOS 中,我們不能只向 ctx_ 提供私鑰,這樣挑戰將被自動簽名。相反,我們需要獲取在需要客戶端身份驗證時發生的回呼以及質詢......并使用 macOS 本機代碼使用密鑰參考在鑰匙串硬體內對質詢進行簽名。
uj5u.com熱心網友回復:
看set_verify_callback
這里有例子:
- asio/example/cpp11/ssl/client.cpp
- asio/example/cpp03/ssl/client.cpp
您可以看到它集成在 Beast 中ssl_stream:https ://www.boost.org/doc/libs/1_78_0/libs/beast/doc/html/beast/ref/boost__beast__ssl_stream/set_verify_callback/overload2.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/447157.html
