Summary

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

Metrics

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

File(s)

C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\HttpsCertificate\ClientCertificateHelper.cs

#LineLine coverage
 1using System.IO;
 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 FileNotFoundException("No certificate found with specified Thumbprint or SubjectName."
 26                    }
 027                }
 28
 29                // Use the first matching certificate.
 030                return matchingCertificates[0];
 31            }
 32            finally
 033            {
 34#if NETSTANDARD || NET46
 035                certStore.Dispose();
 36#else
 37                certStore.Close();
 38#endif
 039            }
 040        }
 41    }
 42}

Methods/Properties

GetCertificate(System.String)