Existing SSL certificate .pfx and .cert inside Linux container

69 Views Asked by At

My application is in dot net 6 and running on widows server (IIS). Application required few certificates for JWT validation and calling SOAP services. Below is the code as of now to read a certificate form store and read it.

 X509Store store = new(StoreName.My, StoreLocation.CurrentUser); // or LocalMachine
 store.Open(OpenFlags.ReadOnly);
 X509Certificate2Collection certCollection = store.Certificates.Find(
 X509FindType.FindBySubjectName, certificateSubName, false);

 store.Close();
 List<X509SecurityKey> signingKeys = new();
   
 foreach (var cert in certCollection)
 {
     signingKeys.Add(new X509SecurityKey(cert));
 }
 return signingKeys;

Above is working fine.

Now I am trying to containerize (Linux) the api and thinking of putting the SSL certificate inside the container as below (Dockerfile)

COPY cert.pfx /app/cert.pfx 
//used different path like /usr/share/ca-certificates/mozilla

but when I am trying to read the certificate using fist code it's not finding it.

Do I need to add the certificate to the store inside Linux container and then use it?

  X509Certificate2Collection certCollection = store.Certificates.Find(X509FindType.FindBySubjectName, userName, false);
        if (certCollection.Count <= 0)
        {
            X509Certificate2 appCert = new("/app/cert.pfx", "pass");
            certCollection.Add(appCert);
        }

Above also not adding certificate to the store.

What is the right way to doing that. Any link or suggestion will be appricated.

0

There are 0 best solutions below