gpt4 book ai didi

ssl - 无法通过 RestSharp 发送客户端证书

转载 作者:行者123 更新时间:2023-12-04 11:34:28 25 4
gpt4 key购买 nike

我可以访问我的 token 并将其添加到 RestSharp RestClient

//Create rest client.
IRestClient client = new RestClient("https://localhost.fiddler:44300");

var webClientCertificate = GetWebClientCertificate();

//Don't ask why... I'm getting an abiguous ref here.
client.ClientCertificates = new System.Security.Cryptography.X509Certificates.X509Certificate2Collection(){webClientCertificate};

IRestRequest request = new RestRequest("api/get-secure-data", Method.GET);
var response = client.Execute(request);

获取WebClient证书:
public X509Certificate2 GetWebClientCertificate()
{
//Access certificate store
X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certificateStore.Open(OpenFlags.ReadOnly);
var certificateCollection = certificateStore.Certificates.Find(X509FindType.FindBySubjectName, "web-client",false);
var webClientCertificate = certificateCollection[0];
certificateStore.Close();

return webClientCertificate;
}

我得到了证书,我可以看到它已添加到客户端。

服务器代码
    [HttpGet]
[Route("api/get-secure-data")]
[RequireHttps]
public IHttpActionResult GetSecureData()
{
try
{
X509Certificate2 cert = Request.GetClientCertificate(); //returns null
PublicKey clientKey = cert.PublicKey;

return Ok(clientKey);
}
catch (Exception exception)
{
return InternalServerError(exception);
}
}

fiddler 显示没有身份验证头,我错过了什么?

最佳答案

首先,您只需要设置证书本身,集合已经存在,其次,您在使用证书进行签名或身份验证(加密)时无法关闭存储,因为您与上下文断开连接。

关于ssl - 无法通过 RestSharp 发送客户端证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35781191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com