Answer the question
In order to leave comments, you need to log in
Why does an error occur during HTTPS authentication?
Hello!
I have a custom C# HTTPS server and when I connect to it I get the following error:
System.ComponentModel.Win32Exception: "Credential missing from security package"
certificate = X509Certificate2.CreateFromPemFile("www/certificate/fullchain.pem", "www/certificate/privkey.pem");
server = new TcpListener(IPAddress.Parse("192.168.1.200"), 40000);
server.Start();
while (true)
{
new Thread(new ParameterizedThreadStart(ServeClient)).Start(server.AcceptTcpClient());
}
SslStream stream = new SslStream(client.GetStream(), false);
stream.AuthenticateAsServer(certificate, false, true); // тут получаю ошибку
string HTTPREQUEST = ReadMessage(stream, client);
var match = Regex.Match(HTTPREQUEST, "^([^ ]+) ([^ ]+)");
string METHOD = match.Groups[1].Value;
string PATH = match.Groups[2].Value;
Console.WriteLine("METHOD=" + METHOD + "; PATH=" + PATH + "\n" + HTTPREQUEST + "\n");
Answer the question
In order to leave comments, you need to log in
The problem turned out to be in C# itself.
Should have been replaced
certificate = X509Certificate2.CreateFromPemFile("www/certificate/fullchain.pem", "www/certificate/privkey.pem");
certificate = new X509Certificate2(X509Certificate2.CreateFromPemFile("www/certificate/fullchain.pem", "www/certificate/privkey.pem").Export("X509ContentType.Pkcs12"));
Check https://www.ssllabs.com/ssltest/index.html or another validator.
One possibility is that you (on the client's machine) do not have the appropriate CA cert.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question