-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathFromPathCertificateLoader.cs
More file actions
37 lines (32 loc) · 1.39 KB
/
FromPathCertificateLoader.cs
File metadata and controls
37 lines (32 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.Identity.Abstractions;
namespace Microsoft.Identity.Web
{
internal sealed class FromPathCertificateLoader : ICredentialSourceLoader
{
public CredentialSource CredentialSource => CredentialSource.Path;
public Task LoadIfNeededAsync(CredentialDescription credentialDescription, CredentialSourceLoaderParameters? _)
{
credentialDescription.Certificate = LoadFromPath(
credentialDescription.CertificateDiskPath!,
credentialDescription.CertificatePassword!);
credentialDescription.CachedValue = credentialDescription.Certificate;
return Task.CompletedTask;
}
private static X509Certificate2 LoadFromPath(
string certificateFileName,
string? password = null)
{
X509KeyStorageFlags x509KeyStorageFlags = CertificateLoaderHelper.DetermineX509KeyStorageFlag();
#pragma warning disable SYSLIB0057 // Type or member is obsolete
return new X509Certificate2(
certificateFileName,
password,
x509KeyStorageFlags);
#pragma warning restore SYSLIB0057 // Type or member is obsolete
}
}
}