繁体   English   中英

多个用户一次访问证书文件

[英]Multiple users accessing certificate file at a time

这不是一个问题,但需要澄清。 这是代码。 这些代码所要做的就是将cer文件发送到位于本地驱动器上的httpwebrequest中的服务器。 我的问题是,如果多个用户同时尝试访问该应用程序,将会发生什么。 我的意思是5-10次请求一次读取同一cer。 是否会说cer文件被其他线程锁定以读取/会中断,或者不会因为仅读而被中断而中断?

//You must change the path to point to your .cer file location. 
X509Certificate Cert = X509Certificate.CreateFromCertFile("C:\\mycert.cer");
// Handle any certificate errors on the certificate from the server.
ServicePointManager.CertificatePolicy = new CertPolicy();
// You must change the URL to point to your Web server.
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://YourServer/sample.asp");
Request.ClientCertificates.Add(Cert);
Request.UserAgent = "Client Cert Sample";
Request.Method = "GET";
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
// Print the repsonse headers.
Console.WriteLine("{0}",Response.Headers);
Console.WriteLine();
// Get the certificate data.
StreamReader sr = new StreamReader(Response.GetResponseStream(), Encoding.Default);
int count;
char [] ReadBuf = new char[1024];
do
{
    count = sr.Read(ReadBuf, 0, 1024);
    if (0 != count)
    {
        Console.WriteLine(new string(ReadBuf));
    }

}while(count > 0);

读取操作不会在Windows中锁定文件。

为什么不从用户存储而不是从文件发送证书,并消除这种担忧,如如何使用HttpWebRequest发送客户端证书中描述的第二种方法中所述。 无论如何,您都需要将私钥加载到密钥存储中,所以我真的看不到使用.cer文件中的证书的任何意义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM