Class: ShopifyCLI::Theme::DevServer::CertificateManager

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/theme/dev_server/certificate_manager.rb

Constant Summary collapse

ISSUER_EXTENSIONS =
[
  ["subjectKeyIdentifier", "hash", false],
  ["authorityKeyIdentifier", "keyid:always", false],
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, domain_name) ⇒ CertificateManager

Returns a new instance of CertificateManager.



16
17
18
19
# File 'lib/shopify_cli/theme/dev_server/certificate_manager.rb', line 16

def initialize(ctx, domain_name)
  @ctx = ctx
  @domain_name = domain_name
end

Instance Attribute Details

#certificateObject (readonly)

Returns the value of attribute certificate.



9
10
11
# File 'lib/shopify_cli/theme/dev_server/certificate_manager.rb', line 9

def certificate
  @certificate
end

#ctxObject (readonly)

Returns the value of attribute ctx.



9
10
11
# File 'lib/shopify_cli/theme/dev_server/certificate_manager.rb', line 9

def ctx
  @ctx
end

#domain_nameObject (readonly)

Returns the value of attribute domain_name.



9
10
11
# File 'lib/shopify_cli/theme/dev_server/certificate_manager.rb', line 9

def domain_name
  @domain_name
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



9
10
11
# File 'lib/shopify_cli/theme/dev_server/certificate_manager.rb', line 9

def private_key
  @private_key
end

Instance Method Details

#find_or_create_certificates!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shopify_cli/theme/dev_server/certificate_manager.rb', line 21

def find_or_create_certificates!
  @private_key = if (private_key_pem = ShopifyCLI::DB.get(:ssl_private_key))
    OpenSSL::PKey::RSA.new(private_key_pem)
  else
    OpenSSL::PKey::RSA.new(2048)
  end

  @certificate = if (certificate_pem = ShopifyCLI::DB.get(:ssl_certificate))
    OpenSSL::X509::Certificate.new(certificate_pem)
  else
    x509_certificate = build_x509_certificate

    sign_certificate!(x509_certificate)

    x509_certificate
  end

  ShopifyCLI::DB.set(ssl_certificate: certificate.to_pem)
  ShopifyCLI::DB.set(ssl_private_key: private_key.to_pem)
end