localhost 1.1.4 → 1.1.5

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: 3aedd0578ec88a4e5f4e8a4f485607ff16a4a132e0f5c5cebdc3c80e29ade744
4
- data.tar.gz: c6aa53e08063c1202b60148a04ae1391aa42c9cdbefe920723bf641a9f969741
3
+ metadata.gz: 8a1b3eb6d424eeebb97617e67e4024201dc4b212a2dc9127c7858b1f6637c0ed
4
+ data.tar.gz: da7d5bcad68fd00a7291039b5d325d3268abf8068af6948f69b6267c0a0980fc
5
5
  SHA512:
6
- metadata.gz: 5b8cbd0e0db9d5d1368f768c3171e0dac6217d6b5a400e33678028844bb1643604eaa8633552b61e018892e6cb98af9e3de5b0db6ae90111169b03f906667ce4
7
- data.tar.gz: 5cef990c8f1d88a315a4429274463ebf04ed63c5251a895eeb1bc1f9f97c50ef907f20e52b75b28dd919e9e363690eca6e71b7a21c558968caf631c7e81d4c1d
6
+ metadata.gz: 6d636c0a1ed83c769a1d3b58a8a4fc2392c064ddc6357f7ae6da4f71037a1912296af6107c6fbff021f9997e5c075b6445d6e24e4ca09692ec4f1b6bb0b845d5
7
+ data.tar.gz: 133e22ea3545a383d2f111dd053bfb070b274ebe247be9956bfbce07e2be07ec4fea7779ca21fe26c1f90e2e1fbcacf891ef1ba41c8637d79199e16a3289930b
@@ -0,0 +1,6 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = tab
5
+ indent_size = 2
6
+
@@ -4,16 +4,19 @@ cache: bundler
4
4
 
5
5
  matrix:
6
6
  include:
7
- - rvm: 2.3.6
8
7
  - rvm: 2.3
9
8
  - rvm: 2.4
10
9
  - rvm: 2.5
11
10
  - rvm: 2.6
11
+ - rvm: 2.6
12
+ os: osx
13
+ - rvm: 2.6
14
+ env: COVERAGE=BriefSummary,Coveralls
15
+ - rvm: truffleruby
12
16
  - rvm: jruby-head
13
17
  env: JRUBY_OPTS="--debug -X+O"
14
18
  - rvm: ruby-head
15
- - rvm: rbx-3
16
19
  allow_failures:
20
+ - rvm: truffleruby
17
21
  - rvm: ruby-head
18
22
  - rvm: jruby-head
19
- - rvm: rbx-3
data/README.md CHANGED
@@ -26,41 +26,53 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
- This example shows how to generate a certificate for an SSL secured web server:
29
+ This example shows how to generate a certificate for an SSL secured server:
30
30
 
31
31
  ```ruby
32
- require 'localhost/authority'
33
32
  require 'socket'
33
+ require 'thread'
34
+
35
+ require 'localhost/authority'
34
36
 
37
+ # Get the self-signed authority for localhost:
35
38
  authority = Localhost::Authority.fetch
36
39
 
40
+ ready = Thread::Queue.new
41
+
42
+ # Start a server thread:
37
43
  server_thread = Thread.new do
38
44
  server = OpenSSL::SSL::SSLServer.new(TCPServer.new("localhost", 4050), authority.server_context)
39
45
 
40
46
  server.listen
41
47
 
48
+ ready << true
49
+
42
50
  peer = server.accept
43
51
 
44
- puts "Writing..."
52
+ peer.puts "Hello World!"
45
53
  peer.flush
46
54
 
47
55
  peer.close
48
56
  end
49
57
 
58
+ ready.pop
59
+
50
60
  client = OpenSSL::SSL::SSLSocket.new(TCPSocket.new("localhost", 4050), authority.client_context)
51
61
 
52
- # Initialize SSL connection
62
+ # Initialize SSL connection:
53
63
  client.connect
54
64
 
55
- puts client.read
65
+ # Read the encrypted message:
66
+ puts client.read(12)
56
67
 
57
68
  client.close
58
-
59
69
  server_thread.join
60
70
  ```
61
71
 
62
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.
63
73
 
74
+ For an example of how to make your own HTTPS web server, see [examples/https.rb](examples/https.rb).
75
+
64
76
  ### Safari
65
77
 
66
78
  If you use this with a web server, when you open the site in Safari:
@@ -72,7 +84,7 @@ If you use this with a web server, when you open the site in Safari:
72
84
 
73
85
  ### Chrome
74
86
 
75
- If you use this with a web server, when you open the site in Safari:
87
+ If you use this with a web server, when you open the site in Chrome:
76
88
 
77
89
  ![Chrome](media/chrome.png)
78
90
 
@@ -0,0 +1,43 @@
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
@@ -132,7 +132,8 @@ module Localhost
132
132
  end
133
133
 
134
134
  context.set_params(
135
- ciphers: SERVER_CIPHERS
135
+ ciphers: SERVER_CIPHERS,
136
+ verify_mode: OpenSSL::SSL::VERIFY_NONE,
136
137
  )
137
138
  end
138
139
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Localhost
22
- VERSION = "1.1.4"
22
+ VERSION = "1.1.5"
23
23
  end
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.require_paths = ["lib"]
18
18
 
19
+ spec.add_development_dependency "covered"
19
20
  spec.add_development_dependency "bundler", "~> 1.16"
20
21
  spec.add_development_dependency "rake", "~> 10.0"
21
22
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localhost
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-19 00:00:00.000000000 Z
11
+ date: 2019-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: covered
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,12 +73,14 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
76
+ - ".editorconfig"
62
77
  - ".gitignore"
63
78
  - ".rspec"
64
79
  - ".travis.yml"
65
80
  - Gemfile
66
81
  - README.md
67
82
  - Rakefile
83
+ - examples/https.rb
68
84
  - lib/localhost.rb
69
85
  - lib/localhost/authority.rb
70
86
  - lib/localhost/version.rb
@@ -89,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
105
  - !ruby/object:Gem::Version
90
106
  version: '0'
91
107
  requirements: []
92
- rubyforge_project:
93
- rubygems_version: 2.7.6
108
+ rubygems_version: 3.0.3
94
109
  signing_key:
95
110
  specification_version: 4
96
111
  summary: Manage a local certificate authority for self-signed localhost development