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:42
Line coverage:0%
Branch coverage:0%

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Security.Cryptography.X509Certificates;
 4
 5namespace WireMock.HttpsCertificate
 6{
 7    internal static class ClientCertificateHelper
 8    {
 9        public static X509Certificate2 GetCertificate(string thumbprintOrSubjectName)
 010        {
 011            X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
 12            try
 013            {
 14                // Certificate must be in the local machine store
 015                certStore.Open(OpenFlags.ReadOnly);
 16
 17                // Attempt to find by thumbprint first
 018                var matchingCertificates = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprintOrSubjec
 019                if (matchingCertificates.Count == 0)
 020                {
 21                    // Fallback to subject name
 022                    matchingCertificates = certStore.Certificates.Find(X509FindType.FindBySubjectName, thumbprintOrSubje
 023                    if (matchingCertificates.Count == 0)
 024                    {
 25                        // No certificates matched the search criteria.
 026                        throw new FileNotFoundException("No certificate found with specified Thumbprint or SubjectName."
 27                    }
 028                }
 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)