Module: AlexaVerifier::CertificateStore

Defined in:
lib/alexa_verifier/certificate_store.rb

Overview

A module used to download, cache and serve certificates from our requests.

Since:

  • 0.1

Constant Summary collapse

CERTIFICATE_CACHE_TIME =

30 minutes

Since:

  • 0.1

1800
CERTIFICATE_SEPARATOR =

Since:

  • 0.1

'-----BEGIN CERTIFICATE-----'.freeze

Class Method Summary collapse

Class Method Details

.delete(uri) ⇒ nil|Hash

Given a certificate uri, remove the certificate from our store.

Since:

  • 0.1



35
36
37
38
39
# File 'lib/alexa_verifier/certificate_store.rb', line 35

def delete(uri)
  store

  @store.delete(uri)
end

.fetch(uri) ⇒ OpenSSL::X509::Certificate+

Given a certificate uri, either download the certificate and chain, or load them from our certificate store.

Since:

  • 0.1



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/alexa_verifier/certificate_store.rb', line 14

def fetch(uri)
  store

  if cache_valid?(@store[uri])
    certificate = @store[uri][:certificate]
    chain = @store[uri][:chain]
  else
    chain = generate_certificate_chain_from_data(download_certificate(uri))
    certificate = chain.delete_at(0)

    @store[uri] = { timestamp: Time.now, certificate: certificate, chain: chain }
  end

  [certificate, chain]
end

.storeHash

Returns a copy of our certificate store

Since:

  • 0.1



44
45
46
# File 'lib/alexa_verifier/certificate_store.rb', line 44

def store
  @store ||= {}
end