H
H
Hyppoprogramm2021-11-20 17:10:39
C++ / C#
Hyppoprogramm, 2021-11-20 17:10:39

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"

This is the server startup code:
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());
}

And this is the code for customer service:
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");

SSL certificate is correct, I checked. Tried to run as administrator. Nothing works.
Help me please!
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hyppoprogramm, 2021-11-21
@Hyppoprogramm

The problem turned out to be in C# itself.
Should have been replaced

certificate = X509Certificate2.CreateFromPemFile("www/certificate/fullchain.pem", "www/certificate/privkey.pem");

on the
certificate = new X509Certificate2(X509Certificate2.CreateFromPemFile("www/certificate/fullchain.pem", "www/certificate/privkey.pem").Export("X509ContentType.Pkcs12"));

V
Vitaly Karasik, 2021-11-20
@vitaly_il1

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 question

Ask a Question

731 491 924 answers to any question