Summary

Class:WireMock.HttpsCertificate.ClientCertificateHelper
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\HttpsCertificate\ClientCertificateHelper.cs
Covered lines:0
Uncovered lines:17
Coverable lines:17
Total lines:41
Line coverage:0%
Branch coverage:0%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
GetCertificate(...)3400

File(s)

C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\HttpsCertificate\ClientCertificateHelper.cs

#LineLine coverage
 1using System;
 2using System.Security.Cryptography.X509Certificates;
 3
 4namespace WireMock.HttpsCertificate
 5{
 6    internal static class ClientCertificateHelper
 7    {
 8        public static X509Certificate2 GetCertificate(string thumbprintOrSubjectName)
 09        {
 010            X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
 11            try
 012            {
 13                //Certificate must be in the local machine store
 014                certStore.Open(OpenFlags.ReadOnly);
 15
 16                //Attempt to find by thumbprint first
 017                var matchingCertificates = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprintOrSubjec
 018                 if (matchingCertificates.Count == 0)
 019                {
 20                    //Fallback to subject name
 021                    matchingCertificates = certStore.Certificates.Find(X509FindType.FindBySubjectName, thumbprintOrSubje
 022                     if (matchingCertificates.Count == 0)
 023                    {
 24                        // No certificates matched the search criteria.
 025                        throw new Exception($"No certificate found with Thumbprint or SubjectName '{thumbprintOrSubjectN
 26                    }
 027                }
 28                // Use the first matching certificate.
 029                return matchingCertificates[0];
 30            }
 31            finally
 032            {
 33#if NETSTANDARD || NET46
 34                certStore.Dispose();
 35#else
 036                certStore.Close();
 37#endif
 038            }
 039        }
 40    }
 41}

Methods/Properties

GetCertificate(System.String)