localhost 1.1.10 → 1.3.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: a395225f2917aaac6c5334ec82ade0ff869f7987993b6394e9b7c95920a668c2
4
- data.tar.gz: f14685f7e6a7967234438d55f63185ef5676781a638faf82eb958fec91f50c01
3
+ metadata.gz: 42bb902395ea685a7f1d14530439871920afb46b852aa9f6c3bbb8b66d07176a
4
+ data.tar.gz: 2b63d1af2999cd2ebca0f706bb626654cf765953fbbe1a0a6d4c3b6985482b50
5
5
  SHA512:
6
- metadata.gz: 532fac64fd1f75d2f56607647703c47c5d27896a29e5625c55bed64dec0a099b78f619c31b6a6c9cb3120482eeae226f0d24faf9880e0890074efe247f34b559
7
- data.tar.gz: 3b4fab6a9028615436bf87162e029ce26334e6e2b4cd6cf6ef981a980404c7a1a8eabbe7cd4d3a7b9fe66d8f3acec7b9a5573737fec335c2039e51758be5adea
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:
@@ -112,7 +116,7 @@ module Localhost
112
116
  certificate.version = 2
113
117
 
114
118
  certificate.not_before = Time.now
115
- certificate.not_after = Time.now + (3600 * 24 * 365 * 10)
119
+ certificate.not_after = Time.now + (3600 * 24 * 365)
116
120
 
117
121
  extension_factory = OpenSSL::X509::ExtensionFactory.new
118
122
  extension_factory.subject_certificate = certificate
@@ -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.1.10"
7
+ VERSION = "1.3.0"
8
8
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2018-2023, by Samuel Williams.
3
+ Copyright, 2018-2024, 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.
@@ -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
@@ -24,6 +24,14 @@ We welcome contributions to this project.
24
24
  4. Push to the branch (`git push origin my-new-feature`).
25
25
  5. Create new Pull Request.
26
26
 
27
+ ### Developer Certificate of Origin
28
+
29
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
30
+
31
+ ### Contributor Covenant
32
+
33
+ This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
34
+
27
35
  ## See Also
28
36
 
29
37
  - [Falcon](https://github.com/socketry/falcon) — Uses `Localhost::Authority` to provide HTTP/2 with minimal configuration.
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.1.10
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,64 +46,8 @@ cert_chain:
45
46
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
46
47
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
47
48
  -----END CERTIFICATE-----
48
- date: 2023-02-08 00:00:00.000000000 Z
49
- dependencies:
50
- - !ruby/object:Gem::Dependency
51
- name: bundler
52
- requirement: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
- type: :development
58
- prerelease: false
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: '0'
64
- - !ruby/object:Gem::Dependency
65
- name: covered
66
- requirement: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: sus
80
- requirement: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - "~>"
83
- - !ruby/object:Gem::Version
84
- version: '0.16'
85
- type: :development
86
- prerelease: false
87
- version_requirements: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - "~>"
90
- - !ruby/object:Gem::Version
91
- version: '0.16'
92
- - !ruby/object:Gem::Dependency
93
- name: sus-fixtures-async
94
- requirement: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- type: :development
100
- prerelease: false
101
- version_requirements: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
49
+ date: 2024-04-12 00:00:00.000000000 Z
50
+ dependencies: []
106
51
  description:
107
52
  email:
108
53
  executables: []
@@ -117,7 +62,9 @@ files:
117
62
  homepage: https://github.com/socketry/localhost
118
63
  licenses:
119
64
  - MIT
120
- metadata: {}
65
+ metadata:
66
+ documentation_uri: https://socketry.github.io/localhost/
67
+ source_code_uri: https://github.com/socketry/localhost.git
121
68
  post_install_message:
122
69
  rdoc_options: []
123
70
  require_paths:
@@ -126,14 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
73
  requirements:
127
74
  - - ">="
128
75
  - !ruby/object:Gem::Version
129
- version: '0'
76
+ version: '3.0'
130
77
  required_rubygems_version: !ruby/object:Gem::Requirement
131
78
  requirements:
132
79
  - - ">="
133
80
  - !ruby/object:Gem::Version
134
81
  version: '0'
135
82
  requirements: []
136
- rubygems_version: 3.4.1
83
+ rubygems_version: 3.5.3
137
84
  signing_key:
138
85
  specification_version: 4
139
86
  summary: Manage a local certificate authority for self-signed localhost development
metadata.gz.sig CHANGED
Binary file