localhost 1.2.0 → 1.3.1

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: 647476f190a1dbfe917956c6cb23717528e94b905ff47906bee0a287fa83639e
4
- data.tar.gz: 035e92adad13af22294589079c5d8a8780497a1f6f392a03d382a166f85323ea
3
+ metadata.gz: 35cad25f5ec79874e21312d5b70e4ffbf8ed616f3b8140a0f22dd6d0e1aa292b
4
+ data.tar.gz: 0e34a06090414bdd734c7b5ef094fab8a10a6c3286f0bf737e7a9f93a5d0b87a
5
5
  SHA512:
6
- metadata.gz: cc47079bea9080adf043cb4cbef2e4e352797557ad2da46be3026e27971216479904afb4d9bbc8ad8183ae409575be74bd0d5c47f9006335bfa7f4d7472d5c26
7
- data.tar.gz: 5b27695d5ca8290ce1d7a10afef2e73587c5db2395b05170463a54d52a80f13617b6145b3d1c157d7627cdcc07660d053aa7183f3615871ad69a017547328219
6
+ metadata.gz: d6d2aa039d439e2e4e38f506335b5d72b80ffcf316886d85c86ecd1780547b156c97ddc060c93c0a9f67543bceb2d28535dde9ed955f28664a95508297433c19
7
+ data.tar.gz: 0142e748e4d118144d455bef736c2c545f18275f7c4503d118a58d239b20c13ba1c0aa3f0339d244eebd3ce30f42565f1d02246c5dc4f73f6698188c2cc1427a
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,25 +1,48 @@
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
16
- def self.path
17
- File.expand_path("~/.localhost")
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.
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
18
41
  end
19
42
 
20
43
  # List all certificate authorities in the given directory:
21
44
  def self.list(root = self.path)
22
- return to_enum(:list) unless block_given?
45
+ return to_enum(:list, root) unless block_given?
23
46
 
24
47
  Dir.glob("*.crt", base: root) do |path|
25
48
  name = File.basename(path, ".crt")
@@ -62,10 +85,6 @@ module Localhost
62
85
 
63
86
  BITS = 1024*2
64
87
 
65
- def ecdh_key
66
- @ecdh_key ||= OpenSSL::PKey::EC.new "prime256v1"
67
- end
68
-
69
88
  def dh_key
70
89
  @dh_key ||= OpenSSL::PKey::DH.new(BITS)
71
90
  end
@@ -153,8 +172,6 @@ module Localhost
153
172
 
154
173
  if context.respond_to? :ecdh_curves=
155
174
  context.ecdh_curves = 'P-256:P-384:P-521'
156
- elsif context.respond_to? :tmp_ecdh_callback=
157
- context.tmp_ecdh_callback = proc {self.ecdh_key}
158
175
  end
159
176
 
160
177
  context.set_params(
@@ -176,28 +193,24 @@ module Localhost
176
193
  end
177
194
 
178
195
  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
196
+ certificate_path = File.join(path, "#{@hostname}.crt")
197
+ key_path = File.join(path, "#{@hostname}.key")
198
+
199
+ return false unless File.exist?(certificate_path) and File.exist?(key_path)
200
+
201
+ certificate = OpenSSL::X509::Certificate.new(File.read(certificate_path))
202
+ key = OpenSSL::PKey::RSA.new(File.read(key_path))
203
+
204
+ # Certificates with old version need to be regenerated.
205
+ return false if certificate.version < 2
206
+
207
+ @certificate = certificate
208
+ @key = key
209
+
210
+ return true
196
211
  end
197
212
 
198
213
  def save(path = @root)
199
- Dir.mkdir(path, 0700) unless File.directory?(path)
200
-
201
214
  lockfile_path = File.join(path, "#{@hostname}.lock")
202
215
 
203
216
  File.open(lockfile_path, File::RDWR|File::CREAT, 0644) do |lockfile|
@@ -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.1"
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/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
@@ -1,3 +1,3 @@
1
- ��Zn��%Nf]�<7UG%cQM�!:r�W/u��1@���S��,wڦ���\�W����)�RY��04�!v�Ƥ�T ��6Hjax�Ļ?v
2
- ��nar4���$�E������h��V���K��.E�~?=���X��-�Ucw�= }<f3~������P�z�gr��?F
3
- D�ߗ�Ŧ�٨���0��VMH����T)��[�Pg���
1
+ m��t�5{�����k$�KYa�k���Gyq7{DU�� 3����Szc�W}�Ц�����a��y�a�1��s��1f3���Qr�]��ꞏz�������)ͮuF�o*� �i�@�Vv^֯jI�wڢ|�8�PNԃ�)��Q��ݏR���(ř̩pEoLl�� ��FðK�Ɵ��҉:��^��;n k*��' g\��|z
2
+ ��l�F����c륐�8P����/S$�y�'��x���:�Cġk�MR�� ��a����gU�$ i���QA�oR^Xi�yyF��Z�q�KY�ba-w�L�@�'��-�K�E�T\�� Tܾ�}�M���Y(t�X
3
+ j'Y���b 4�[~�6
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.1
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-16 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:
@@ -70,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
73
  requirements:
71
74
  - - ">="
72
75
  - !ruby/object:Gem::Version
73
- version: '3.0'
76
+ version: '3.1'
74
77
  required_rubygems_version: !ruby/object:Gem::Requirement
75
78
  requirements:
76
79
  - - ">="
metadata.gz.sig CHANGED
Binary file