localhost 1.3.0 → 1.3.1

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: 42bb902395ea685a7f1d14530439871920afb46b852aa9f6c3bbb8b66d07176a
4
- data.tar.gz: 2b63d1af2999cd2ebca0f706bb626654cf765953fbbe1a0a6d4c3b6985482b50
3
+ metadata.gz: 35cad25f5ec79874e21312d5b70e4ffbf8ed616f3b8140a0f22dd6d0e1aa292b
4
+ data.tar.gz: 0e34a06090414bdd734c7b5ef094fab8a10a6c3286f0bf737e7a9f93a5d0b87a
5
5
  SHA512:
6
- metadata.gz: f27728bc1e1593af0db04c176bd99c878958aa662d6902649d6d5cb617034269e641a61d201255be7f8a859a08b3015980b56f28672dc301547f7aa3c6c96fa8
7
- data.tar.gz: 66ad2882eef6927aaf6da87280931a81f5928d2cf72bb92a6a10451721465a08b9d51f52a01a1d97847a7019c634499c2cb068ed19401d1e8e713452ec633156
6
+ metadata.gz: d6d2aa039d439e2e4e38f506335b5d72b80ffcf316886d85c86ecd1780547b156c97ddc060c93c0a9f67543bceb2d28535dde9ed955f28664a95508297433c19
7
+ data.tar.gz: 0142e748e4d118144d455bef736c2c545f18275f7c4503d118a58d239b20c13ba1c0aa3f0339d244eebd3ce30f42565f1d02246c5dc4f73f6698188c2cc1427a
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,4 @@
1
- *X�ygs����Ki��⻃�/���D\y'q��n��Y������`�<�G�VL9��+e�2i�i��2´F�k��B���2-�60"gǨ,cT����HM>��Ђ�= CmP���_1Dk�v`md$C�W�˗12�q �I8U��&�I~��P�"��i��D��=�_�غE��)���4���n��%��s���%�r r9�7�e��{��_ 4˯�{��T3j
2
- pPMVJ0�`sE>y��l�9K�S�5���������‚2��"μ���f������繞���* �L��8dLO�o��퐝7�Š���n���y���u�GrA�1�d��蓀�b�ӑ�zR�៝�x�_ݿ���6xÇ��9����:.*|�a�
1
+ ���4�i�
2
+ (��>sE�y;<XYΌh�`��6P I!8�S(7�ۘפ��:(8[fd?]�����Mg���#�uK���bC@_
3
+ �"�K�:�O��7��w��ćMr>V�e�S��Ȗ��i3�4�S���@_h)�
4
+ ��s�����-n��t0A=�x1[Q!�4(�p�G��gN��Ӳv�[������!h9:po���. L�l�H��W�ØP5L����
@@ -17,13 +17,32 @@ module Localhost
17
17
  class Authority
18
18
  # Where to store the key pair on the filesystem. This is a subdirectory
19
19
  # of $XDG_STATE_HOME, or ~/.local/state/ when that's not defined.
20
- def self.path
21
- File.expand_path("localhost.rb", ENV.fetch("XDG_STATE_HOME", "~/.local/state"))
20
+ #
21
+ # Ensures that the directory to store the certificate exists. If the legacy
22
+ # directory (~/.localhost/) exists, it is moved into the new XDG Basedir
23
+ # compliant directory.
24
+ #
25
+ # After May 2025, the old_root option may be removed.
26
+ def self.path(env = ENV, old_root: nil)
27
+ path = File.expand_path("localhost.rb", env.fetch("XDG_STATE_HOME", "~/.local/state"))
28
+
29
+ unless File.directory?(path)
30
+ FileUtils.mkdir_p(path, mode: 0700)
31
+ end
32
+
33
+ # Migrates the legacy dir ~/.localhost/ to the XDG compliant directory
34
+ old_root ||= File.expand_path("~/.localhost")
35
+ if File.directory?(old_root)
36
+ FileUtils.mv(Dir.glob(File.join(old_root, "*")), path, force: true)
37
+ FileUtils.rmdir(old_root)
38
+ end
39
+
40
+ return path
22
41
  end
23
42
 
24
43
  # List all certificate authorities in the given directory:
25
44
  def self.list(root = self.path)
26
- return to_enum(:list) unless block_given?
45
+ return to_enum(:list, root) unless block_given?
27
46
 
28
47
  Dir.glob("*.crt", base: root) do |path|
29
48
  name = File.basename(path, ".crt")
@@ -66,10 +85,6 @@ module Localhost
66
85
 
67
86
  BITS = 1024*2
68
87
 
69
- def ecdh_key
70
- @ecdh_key ||= OpenSSL::PKey::EC.new "prime256v1"
71
- end
72
-
73
88
  def dh_key
74
89
  @dh_key ||= OpenSSL::PKey::DH.new(BITS)
75
90
  end
@@ -157,8 +172,6 @@ module Localhost
157
172
 
158
173
  if context.respond_to? :ecdh_curves=
159
174
  context.ecdh_curves = 'P-256:P-384:P-521'
160
- elsif context.respond_to? :tmp_ecdh_callback=
161
- context.tmp_ecdh_callback = proc {self.ecdh_key}
162
175
  end
163
176
 
164
177
  context.set_params(
@@ -180,11 +193,9 @@ module Localhost
180
193
  end
181
194
 
182
195
  def load(path = @root)
183
- ensure_authority_path_exists(path)
184
-
185
196
  certificate_path = File.join(path, "#{@hostname}.crt")
186
197
  key_path = File.join(path, "#{@hostname}.key")
187
-
198
+
188
199
  return false unless File.exist?(certificate_path) and File.exist?(key_path)
189
200
 
190
201
  certificate = OpenSSL::X509::Certificate.new(File.read(certificate_path))
@@ -200,8 +211,6 @@ module Localhost
200
211
  end
201
212
 
202
213
  def save(path = @root)
203
- ensure_authority_path_exists(path)
204
-
205
214
  lockfile_path = File.join(path, "#{@hostname}.lock")
206
215
 
207
216
  File.open(lockfile_path, File::RDWR|File::CREAT, 0644) do |lockfile|
@@ -218,19 +227,5 @@ module Localhost
218
227
  )
219
228
  end
220
229
  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
235
230
  end
236
231
  end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2018-2024, by Samuel Williams.
5
5
 
6
6
  module Localhost
7
- VERSION = "1.3.0"
7
+ VERSION = "1.3.1"
8
8
  end
data/readme.md CHANGED
@@ -12,7 +12,13 @@ I wanted to provide a server-agnostic way of doing this, primarily because I thi
12
12
 
13
13
  ## Usage
14
14
 
15
- Please see the [project documentation](https://socketry.github.io/localhost/).
15
+ Please see the [project documentation](https://socketry.github.io/localhost/) for more details.
16
+
17
+ - [Getting Started](https://socketry.github.io/localhost/guides/getting-started/index) - This guide explains how to use `localhost` for provisioning local TLS certificates for development.
18
+
19
+ - [Browser Configuration](https://socketry.github.io/localhost/guides/browser-configuration/index) - This guide explains how to configure your local browser in order to avoid warnings about insecure self-signed certificates.
20
+
21
+ - [Example Server](https://socketry.github.io/localhost/guides/example-server/index) - This guide demonstrates how to use <code class="language-ruby">Localhost::Authority</code> to implement a simple HTTPS client & server.
16
22
 
17
23
  ## Contributing
18
24
 
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.3.0
4
+ version: 1.3.1
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: 2024-04-12 00:00:00.000000000 Z
49
+ date: 2024-04-16 00:00:00.000000000 Z
50
50
  dependencies: []
51
51
  description:
52
52
  email:
@@ -73,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '3.0'
76
+ version: '3.1'
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
metadata.gz.sig CHANGED
Binary file