localhost 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 647476f190a1dbfe917956c6cb23717528e94b905ff47906bee0a287fa83639e
4
- data.tar.gz: 035e92adad13af22294589079c5d8a8780497a1f6f392a03d382a166f85323ea
3
+ metadata.gz: 42bb902395ea685a7f1d14530439871920afb46b852aa9f6c3bbb8b66d07176a
4
+ data.tar.gz: 2b63d1af2999cd2ebca0f706bb626654cf765953fbbe1a0a6d4c3b6985482b50
5
5
  SHA512:
6
- metadata.gz: cc47079bea9080adf043cb4cbef2e4e352797557ad2da46be3026e27971216479904afb4d9bbc8ad8183ae409575be74bd0d5c47f9006335bfa7f4d7472d5c26
7
- data.tar.gz: 5b27695d5ca8290ce1d7a10afef2e73587c5db2395b05170463a54d52a80f13617b6145b3d1c157d7627cdcc07660d053aa7183f3615871ad69a017547328219
6
+ metadata.gz: f27728bc1e1593af0db04c176bd99c878958aa662d6902649d6d5cb617034269e641a61d201255be7f8a859a08b3015980b56f28672dc301547f7aa3c6c96fa8
7
+ data.tar.gz: 66ad2882eef6927aaf6da87280931a81f5928d2cf72bb92a6a10451721465a08b9d51f52a01a1d97847a7019c634499c2cb068ed19401d1e8e713452ec633156
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,20 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2023, by Samuel Williams.
4
+ # Copyright, 2018-2024, 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.
8
8
  # Copyright, 2023, by Antonio Terceiro.
9
9
  # Copyright, 2023, by Yuuji Yaginuma.
10
+ # Copyright, 2024, by Colin Shea.
10
11
 
12
+ require 'fileutils'
11
13
  require 'openssl'
12
14
 
13
15
  module Localhost
14
16
  # Represents a single public/private key pair for a given hostname.
15
17
  class Authority
18
+ # Where to store the key pair on the filesystem. This is a subdirectory
19
+ # of $XDG_STATE_HOME, or ~/.local/state/ when that's not defined.
16
20
  def self.path
17
- File.expand_path("~/.localhost")
21
+ File.expand_path("localhost.rb", ENV.fetch("XDG_STATE_HOME", "~/.local/state"))
18
22
  end
19
23
 
20
24
  # List all certificate authorities in the given directory:
@@ -176,27 +180,27 @@ module Localhost
176
180
  end
177
181
 
178
182
  def load(path = @root)
179
- if File.directory?(path)
180
- certificate_path = File.join(path, "#{@hostname}.crt")
181
- key_path = File.join(path, "#{@hostname}.key")
182
-
183
- return false unless File.exist?(certificate_path) and File.exist?(key_path)
184
-
185
- certificate = OpenSSL::X509::Certificate.new(File.read(certificate_path))
186
- key = OpenSSL::PKey::RSA.new(File.read(key_path))
187
-
188
- # Certificates with old version need to be regenerated.
189
- return false if certificate.version < 2
190
-
191
- @certificate = certificate
192
- @key = key
193
-
194
- return true
195
- end
183
+ ensure_authority_path_exists(path)
184
+
185
+ certificate_path = File.join(path, "#{@hostname}.crt")
186
+ key_path = File.join(path, "#{@hostname}.key")
187
+
188
+ return false unless File.exist?(certificate_path) and File.exist?(key_path)
189
+
190
+ certificate = OpenSSL::X509::Certificate.new(File.read(certificate_path))
191
+ key = OpenSSL::PKey::RSA.new(File.read(key_path))
192
+
193
+ # Certificates with old version need to be regenerated.
194
+ return false if certificate.version < 2
195
+
196
+ @certificate = certificate
197
+ @key = key
198
+
199
+ return true
196
200
  end
197
201
 
198
202
  def save(path = @root)
199
- Dir.mkdir(path, 0700) unless File.directory?(path)
203
+ ensure_authority_path_exists(path)
200
204
 
201
205
  lockfile_path = File.join(path, "#{@hostname}.lock")
202
206
 
@@ -214,5 +218,19 @@ module Localhost
214
218
  )
215
219
  end
216
220
  end
221
+
222
+ # Ensures that the directory to store the certificate exists. If the legacy
223
+ # directory (~/.localhost/) exists, it is moved into the new XDG Basedir
224
+ # compliant directory.
225
+ def ensure_authority_path_exists(path = @root)
226
+ old_root = File.expand_path("~/.localhost")
227
+
228
+ if File.directory?(old_root) and not File.directory?(path)
229
+ # Migrates the legacy dir ~/.localhost/ to the XDG compliant directory
230
+ File.rename(old_root, path)
231
+ elsif not File.directory?(path)
232
+ FileUtils.makedirs(path, mode: 0700)
233
+ end
234
+ end
217
235
  end
218
236
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2023, by Samuel Williams.
4
+ # Copyright, 2018-2024, by Samuel Williams.
5
5
 
6
6
  module Localhost
7
- VERSION = "1.2.0"
7
+ VERSION = "1.3.0"
8
8
  end
data/license.md CHANGED
@@ -9,6 +9,7 @@ Copyright, 2021, by Ye Lin Aung.
9
9
  Copyright, 2022, by Juri Hahn.
10
10
  Copyright, 2023, by Antonio Terceiro.
11
11
  Copyright, 2023, by Yuuji Yaginuma.
12
+ Copyright, 2024, by Colin Shea.
12
13
 
13
14
  Permission is hereby granted, free of charge, to any person obtaining a copy
14
15
  of this software and associated documentation files (the "Software"), to deal
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.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -9,6 +9,7 @@ authors:
9
9
  - Ye Lin Aung
10
10
  - Akshay Birajdar
11
11
  - Antonio Terceiro
12
+ - Colin Shea
12
13
  - Gabriel Sobrinho
13
14
  - Juri Hahn
14
15
  - Richard S. Leung
@@ -45,7 +46,7 @@ cert_chain:
45
46
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
46
47
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
47
48
  -----END CERTIFICATE-----
48
- date: 2024-02-01 00:00:00.000000000 Z
49
+ date: 2024-04-12 00:00:00.000000000 Z
49
50
  dependencies: []
50
51
  description:
51
52
  email:
@@ -61,7 +62,9 @@ files:
61
62
  homepage: https://github.com/socketry/localhost
62
63
  licenses:
63
64
  - MIT
64
- metadata: {}
65
+ metadata:
66
+ documentation_uri: https://socketry.github.io/localhost/
67
+ source_code_uri: https://github.com/socketry/localhost.git
65
68
  post_install_message:
66
69
  rdoc_options: []
67
70
  require_paths:
metadata.gz.sig CHANGED
Binary file