protected virtual async Task LoadTocEntryStatement( IMetadataRepository repository, MetadataBLOBPayload blob, MetadataBLOBPayloadEntry entry, DateTime?cacheUntil = null) { if (entry.AaGuid != null && !_entries.ContainsKey(Guid.Parse(entry.AaGuid))) { var entryAaGuid = Guid.Parse(entry.AaGuid); var cacheKey = GetEntryCacheKey(repository, entryAaGuid); var cachedEntry = await _cache.GetStringAsync(cacheKey); if (cachedEntry != null) { var statement = JsonSerializer.Deserialize <MetadataStatement>(cachedEntry); if (!string.IsNullOrWhiteSpace(statement.AaGuid)) { var aaGuid = Guid.Parse(statement.AaGuid); _metadataStatements.TryAdd(aaGuid, statement); _entries.TryAdd(aaGuid, entry); } } else { _log?.LogInformation("Entry for {0} {1} not cached so loading from MDS...", entry.AaGuid, entry.MetadataStatement?.Description ?? entry.StatusReports?.FirstOrDefault().CertificationDescriptor ?? "(unknown)"); try { if (!string.IsNullOrWhiteSpace(entry.AaGuid)) { var statementJson = JsonSerializer.Serialize(entry.MetadataStatement, new JsonSerializerOptions { WriteIndented = true }); _log?.LogDebug("{0}:{1}\n{2}", entry.AaGuid, entry.MetadataStatement.Description, statementJson); var aaGuid = Guid.Parse(entry.AaGuid); _metadataStatements.TryAdd(aaGuid, entry.MetadataStatement); _entries.TryAdd(aaGuid, entry); if (cacheUntil.HasValue) { await _cache.SetStringAsync(cacheKey, statementJson, new DistributedCacheEntryOptions { AbsoluteExpiration = cacheUntil }); } } } catch (Exception ex) { _log?.LogError(ex, "Error getting MetadataStatement from {0} for AAGUID '{1}' ", repository.GetType().Name, entry.AaGuid); throw; } } } }
public async Task <MetadataBLOBPayload> GetBLOBAsync(CancellationToken cancellationToken = default) { if (Directory.Exists(_path)) { foreach (var filename in Directory.GetFiles(_path)) { await using var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); var statement = await JsonSerializer.DeserializeAsync <MetadataStatement>(fileStream, cancellationToken : cancellationToken); _ = statement ?? throw new NullReferenceException(nameof(statement)); var conformanceEntry = new MetadataBLOBPayloadEntry { AaGuid = statement.AaGuid, MetadataStatement = statement, StatusReports = new StatusReport[] { new StatusReport { Status = AuthenticatorStatus.NOT_FIDO_CERTIFIED } } }; if (null != conformanceEntry.AaGuid) { _entries.Add(new Guid(conformanceEntry.AaGuid), conformanceEntry); } } } _blob = new MetadataBLOBPayload() { Entries = _entries.Select(o => o.Value).ToArray(), NextUpdate = "", //Empty means it won't get cached LegalHeader = "Local FAKE", Number = 1 }; return(_blob); }
public Task <MetadataStatement?> GetMetadataStatementAsync(MetadataBLOBPayload blob, MetadataBLOBPayloadEntry entry, CancellationToken cancellationToken = default) { return(Task.FromResult <MetadataStatement?>(entry.MetadataStatement)); }
public async Task <MetadataStatement?> GetMetadataStatementAsync(MetadataBLOBPayload blob, MetadataBLOBPayloadEntry entry, CancellationToken cancellationToken = default) { if (_blob is null) { await GetBLOBAsync(cancellationToken); } if (!string.IsNullOrEmpty(entry.AaGuid) && Guid.TryParse(entry.AaGuid, out Guid parsedAaGuid)) { if (_entries.ContainsKey(parsedAaGuid)) { return(_entries[parsedAaGuid].MetadataStatement); } } return(null); }
protected virtual async Task LoadEntryStatementAsync(IMetadataRepository repository, MetadataBLOBPayload blob, MetadataBLOBPayloadEntry entry, CancellationToken cancellationToken) { if (entry.AaGuid != null) { var statement = await repository.GetMetadataStatementAsync(blob, entry, cancellationToken); if (!string.IsNullOrWhiteSpace(statement?.AaGuid)) { _metadataStatements.TryAdd(Guid.Parse(statement.AaGuid), statement); } } }