0

hi I want to Create X509Certificate To Use in SslStream.AuthenticateAsServer() on windows 10 loopbak. I try to Create Certificate with OpenSsl and Makecert Script but certificates not work. please help me. my Code :

X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                    store.Open(OpenFlags.ReadOnly);

                    RawStringData = RawStringData.Replace("CONNECT ", "GET https://");
                    RawStringData = RawStringData.Replace(":443", "/");
                    RawStringData = RawStringData.Replace("Proxy-Connection", "Connection");
                    RawByteArrayData = Encoding.ASCII.GetBytes(RawStringData);
                    Port = 443;
                    ServerSocket.Connect(HostEntry.AddressList[0], Port);
                    HttpsStream = new SslStream(new NetworkStream(ServerSocket));
                    HttpsStream.AuthenticateAsClient(Host);
                    HttpsStream.Write(RawByteArrayData);
                    int Count = HttpsStream.Read(NewData, 0, NewData.Length);
                    string pfxpath = @"D:\test.pfx";
                    X509Certificate2 cert = new X509Certificate2(File.ReadAllBytes(pfxpath));
                    byte[] pfxData = File.ReadAllBytes(pfxpath);

                    cert = new X509Certificate2(pfxData,"", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

                    X509Certificate x509 = store.Certificates.Find(X509FindType.FindByIssuerName, "localhost", false)[0];
                    ssl = new SslStream(new NetworkStream(A) , false , Verification , null );
                    ssl.AuthenticateAsServer(cert , false, System.Security.Authentication.SslProtocols.Tls, true);
                    ssl.Write(NewData);
ali mahdavi
  • 1
  • 1
  • 4
  • Can you tell us what you have tried so far and how that is failing? – Dragonthoughts Jun 27 '18 at 10:27
  • See my solution at following posting : https://stackoverflow.com/questions/46722997/saml-assertion-in-a-xml-using-c-sharp/46724392 – jdweng Jun 27 '18 at 10:33
  • @Dragonthoughts I create many Certificate with Openssl and makecert and install them into Trusted root then test it . but any time when program recive to AuthenticateAsServer() , program blocked indefinitely. I want to Send Data to Web Browser. I test all Certificate that in Trusted root in LocalMachine and CurrentUser . – ali mahdavi Jun 27 '18 at 11:27
  • @jdweng I see That but like other test , program blocked indefinitely – ali mahdavi Jun 27 '18 at 11:29

0 Answers0