localhost 1.1.5 → 1.1.9

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: 8a1b3eb6d424eeebb97617e67e4024201dc4b212a2dc9127c7858b1f6637c0ed
4
- data.tar.gz: da7d5bcad68fd00a7291039b5d325d3268abf8068af6948f69b6267c0a0980fc
3
+ metadata.gz: 5c6fcac1295924f18159bdfbf56da57dc568c01dfe16fe030ca4efa03a51f77d
4
+ data.tar.gz: e781042e92c7456d0e99ca8373c22433e193e4ac2dbea36829484a0fa121f77a
5
5
  SHA512:
6
- metadata.gz: 6d636c0a1ed83c769a1d3b58a8a4fc2392c064ddc6357f7ae6da4f71037a1912296af6107c6fbff021f9997e5c075b6445d6e24e4ca09692ec4f1b6bb0b845d5
7
- data.tar.gz: 133e22ea3545a383d2f111dd053bfb070b274ebe247be9956bfbce07e2be07ec4fea7779ca21fe26c1f90e2e1fbcacf891ef1ba41c8637d79199e16a3289930b
6
+ metadata.gz: 03f3a2b111cfdc84199224ac5ab66c842d03f79d7514354ba06086d057769d3b31fc7606333696f342d2e9d0d438c89a19a470f2e38f0f64a77c200d9897a724
7
+ data.tar.gz: b696353ce1f45d8dbd863cf33b677a5d25ff83b2703585eb1a9b42faf7efe83a0b6bc5105f7c558e36c8542c01da8649eb21804dba415c52a7772e9db292ff85
checksums.yaml.gz.sig ADDED
Binary file
@@ -22,25 +22,44 @@ require 'yaml'
22
22
  require 'openssl'
23
23
 
24
24
  module Localhost
25
+ # Represents a single public/private key pair for a given hostname.
25
26
  class Authority
26
27
  def self.path
27
28
  File.expand_path("~/.localhost")
28
29
  end
29
30
 
30
- def self.fetch(*args)
31
- authority = self.new(*args)
32
- path = self.path
31
+ # List all certificate authorities in the given directory:
32
+ def self.list(root = self.path)
33
+ return to_enum(:list) unless block_given?
33
34
 
34
- unless authority.load(path)
35
- Dir.mkdir(path, 0700) unless File.directory?(path)
35
+ Dir.glob("*.crt", base: root) do |path|
36
+ name = File.basename(path, ".crt")
36
37
 
37
- authority.save(path)
38
+ authority = self.new(name, root: root)
39
+
40
+ if authority.load
41
+ yield authority
42
+ end
43
+ end
44
+ end
45
+
46
+ # Fetch (load or create) a certificate with the given hostname.
47
+ # See {#initialize} for the format of the arguments.
48
+ def self.fetch(*arguments, **options)
49
+ authority = self.new(*arguments, **options)
50
+
51
+ unless authority.load
52
+ authority.save
38
53
  end
39
54
 
40
55
  return authority
41
56
  end
42
57
 
43
- def initialize(hostname = "localhost")
58
+ # Create an authority forn the given hostname.
59
+ # @parameter hostname [String] The common name to use for the certificate.
60
+ # @parameter root [String] The root path for loading and saving the certificate.
61
+ def initialize(hostname = "localhost", root: self.class.path)
62
+ @root = root
44
63
  @hostname = hostname
45
64
 
46
65
  @key = nil
@@ -49,6 +68,9 @@ module Localhost
49
68
  @store = nil
50
69
  end
51
70
 
71
+ # The hostname of the certificate authority.
72
+ attr :hostname
73
+
52
74
  BITS = 1024*2
53
75
 
54
76
  def ecdh_key
@@ -59,6 +81,17 @@ module Localhost
59
81
  @dh_key ||= OpenSSL::PKey::DH.new(BITS)
60
82
  end
61
83
 
84
+ # The private key path.
85
+ def key_path
86
+ File.join(@root, "#{@hostname}.key")
87
+ end
88
+
89
+ # The public certificate path.
90
+ def certificate_path
91
+ File.join(@root, "#{@hostname}.crt")
92
+ end
93
+
94
+ # The private key.
62
95
  def key
63
96
  @key ||= OpenSSL::PKey::RSA.new(BITS)
64
97
  end
@@ -67,14 +100,17 @@ module Localhost
67
100
  @key = key
68
101
  end
69
102
 
103
+ # The certificate name.
70
104
  def name
71
- @name ||= OpenSSL::X509::Name.parse("O=Development/CN=#{@hostname}")
105
+ @name ||= OpenSSL::X509::Name.parse("/O=Development/CN=#{@hostname}")
72
106
  end
73
107
 
74
108
  def name= name
75
109
  @name = name
76
110
  end
77
111
 
112
+ # The public certificate.
113
+ # @returns [OpenSSL::X509::Certificate] A self-signed certificate.
78
114
  def certificate
79
115
  @certificate ||= OpenSSL::X509::Certificate.new.tap do |certificate|
80
116
  certificate.subject = self.name
@@ -105,7 +141,7 @@ module Localhost
105
141
  end
106
142
  end
107
143
 
108
- # The certificate store which is used for validating the server certificate:
144
+ # The certificate store which is used for validating the server certificate.
109
145
  def store
110
146
  @store ||= OpenSSL::X509::Store.new.tap do |store|
111
147
  store.add_cert(self.certificate)
@@ -114,8 +150,9 @@ module Localhost
114
150
 
115
151
  SERVER_CIPHERS = "EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5".freeze
116
152
 
117
- def server_context(*args)
118
- OpenSSL::SSL::SSLContext.new(*args).tap do |context|
153
+ # @returns [OpenSSL::SSL::SSLContext] An context suitable for implementing a secure server.
154
+ def server_context(*arguments)
155
+ OpenSSL::SSL::SSLContext.new(*arguments).tap do |context|
119
156
  context.key = self.key
120
157
  context.cert = self.certificate
121
158
 
@@ -126,7 +163,7 @@ module Localhost
126
163
  end
127
164
 
128
165
  if context.respond_to? :ecdh_curves=
129
- context.ecdh_curves = 'P-256:P-384:P-224:P-521'
166
+ context.ecdh_curves = 'P-256:P-384:P-521'
130
167
  elsif context.respond_to? :tmp_ecdh_callback=
131
168
  context.tmp_ecdh_callback = proc {self.ecdh_key}
132
169
  end
@@ -138,6 +175,7 @@ module Localhost
138
175
  end
139
176
  end
140
177
 
178
+ # @returns [OpenSSL::SSL::SSLContext] An context suitable for connecting to a secure server using this authority.
141
179
  def client_context(*args)
142
180
  OpenSSL::SSL::SSLContext.new(*args).tap do |context|
143
181
  context.cert_store = self.store
@@ -148,8 +186,8 @@ module Localhost
148
186
  end
149
187
  end
150
188
 
151
- def load(path)
152
- if File.directory? path
189
+ def load(path = @root)
190
+ if File.directory?(path)
153
191
  certificate_path = File.join(path, "#{@hostname}.crt")
154
192
  key_path = File.join(path, "#{@hostname}.key")
155
193
 
@@ -168,16 +206,24 @@ module Localhost
168
206
  end
169
207
  end
170
208
 
171
- def save(path)
172
- File.write(
173
- File.join(path, "#{@hostname}.crt"),
174
- self.certificate.to_pem
175
- )
209
+ def save(path = @root)
210
+ Dir.mkdir(path, 0700) unless File.directory?(path)
176
211
 
177
- File.write(
178
- File.join(path, "#{@hostname}.key"),
179
- self.key.to_pem
180
- )
212
+ lockfile_path = File.join(path, "#{@hostname}.lock")
213
+
214
+ File.open(lockfile_path, File::RDWR|File::CREAT, 0644) do |lockfile|
215
+ lockfile.flock(File::LOCK_EX)
216
+
217
+ File.write(
218
+ File.join(path, "#{@hostname}.crt"),
219
+ self.certificate.to_pem
220
+ )
221
+
222
+ File.write(
223
+ File.join(path, "#{@hostname}.key"),
224
+ self.key.to_pem
225
+ )
226
+ end
181
227
  end
182
228
  end
183
229
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Localhost
22
- VERSION = "1.1.5"
22
+ VERSION = "1.1.9"
23
23
  end
data/lib/localhost.rb CHANGED
@@ -18,4 +18,5 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require "localhost/version"
21
+ require_relative 'localhost/version'
22
+ require_relative 'localhost/authority'
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,17 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localhost
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2019-04-07 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
14
+ ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
15
+ MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
16
+ aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
17
+ AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
18
+ xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
19
+ eNMDgKsMJtC7u/43abRKx7TCURW3iWyR19NRngsJJmaR51yGGGm2Kfsr+JtKKLtL
20
+ L188Wm3f13KAx7QJU8qyuBnj1/gWem076hzdA7xi1DbrZrch9GCRz62xymJlrJHn
21
+ 9iZEZ7AxrS7vokhMlzSr/XMUihx/8aFKtk+tMLClqxZSmBWIErWdicCGTULXCBNb
22
+ E/mljo4zEVKhlTWpJklMIhr55ZRrSarKFuW7en0+tpJrfsYiAmXMJNi4XAYJH7uL
23
+ rgJuJwSaa/dMz+VmUoo7VKtSfCoOI+6v5/z0sK3oT6sG6ZwyI47DBq2XqNC6tnAj
24
+ w+XmCywiTQrFzMMAvcA7rPI4F0nU1rZId51rOvvfxaONp+wgTi4P8owZLw0/j0m4
25
+ 8C20DYi6EYx4AHDXiLpElWh3AgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8E
26
+ BAMCBLAwHQYDVR0OBBYEFB6ZaeWKxQjGTI+pmz7cKRmMIywwMC4GA1UdEQQnMCWB
27
+ I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWB
28
+ I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEB
29
+ CwUAA4IBgQBVoM+pu3dpdUhZM1w051iw5GfiqclAr1Psypf16Tiod/ho//4oAu6T
30
+ 9fj3DPX/acWV9P/FScvqo4Qgv6g4VWO5ZU7z2JmPoTXZtYMunRAmQPFL/gSUc6aK
31
+ vszMHIyhtyzRc6DnfW2AiVOjMBjaYv8xXZc9bduniRVPrLR4J7ozmGLh4o4uJp7w
32
+ x9KCFaR8Lvn/r0oJWJOqb/DMAYI83YeN2Dlt3jpwrsmsONrtC5S3gOUle5afSGos
33
+ bYt5ocnEpKSomR9ZtnCGljds/aeO1Xgpn2r9HHcjwnH346iNrnHmMlC7BtHUFPDg
34
+ Ts92S47PTOXzwPBDsrFiq3VLbRjHSwf8rpqybQBH9MfzxGGxTaETQYOd6b4e4Ag6
35
+ y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
36
+ RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
37
+ HiLJ8VOFx6w=
38
+ -----END CERTIFICATE-----
39
+ date: 2021-09-19 00:00:00.000000000 Z
12
40
  dependencies:
13
41
  - !ruby/object:Gem::Dependency
14
- name: covered
42
+ name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
16
44
  requirements:
17
45
  - - ">="
@@ -25,33 +53,19 @@ dependencies:
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.16'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.16'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
56
+ name: covered
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '10.0'
61
+ version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,31 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.0'
69
- description:
83
+ description:
70
84
  email:
71
- - samuel.williams@oriontransfer.co.nz
72
85
  executables: []
73
86
  extensions: []
74
87
  extra_rdoc_files: []
75
88
  files:
76
- - ".editorconfig"
77
- - ".gitignore"
78
- - ".rspec"
79
- - ".travis.yml"
80
- - Gemfile
81
- - README.md
82
- - Rakefile
83
- - examples/https.rb
84
89
  - lib/localhost.rb
85
90
  - lib/localhost/authority.rb
86
91
  - lib/localhost/version.rb
87
- - localhost.gemspec
88
- - media/chrome.png
89
- - media/safari.png
90
92
  homepage: https://github.com/socketry/localhost
91
- licenses: []
93
+ licenses:
94
+ - MIT
92
95
  metadata: {}
93
- post_install_message:
96
+ post_install_message:
94
97
  rdoc_options: []
95
98
  require_paths:
96
99
  - lib
@@ -105,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
108
  - !ruby/object:Gem::Version
106
109
  version: '0'
107
110
  requirements: []
108
- rubygems_version: 3.0.3
109
- signing_key:
111
+ rubygems_version: 3.1.6
112
+ signing_key:
110
113
  specification_version: 4
111
114
  summary: Manage a local certificate authority for self-signed localhost development
112
115
  servers.
metadata.gz.sig ADDED
Binary file
data/.editorconfig DELETED
@@ -1,6 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = tab
5
- indent_size = 2
6
-
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
-
13
- /ssl/
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- matrix:
6
- include:
7
- - rvm: 2.3
8
- - rvm: 2.4
9
- - rvm: 2.5
10
- - rvm: 2.6
11
- - rvm: 2.6
12
- os: osx
13
- - rvm: 2.6
14
- env: COVERAGE=BriefSummary,Coveralls
15
- - rvm: truffleruby
16
- - rvm: jruby-head
17
- env: JRUBY_OPTS="--debug -X+O"
18
- - rvm: ruby-head
19
- allow_failures:
20
- - rvm: truffleruby
21
- - rvm: ruby-head
22
- - rvm: jruby-head
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in localhost.gemspec
6
- gemspec
7
-
8
- group :development do
9
- gem 'async-io'
10
- gem 'async-rspec'
11
-
12
- gem 'async-process'
13
- end
data/README.md DELETED
@@ -1,132 +0,0 @@
1
- # Localhost [![Build Status](https://travis-ci.com/socketry/localhost.svg)](https://travis-ci.com/socketry/localhost)
2
-
3
- This gem provides a convenient API for generating per-user self-signed root certificates.
4
-
5
- ## Motivation
6
-
7
- HTTP/2 requires SSL in web browsers. If you want to use HTTP/2 for development (and you should), you need to start using URLs like `https://localhost:8080`. In most cases, this requires adding a self-signed certificate to your certificate store (e.g. Keychain on macOS), and storing the private key for the web-server to use.
8
-
9
- I wanted to provide a server-agnostic way of doing this, primarily because I think it makes sense to minimise the amount of junky self-signed keys you add to your certificate store for `localhost`.
10
-
11
- ## Installation
12
-
13
- Add this line to your application's Gemfile:
14
-
15
- ```ruby
16
- gem 'localhost'
17
- ```
18
-
19
- And then execute:
20
-
21
- $ bundle
22
-
23
- Or install it yourself as:
24
-
25
- $ gem install localhost
26
-
27
- ## Usage
28
-
29
- This example shows how to generate a certificate for an SSL secured server:
30
-
31
- ```ruby
32
- require 'socket'
33
- require 'thread'
34
-
35
- require 'localhost/authority'
36
-
37
- # Get the self-signed authority for localhost:
38
- authority = Localhost::Authority.fetch
39
-
40
- ready = Thread::Queue.new
41
-
42
- # Start a server thread:
43
- server_thread = Thread.new do
44
- server = OpenSSL::SSL::SSLServer.new(TCPServer.new("localhost", 4050), authority.server_context)
45
-
46
- server.listen
47
-
48
- ready << true
49
-
50
- peer = server.accept
51
-
52
- peer.puts "Hello World!"
53
- peer.flush
54
-
55
- peer.close
56
- end
57
-
58
- ready.pop
59
-
60
- client = OpenSSL::SSL::SSLSocket.new(TCPSocket.new("localhost", 4050), authority.client_context)
61
-
62
- # Initialize SSL connection:
63
- client.connect
64
-
65
- # Read the encrypted message:
66
- puts client.read(12)
67
-
68
- client.close
69
- server_thread.join
70
- ```
71
-
72
- If you use Safari to access such a server, it will allow you to add the certificate to your keychain without much work. Once you've done this, you won't need to do it again for any other site when running such a development environment from the same user account.
73
-
74
- For an example of how to make your own HTTPS web server, see [examples/https.rb](examples/https.rb).
75
-
76
- ### Safari
77
-
78
- If you use this with a web server, when you open the site in Safari:
79
-
80
- ![Safari](media/safari.png)
81
-
82
- - Click "View the certificate" to check that it is the correct certificate.
83
- - Click "visit this website" which will prompt you to add the certificate to your keychain. Once you've done this, it should work for a long time.
84
-
85
- ### Chrome
86
-
87
- If you use this with a web server, when you open the site in Chrome:
88
-
89
- ![Chrome](media/chrome.png)
90
-
91
- - Click "ADVANCED" to see additional details, including...
92
- - Click "Proceed to localhost (unsafe)" which will allow you to use the site for the current browser session.
93
-
94
- ### Files
95
-
96
- The certificate and private key are stored in `~/.localhost/`. You can delete them and they will be regenerated. If you added the certificate to your keychain, you'll probably want to delete that too.
97
-
98
- ## Contributing
99
-
100
- 1. Fork it
101
- 2. Create your feature branch (`git checkout -b my-new-feature`)
102
- 3. Commit your changes (`git commit -am 'Add some feature'`)
103
- 4. Push to the branch (`git push origin my-new-feature`)
104
- 5. Create new Pull Request
105
-
106
- ## See Also
107
-
108
- - [falcon](https://github.com/socketry/falcon) — Uses this `Localhost::Authority` to provide HTTP/2 with minimal configuration for `localhost`.
109
-
110
- ## License
111
-
112
- Released under the MIT license.
113
-
114
- Copyright, 2018, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
115
-
116
- Permission is hereby granted, free of charge, to any person obtaining a copy
117
- of this software and associated documentation files (the "Software"), to deal
118
- in the Software without restriction, including without limitation the rights
119
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
120
- copies of the Software, and to permit persons to whom the Software is
121
- furnished to do so, subject to the following conditions:
122
-
123
- The above copyright notice and this permission notice shall be included in
124
- all copies or substantial portions of the Software.
125
-
126
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
127
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
128
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
129
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
130
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
131
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
132
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/examples/https.rb DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'async'
4
- require 'async/io/host_endpoint'
5
- require 'async/io/ssl_endpoint'
6
- require 'async/http/server'
7
- require 'async/http/client'
8
- require 'localhost/authority'
9
-
10
- # The (self-signed) authority to use:
11
- hostname = "localhost"
12
- authority = Localhost::Authority.fetch(hostname)
13
-
14
- # The server app:
15
- app = lambda do |request|
16
- Async::HTTP::Response[200, {}, ["Hello World!"]]
17
- end
18
-
19
- # Bind to the specified host:
20
- endpoint = Async::IO::Endpoint.tcp(hostname, "8080")
21
-
22
- # Prepare the server, endpoint will be used for `bind`:
23
- server_endpoint = Async::IO::SSLEndpoint.new(endpoint, ssl_context: authority.server_context)
24
- server = Async::HTTP::Server.new(app, server_endpoint, Async::HTTP::Protocol::HTTP1)
25
-
26
- # Prepare the client, endpoint will be used for `connect`:
27
- client_endpoint = Async::IO::SSLEndpoint.new(endpoint, ssl_context: authority.client_context)
28
- client = Async::HTTP::Client.new(client_endpoint, Async::HTTP::Protocol::HTTP1)
29
-
30
- # Run the reactor:
31
- Async::Reactor.run do |task|
32
- # Start the server task:
33
- server_task = task.async do
34
- server.run
35
- end
36
-
37
- # Connect to the server:
38
- response = client.get("/")
39
- puts "Status: #{response.status}\n#{response.read}"
40
-
41
- # Stop the server:
42
- server_task.stop
43
- end
data/localhost.gemspec DELETED
@@ -1,23 +0,0 @@
1
-
2
- require_relative "lib/localhost/version"
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "localhost"
6
- spec.version = Localhost::VERSION
7
- spec.authors = ["Samuel Williams"]
8
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
-
10
- spec.summary = "Manage a local certificate authority for self-signed localhost development servers."
11
- spec.homepage = "https://github.com/socketry/localhost"
12
-
13
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
- f.match(%r{^(test|spec|features)/})
15
- end
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.require_paths = ["lib"]
18
-
19
- spec.add_development_dependency "covered"
20
- spec.add_development_dependency "bundler", "~> 1.16"
21
- spec.add_development_dependency "rake", "~> 10.0"
22
- spec.add_development_dependency "rspec", "~> 3.0"
23
- end
data/media/chrome.png DELETED
Binary file
data/media/safari.png DELETED
Binary file