Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hardcoded Metadata Service BLOB url to allow users to override it #444

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Src/Fido2.AspNet/Fido2NetLibBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IFido2MetadataServiceBuilder AddFileSystemMetadataRepository(this

public static IFido2MetadataServiceBuilder AddConformanceMetadataRepository(
this IFido2MetadataServiceBuilder builder,
HttpClient client = null,
HttpClient client = null,
string origin = "")
{
builder.Services.AddTransient<IMetadataRepository>(provider =>
Expand All @@ -75,9 +75,12 @@ public static IFido2MetadataServiceBuilder AddConformanceMetadataRepository(

public static IFido2MetadataServiceBuilder AddFidoMetadataRepository(this IFido2MetadataServiceBuilder builder, Action<IHttpClientBuilder> clientBuilder = null)
{
var httpClientBuilder = builder.Services.AddHttpClient(nameof(Fido2MetadataServiceRepository));
var httpClientBuilder = builder.Services.AddHttpClient(nameof(Fido2MetadataServiceRepository), client =>
{
client.BaseAddress = new Uri("https://mds3.fidoalliance.org/");
});

if (clientBuilder != null)
if (clientBuilder != null)
clientBuilder(httpClientBuilder);

builder.Services.AddTransient<IMetadataRepository, Fido2MetadataServiceRepository>();
Expand Down
19 changes: 3 additions & 16 deletions Src/Fido2/Metadata/Fido2MetadataServiceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public sealed class Fido2MetadataServiceRepository : IMetadataRepository
"Mx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7rkpeDMdmztcpH"u8 +
"WD9f"u8;

private readonly string _blobUrl = "https://mds3.fidoalliance.org/";
private readonly IHttpClientFactory _httpClientFactory;

public Fido2MetadataServiceRepository(IHttpClientFactory httpClientFactory)
Expand All @@ -57,23 +56,10 @@ public async Task<MetadataBLOBPayload> GetBLOBAsync(CancellationToken cancellati
}

private async Task<string> GetRawBlobAsync(CancellationToken cancellationToken)
{
var url = _blobUrl;
return await DownloadStringAsync(url, cancellationToken);
}

private async Task<string> DownloadStringAsync(string url, CancellationToken cancellationToken)
{
return await _httpClientFactory
.CreateClient(nameof(Fido2MetadataServiceRepository))
.GetStringAsync(url, cancellationToken);
}

private async Task<byte[]> DownloadDataAsync(string url, CancellationToken cancellationToken)
{
return await _httpClientFactory
.CreateClient(nameof(Fido2MetadataServiceRepository))
.GetByteArrayAsync(url, cancellationToken);
.GetStringAsync("/", cancellationToken);
}

private async Task<MetadataBLOBPayload> DeserializeAndValidateBlobAsync(string rawBLOBJwt, CancellationToken cancellationToken)
Expand Down Expand Up @@ -174,7 +160,8 @@ private async Task<MetadataBLOBPayload> DeserializeAndValidateBlobAsync(string r
if (element.Certificate.Issuer != element.Certificate.Subject)
{
var cdp = CryptoUtils.CDPFromCertificateExts(element.Certificate.Extensions);
var crlFile = await DownloadDataAsync(cdp, cancellationToken);
using var client = _httpClientFactory.CreateClient();
var crlFile = await client.GetByteArrayAsync(cdp, cancellationToken);
if (CryptoUtils.IsCertInCRL(crlFile, element.Certificate))
throw new Fido2VerificationException($"Cert {element.Certificate.Subject} found in CRL {cdp}");
}
Expand Down