Open PJ-Kowalski opened 1 year ago
Hi there!
Here are some suggestions for your questions:
Azure WebApp Service has limited support for client certificate authentication. You'll need to enable it manually in the portal or through Azure CLI:
az webapp update -g <resource_group> -n <app_name> --set clientCertEnabled=true
Then, in your Blazor app, you can check the X-ARR-ClientCert header for the client certificate. Based on the certificate, you can decide whether to allow or reject the connection. Please note that client certificate authentication is available only for the Basic or higher pricing tiers.
To configure Kestrel for client certificate authentication, you can use the KestrelServerOptions like this:
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.ConfigureHttpsDefaults(httpsOptions =>
{
httpsOptions.ServerCertificate = GetServerCertificateFromFile();
httpsOptions.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
httpsOptions.CheckCertificateRevocation = false;
});
})
.Build();
This will enforce client certificates for incoming connections.
Yes, you can use certificates generated with OpenSSL. Just make sure you generate a proper certificate chain with a root certificate, intermediate certificate(s), and an end-entity certificate.
openssl genrsa -out rootCA.key 4096
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 365 -sha256
openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt -certfile rootCA.pem
This will create a server.pfx file, which you can use in your .NET application.
public static X509Certificate2 GetServerCertificateFromFile()
{
string pfxPath = Path.Combine("Certificates", "server.pfx");
string pfxPassword = "your_pfx_password";
X509Certificate2 certificate = new X509Certificate2(pfxPath, pfxPassword, X509KeyStorageFlags.Exportable);
return certificate;
}
Remember to replace your_pfx_password with the password you set when exporting the PFX file (and make sure to keep it secure).
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.ConfigureHttpsDefaults(httpsOptions =>
{
httpsOptions.ServerCertificate = GetServerCertificateFromFile();
httpsOptions.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
httpsOptions.CheckCertificateRevocation = false;
});
})
.Build();
This should enable your application to use the certificates generated with OpenSSL for securing the server. Keep in mind that client certificates should also be generated and signed by a trusted CA (either your own root CA or a public one).
I hope this helps! If you have any further questions or need more clarification, please let me know.
Describe your question
I create .Net Blazor App that works as MQTT broker (TCP and WS). I host this App on Azure WebApp Service. Due to fact on WebApp i can use only port 80, only Web Sockets work. Broker working fine, but i lake to make connection secure by certificates, to allow connection only for client with valid certificate
in program.cs i add following
but i can still connect with any client, and without TSL encryption (if i check ignore certificate error in client) so, my question is:
Which project is your question related to?