in CredentialProvider.Microsoft/Util/CertificateUtil.cs [48:89]
public static X509Certificate2 GetCertificateByFilePath(ILogger logger, string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
logger.Info(message: Resources.InvalidCertificateInput);
return null;
}
try
{
var fileType = Path.GetExtension(filePath);
X509Certificate2 certificate;
switch (fileType)
{
case ".pfx":
certificate = new X509Certificate2(filePath);
break;
case ".pem":
#if NET6_0_OR_GREATER
certificate= X509Certificate2.CreateFromPemFile(filePath);
break;
#endif
throw new NotSupportedException(Resources.ClientCertificatePemFilesNotSupported);
default:
throw new NotSupportedException(Resources.ClientCertificateFileTypeNotSupported);
}
if (certificate == null)
{
logger.Verbose(string.Format(Resources.ClientCertificateFilePathNotFound, filePath));
return null;
}
logger.Verbose(string.Format(Resources.ClientCertificateFound, filePath));
return certificate;
}
catch (Exception ex)
{
logger.Error(string.Format(Resources.ClientCertificateError, ex, ex.Message));
return null;
}
}