localhost 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb2af90326b97a7ed35c40f67354cd551fc7f7087b3988752be1ce84346b5d33
4
- data.tar.gz: 7d3e6cfe20a573d193ab7d54128af846481287423f058705ec1c7e7267d2093d
3
+ metadata.gz: f89b94a723b8a61b6643315b8e80d1c41e8bbba1e40b4ef717712a27f6b9c99e
4
+ data.tar.gz: 17a0be5aa542d32276375451ed5f3a29a83f838a9a9905a3e451477c8aa45d8c
5
5
  SHA512:
6
- metadata.gz: 8c6c85bff1973b4637c03031a73f4f0a77974eb7f9def2db89b7213586ff051f2c3d4d214732a052d6334f6253b9c54282427bf99c321d3a8c125f02bae07493
7
- data.tar.gz: e35941e8efbae8f94b00f2738b7425cfbc4046dca06971c9a970747146e5eef22de7e17e41a185cd15cae9f44f602e5dccee705d01da19508292511f872d1d1b
6
+ metadata.gz: fe38188f3a314ad69e4c7bcc03092cf9e2e1efa98570879aef8d52a94d851f310d8884b767aff64a6642b40d4ca04e0dec54ee2e1c75d1158ec6d514cc09e103
7
+ data.tar.gz: ce8a85d130b0c828170105f177b189fb5417abd1b9b7c00079eb7951fd6c1a82767d74609ccd3fa2fa3b7b5b665eca98feab3aaffb922cc083f560777786357d
checksums.yaml.gz.sig CHANGED
Binary file
data/bake/localhost.rb CHANGED
@@ -13,13 +13,7 @@ end
13
13
  #
14
14
  # @returns [Array(Hash)] The certificate and key paths, and the expiry date.
15
15
  def list
16
- Localhost::Authority.list.map do |authority|
17
- {
18
- certificate_path: authority.certificate_path,
19
- key_path: authority.key_path,
20
- expires_at: authority.certificate.not_after,
21
- }
22
- end
16
+ Localhost::Authority.list.map(&:to_h)
23
17
  end
24
18
 
25
19
  # Fetch a local authority by hostname. If the authority does not exist, it will be created.
@@ -27,21 +21,25 @@ end
27
21
  # @parameter hostname [String] The hostname to fetch.
28
22
  # @returns [Hash] The certificate and key paths, and the expiry date.
29
23
  def fetch(hostname)
30
- if authority = Localhost::Authority.fetch(hostname)
31
- return {
32
- certificate_path: authority.certificate_path,
33
- key_path: authority.key_path,
34
- expires_at: authority.certificate.not_after,
35
- }
36
- end
24
+ Localhost::Authority.fetch(hostname)
37
25
  end
38
26
 
27
+ # Install a certificate into the system trust store.
28
+ # @parameter name [String] The name of the issuer to install, or nil for the default issuer.
39
29
  def install(name: nil)
40
30
  issuer = Localhost::Issuer.fetch(name)
41
31
 
32
+ $stderr.puts "Installing certificate for #{issuer.subject}..."
42
33
  Localhost::System.current.install(issuer.certificate_path)
34
+
35
+ return nil
43
36
  end
44
37
 
38
+ # Delete all local authorities.
45
39
  def purge
40
+ $stderr.puts "Purging localhost state..."
41
+
46
42
  Localhost::State.purge
43
+
44
+ return nil
47
45
  end
@@ -242,5 +242,23 @@ module Localhost
242
242
 
243
243
  return true
244
244
  end
245
+
246
+ # @returns A hash representation of the authority's certificate details.
247
+ def to_h
248
+ {
249
+ hostname: @hostname,
250
+ certificate_path: certificate_path,
251
+ key_path: key_path,
252
+ expires_at: certificate.not_after,
253
+ }
254
+ end
255
+
256
+ def as_json(...)
257
+ self.to_h
258
+ end
259
+
260
+ def to_json(...)
261
+ self.as_json.to_json(...)
262
+ end
245
263
  end
246
264
  end
@@ -32,7 +32,7 @@ module Localhost
32
32
  def self.purge(env = ENV)
33
33
  path = self.path(env)
34
34
 
35
- FileUtils.rm_rf(path)
36
- end
35
+ return FileUtils.rm_rf(path)
36
+ end
37
37
  end
38
38
  end
@@ -13,13 +13,21 @@ module Localhost
13
13
  def self.install(certificate)
14
14
  login_keychain = File.expand_path("~/Library/Keychains/login.keychain-db")
15
15
 
16
- system(
16
+ success = system(
17
17
  "security", "add-trusted-cert",
18
18
  "-d", "-r", "trustRoot",
19
19
  "-k", login_keychain,
20
20
  certificate
21
21
  )
22
+
23
+ if success
24
+ $stderr.puts "Installed certificate to #{login_keychain}"
25
+
26
+ return true
27
+ else
28
+ raise "Failed to install certificate: #{certificate}"
29
+ end
22
30
  end
23
31
  end
24
32
  end
25
- end
33
+ end
@@ -7,16 +7,44 @@ module Localhost
7
7
  module System
8
8
  # Linux specific system operations.
9
9
  module Linux
10
+ # This appears to be the standard path for the system trust store on many Linux distributions.
11
+ ANCHORS_PATH = "/etc/ca-certificates/trust-source/anchors/"
12
+ UPDATE_CA_TRUST = "update-ca-trust"
13
+
14
+ # This is an older method for systems that do not use `update-ca-trust`.
15
+ LOCAL_CERTIFICATES_PATH = "/usr/local/share/ca-certificates/"
16
+ UPDATE_CA_CERTIFICATES = "update-ca-certificates"
17
+
10
18
  # Install a certificate into the system trust store.
11
19
  #
12
20
  # @parameter certificate [String] The path to the certificate file.
13
21
  def self.install(certificate)
14
22
  filename = File.basename(certificate)
15
- destination = "/usr/local/share/ca-certificates/localhost-#{filename}"
23
+ command = nil
16
24
 
17
- system("sudo", "cp", certificate, destination)
18
- system("sudo", "update-ca-certificates")
25
+ if File.exist?(ANCHORS_PATH)
26
+ # For systems using `update-ca-trust`.
27
+ destination = File.join(ANCHORS_PATH, filename)
28
+ command = UPDATE_CA_TRUST
29
+ elsif File.exist?(LOCAL_CERTIFICATES_PATH)
30
+ # For systems using `update-ca-certificates`.
31
+ destination = File.join(LOCAL_CERTIFICATES_PATH, filename)
32
+ command = UPDATE_CA_CERTIFICATES
33
+ else
34
+ raise "No known system trust store found. Please install the certificate manually."
35
+ end
36
+
37
+ success = system("sudo", "cp", certificate, destination)
38
+ success &= system("sudo", command)
39
+
40
+ if success
41
+ $stderr.puts "Installed certificate to #{destination}"
42
+
43
+ return true
44
+ else
45
+ raise "Failed to install certificate: #{certificate}"
46
+ end
19
47
  end
20
48
  end
21
49
  end
22
- end
50
+ end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2024, by Samuel Williams.
4
+ # Copyright, 2018-2025, by Samuel Williams.
5
5
 
6
6
  module Localhost
7
- VERSION = "1.5.0"
7
+ VERSION = "1.6.0"
8
8
  end
data/readme.md CHANGED
@@ -22,6 +22,11 @@ Please see the [project documentation](https://socketry.github.io/localhost/) fo
22
22
 
23
23
  Please see the [project releases](https://socketry.github.io/localhost/releases/index) for all releases.
24
24
 
25
+ ### v1.6.0
26
+
27
+ - Add support for `update-ca-trust` on Linux sytems.
28
+ - Better command output.
29
+
25
30
  ### v1.4.0
26
31
 
27
32
  - Add `localhost:purge` to delete all certificates.
data/releases.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Releases
2
2
 
3
+ ## v1.6.0
4
+
5
+ - Add support for `update-ca-trust` on Linux sytems.
6
+ - Better command output.
7
+
3
8
  ## v1.4.0
4
9
 
5
10
  - Add `localhost:purge` to delete all certificates.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localhost
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -46,7 +46,7 @@ cert_chain:
46
46
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
47
47
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
48
48
  -----END CERTIFICATE-----
49
- date: 2025-04-12 00:00:00.000000000 Z
49
+ date: 1980-01-02 00:00:00.000000000 Z
50
50
  dependencies: []
51
51
  executables: []
52
52
  extensions: []
@@ -77,14 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: '3.1'
80
+ version: '3.2'
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.6.2
87
+ rubygems_version: 3.6.7
88
88
  specification_version: 4
89
89
  summary: Manage a local certificate authority for self-signed localhost development
90
90
  servers.
metadata.gz.sig CHANGED
Binary file