localhost 1.5.0 → 1.7.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: 03be6efdb28ecebf6663f77b0e8b0c6267976a3c10aa8a6d630890656da9f449
4
+ data.tar.gz: 2da6f5035d4e553058fb34393c36e067cd20e23bb0e22c343611a9573862fe1c
5
5
  SHA512:
6
- metadata.gz: 8c6c85bff1973b4637c03031a73f4f0a77974eb7f9def2db89b7213586ff051f2c3d4d214732a052d6334f6253b9c54282427bf99c321d3a8c125f02bae07493
7
- data.tar.gz: e35941e8efbae8f94b00f2738b7425cfbc4046dca06971c9a970747146e5eef22de7e17e41a185cd15cae9f44f602e5dccee705d01da19508292511f872d1d1b
6
+ metadata.gz: 0b6b90d3fdb12a662104aaeb27da9e1ab9403c705f9ee90b87ccb8c0c5ebaa13c95b26be111812a44b6d74585f9fc7d5c8cd54951862053b66ccb3c5ebebfa41
7
+ data.tar.gz: bc8995c9f8e2e44619faee824dc97dc5bd8c593b1471b122958a0a719faf25d8c184a9b8a193f4af2e0013b941bba5d641191b9d4407497c3af8d598e7b033f6
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2025, by Samuel Williams.
4
+ # Copyright, 2018-2026, by Samuel Williams.
5
5
  # Copyright, 2019, by Richard S. Leung.
6
6
  # Copyright, 2021, by Akshay Birajdar.
7
7
  # Copyright, 2021, by Ye Lin Aung.
@@ -173,7 +173,7 @@ module Localhost
173
173
  context.session_id_context = "localhost"
174
174
 
175
175
  if context.respond_to? :tmp_dh_callback=
176
- context.tmp_dh_callback = proc {self.dh_key}
176
+ context.tmp_dh_callback = proc{self.dh_key}
177
177
  end
178
178
 
179
179
  if context.respond_to? :ecdh_curves=
@@ -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
@@ -1,22 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2025, by Samuel Williams.
4
+ # Copyright, 2025-2026, by Samuel Williams.
5
5
 
6
6
  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
+ # OpenSUSE/SLES use this path for certificate anchors.
15
+ OPENSUSE_ANCHORS_PATH = "/etc/pki/trust/anchors/"
16
+
17
+ # This is an older method for systems that do not use `update-ca-trust`.
18
+ LOCAL_CERTIFICATES_PATH = "/usr/local/share/ca-certificates/"
19
+ UPDATE_CA_CERTIFICATES = "update-ca-certificates"
20
+
10
21
  # Install a certificate into the system trust store.
11
22
  #
12
23
  # @parameter certificate [String] The path to the certificate file.
13
24
  def self.install(certificate)
14
25
  filename = File.basename(certificate)
15
- destination = "/usr/local/share/ca-certificates/localhost-#{filename}"
26
+ command = nil
16
27
 
17
- system("sudo", "cp", certificate, destination)
18
- system("sudo", "update-ca-certificates")
28
+ if File.exist?(ANCHORS_PATH)
29
+ # For systems using `update-ca-trust` (most Linux distributions).
30
+ destination = File.join(ANCHORS_PATH, filename)
31
+ command = UPDATE_CA_TRUST
32
+ elsif File.exist?(OPENSUSE_ANCHORS_PATH)
33
+ # For systems using `update-ca-certificates` (OpenSUSE/SLES).
34
+ destination = File.join(OPENSUSE_ANCHORS_PATH, filename)
35
+ command = UPDATE_CA_CERTIFICATES
36
+ elsif File.exist?(LOCAL_CERTIFICATES_PATH)
37
+ # For systems using `update-ca-certificates`.
38
+ destination = File.join(LOCAL_CERTIFICATES_PATH, filename)
39
+ command = UPDATE_CA_CERTIFICATES
40
+ else
41
+ raise "No known system trust store found. Please install the certificate manually."
42
+ end
43
+
44
+ success = system("sudo", "cp", certificate, destination)
45
+ success &= system("sudo", command)
46
+
47
+ if success
48
+ $stderr.puts "Installed certificate to #{destination}"
49
+
50
+ return true
51
+ else
52
+ raise "Failed to install certificate: #{certificate}"
53
+ end
19
54
  end
20
55
  end
21
56
  end
22
- end
57
+ 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.7.0"
8
8
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2018-2025, by Samuel Williams.
3
+ Copyright, 2018-2026, by Samuel Williams.
4
4
  Copyright, 2018, by Gabriel Sobrinho.
5
5
  Copyright, 2019, by Richard S. Leung.
6
6
  Copyright, 2020-2021, by Olle Jonsson.
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.7.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: 4.0.3
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