0

My websocket server is not starting. I cannot connect. But if I run program with admin rights It's working.

            X509Certificate2 certificate = new X509Certificate2(Resource.UZCRYPTO);
            using (X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser))
            {
                store.Open(OpenFlags.ReadWrite);
                if (!store.Certificates.Contains(certificate))
                    store.Add(certificate);
            }

            X509Certificate2 cert = new X509Certificate2(Resource._127_0_0_1, "1", X509KeyStorageFlags.MachineKeySet);
            //WebCoket set
            WebSocketServer wssv = new WebSocketServer(IPAddress.Parse("127.0.0.1"), 4141, true);
            wssv.SslConfiguration.ServerCertificate = new X509Certificate2(cert);
            wssv.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls11 | SslProtocols.Tls12;
            wssv.AddWebSocketService<WebSocketEcho>("/");
            wssv.KeepClean = false;
            wssv.Start();
Clemens
  • 123,504
  • 12
  • 155
  • 268
  • 1
    If you use the WPF tag you don't have a server to begin with. You have a desktop application that wants to act as a server, making changes to the machine that require admin rights. Most malware would like to do the same changes (open up and listen to ports), which is why it's not allowed – Panagiotis Kanavos Apr 11 '22 at 07:53
  • 1
    Worse, your code is forcing the use of weaker SSL algorithms. What are you trying to do? Why does your *desktop* application try to act as a Websocket server? And why hard-code the TLS version instead of letting the OS pick the strongest available, like TLS1.3 on Windows 11? – Panagiotis Kanavos Apr 11 '22 at 07:54

0 Answers0