0

I am trying to run the application using IP address instead of localhost on https like https://192.1638.2.1:5001/index.html.

What I have done:

  1. I have created a self-signed certificate using below power shell code.
New-SelfSignedCertificate -CertStoreLocation "cert:\LocalMachine\My"  -dnsname "192.168.2.1" -NotAfter (Get-Date).AddYears(10) -FriendlyName "SS_192_168_2_1" -KeyUsageProperty All -KeyUsage CertSign, CRLSign, DigitalSignature


Thumbprint                                Subject
----------                                -------
ABE394F15852C9389655F3EBC111FCE624D43479  CN=192.168.2.1


$mypwd = ConvertTo-SecureString -String "SS123" -Force -AsPlainText
Get-ChildItem -Path cert:\localMachine\my\ABE394F15852C9389655F3EBC111FCE624D43479 | Export-PfxCertificate -FilePath "D:\Certificates\SS_192_168_2_1.pfx" -Password $mypwd

  1. Added SS_192_168_2_1.pfx to certificate store in Trusted Root Certificate Authority of Current User. While adding this a popup came asking for password setup and have entered a new password and got saved warning popup. enter image description here

  2. Configured .NET core web API app to use this file as server certificate.


    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }
    
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
                webBuilder.ConfigureKestrel(options =>
                {
                    options.ConfigureEndpointDefaults(listenOptions =>
                    {
                        // Loads the certificate (a must-have)
                        listenOptions.UseHttps(@"D:\Certificates\SS_192_168_2_1.pfx", "SS123");
                    });

                    options.ConfigureHttpsDefaults(o =>
                    {
                        o.ClientCertificateMode = ClientCertificateMode.NoCertificate;
                    });
                });
            });
    }

Issue:

  1. Still the browser shows Not Secure and post man shows as Self signed certificate whereas localhost is showing Secure. What is that I am missing here??
Nithin B
  • 601
  • 1
  • 9
  • 26
  • Try to configure your server to require certificates:`o.ClientCertificateMode = ClientCertificateMode.RequireCertificate;` Besides, you can have a look at:[Securing a private IP address (https certificate)](https://stackoverflow.com/questions/38125490/securing-a-private-ip-address-https-certificate) – Qing Guo Dec 02 '22 at 07:54
  • @QingGuo `o.ClientCertificateMode = ClientCertificateMode.RequireCertificate;` is used to where server needs client certificate to authenticate client. But here browser is checking if server is genuine using server certificate. – Nithin B Dec 09 '22 at 16:18

0 Answers0