Class: FidoMetadata::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/fido_metadata/store.rb

Constant Summary collapse

METADATA_ENDPOINT =
URI("https://mds2.fidoalliance.org/")
TOC_CACHE_KEY =
"metadata_toc"
STATEMENT_CACHE_KEY =
"statement_%s"

Instance Method Summary collapse

Instance Method Details

#fetch_entry(aaguid: nil, attestation_certificate_key_id: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fido_metadata/store.rb', line 26

def fetch_entry(aaguid: nil, attestation_certificate_key_id: nil)
  verify_arguments(aaguid: aaguid, attestation_certificate_key_id: attestation_certificate_key_id)

  if aaguid
    table_of_contents.entries.detect { |entry| entry.aaguid == aaguid }
  elsif attestation_certificate_key_id
    table_of_contents.entries.detect do |entry|
      entry.attestation_certificate_key_identifiers&.detect do |id|
        id == attestation_certificate_key_id
      end
    end
  end
end

#fetch_statement(aaguid: nil, attestation_certificate_key_id: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fido_metadata/store.rb', line 40

def fetch_statement(aaguid: nil, attestation_certificate_key_id: nil)
  verify_arguments(aaguid: aaguid, attestation_certificate_key_id: attestation_certificate_key_id)

  key = STATEMENT_CACHE_KEY % (aaguid || attestation_certificate_key_id)
  statement = cache_backend.read(key)
  return statement if statement

  entry = if aaguid
            fetch_entry(aaguid: aaguid)
          elsif attestation_certificate_key_id
            fetch_entry(attestation_certificate_key_id: attestation_certificate_key_id)
          end
  return unless entry

  json = client.download_entry(entry.url, expected_hash: entry.hash)
  statement = FidoMetadata::Statement.from_json(json)
  cache_backend.write(
    key,
    statement,
    expires_in: table_of_contents.expires_in,
    race_condition_ttl: race_condition_ttl
  )
  statement
end

#table_of_contentsObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fido_metadata/store.rb', line 13

def table_of_contents
  @table_of_contents ||= begin
    key = TOC_CACHE_KEY
    toc = cache_backend.read(key)
    return toc if toc

    json = client.download_toc(METADATA_ENDPOINT)
    toc = FidoMetadata::TableOfContents.from_json(json)
    cache_backend.write(key, toc, expires_in: toc.expires_in, race_condition_ttl: race_condition_ttl)
    toc
  end
end