localhost 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -1
- data/lib/localhost/authority.rb +29 -19
- data/lib/localhost/version.rb +1 -1
- data/media/chrome.png +0 -0
- data/media/safari.png +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdb38bb72334de27b11b1eee998475657887f85f47f81a44b31888964d9fe88d
|
4
|
+
data.tar.gz: c71c4fa7959047645b0508145f3f9e6b9e6ee6fd42a54b009dd2cb5e7c1ef0c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8e4444acb08913da2359a9780869bdfdad35329a037822552d8f13a9c352fff51388a7070626c394d5ab7bbded237444e859aae68571e871e99d69ff8ad3503
|
7
|
+
data.tar.gz: 0cd28c7367ab533aa99a5dda6b4dc05485b6a8c79dd35ed68782ba29eb10fe16fe99d067e1bd13d99056cd9539600c228ecb8567f909bf96ffa3e5a5826f4076
|
data/README.md
CHANGED
@@ -61,9 +61,27 @@ server_thread.join
|
|
61
61
|
|
62
62
|
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
63
|
|
64
|
+
### Safari
|
65
|
+
|
66
|
+
If you use this with a web server, when you open the site in Safari:
|
67
|
+
|
68
|
+
![Safari](media/safari.png)
|
69
|
+
|
70
|
+
- Click "View the certificate" to check that it is the correct certificate.
|
71
|
+
- 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.
|
72
|
+
|
73
|
+
### Chrome
|
74
|
+
|
75
|
+
If you use this with a web server, when you open the site in Safari:
|
76
|
+
|
77
|
+
![Chrome](media/chrome.png)
|
78
|
+
|
79
|
+
- Click "ADVANCED" to see additional details, including...
|
80
|
+
- Click "Proceed to localhost (unsafe)" which will allow you to use the site for the current browser session.
|
81
|
+
|
64
82
|
### Files
|
65
83
|
|
66
|
-
The certificate and private key are stored in `~/.localhost/`.
|
84
|
+
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.
|
67
85
|
|
68
86
|
## Contributing
|
69
87
|
|
data/lib/localhost/authority.rb
CHANGED
@@ -50,13 +50,21 @@ module Localhost
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def key
|
53
|
-
@key ||= OpenSSL::PKey::RSA.new(1024)
|
53
|
+
@key ||= OpenSSL::PKey::RSA.new(1024*2)
|
54
|
+
end
|
55
|
+
|
56
|
+
def key= key
|
57
|
+
@key = key
|
54
58
|
end
|
55
59
|
|
56
60
|
def name
|
57
61
|
@name ||= OpenSSL::X509::Name.parse("O=Development/CN=#{@hostname}")
|
58
62
|
end
|
59
63
|
|
64
|
+
def name= name
|
65
|
+
@name = name
|
66
|
+
end
|
67
|
+
|
60
68
|
def certificate
|
61
69
|
@certificate ||= OpenSSL::X509::Certificate.new.tap do |certificate|
|
62
70
|
certificate.subject = self.name
|
@@ -66,6 +74,7 @@ module Localhost
|
|
66
74
|
certificate.public_key = self.key.public_key
|
67
75
|
|
68
76
|
certificate.serial = 1
|
77
|
+
certificate.version = 2
|
69
78
|
|
70
79
|
certificate.not_before = Time.now
|
71
80
|
certificate.not_after = Time.now + (3600 * 24 * 365 * 10)
|
@@ -74,11 +83,13 @@ module Localhost
|
|
74
83
|
extension_factory.subject_certificate = certificate
|
75
84
|
extension_factory.issuer_certificate = certificate
|
76
85
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
certificate.extensions = [
|
87
|
+
extension_factory.create_extension("basicConstraints", "CA:FALSE", true),
|
88
|
+
extension_factory.create_extension("subjectKeyIdentifier", "hash"),
|
89
|
+
]
|
90
|
+
|
91
|
+
certificate.add_extension extension_factory.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
|
92
|
+
certificate.add_extension extension_factory.create_extension("subjectAltName", "DNS: #{@hostname}")
|
82
93
|
|
83
94
|
certificate.sign self.key, OpenSSL::Digest::SHA256.new
|
84
95
|
end
|
@@ -99,10 +110,6 @@ module Localhost
|
|
99
110
|
context.session_id_context = "localhost"
|
100
111
|
|
101
112
|
context.set_params
|
102
|
-
|
103
|
-
if context.respond_to? :verify_hostname=
|
104
|
-
context.verify_hostname = false
|
105
|
-
end
|
106
113
|
end
|
107
114
|
end
|
108
115
|
|
@@ -113,21 +120,24 @@ module Localhost
|
|
113
120
|
context.set_params(
|
114
121
|
verify_mode: OpenSSL::SSL::VERIFY_PEER,
|
115
122
|
)
|
116
|
-
|
117
|
-
if context.respond_to? :verify_hostname=
|
118
|
-
context.verify_hostname = false
|
119
|
-
end
|
120
123
|
end
|
121
124
|
end
|
122
125
|
|
123
126
|
def load(path)
|
124
|
-
if File.directory? path
|
127
|
+
if File.directory? path
|
128
|
+
certificate_path = File.join(path, "#{@hostname}.crt")
|
125
129
|
key_path = File.join(path, "#{@hostname}.key")
|
126
|
-
return false unless File.exist?(key_path)
|
127
|
-
@key = OpenSSL::PKey::RSA.new(File.read(key_path))
|
128
130
|
|
129
|
-
|
130
|
-
|
131
|
+
return false unless File.exist?(certificate_path) and File.exist?(key_path)
|
132
|
+
|
133
|
+
certificate = OpenSSL::X509::Certificate.new(File.read(certificate_path))
|
134
|
+
key = OpenSSL::PKey::RSA.new(File.read(key_path))
|
135
|
+
|
136
|
+
# Certificates with old version need to be regenerated.
|
137
|
+
return false if certificate.version < 2
|
138
|
+
|
139
|
+
@certificate = certificate
|
140
|
+
@key = key
|
131
141
|
|
132
142
|
return true
|
133
143
|
end
|
data/lib/localhost/version.rb
CHANGED
data/media/chrome.png
ADDED
Binary file
|
data/media/safari.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localhost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
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-
|
11
|
+
date: 2018-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,8 @@ files:
|
|
69
69
|
- lib/localhost/authority.rb
|
70
70
|
- lib/localhost/version.rb
|
71
71
|
- localhost.gemspec
|
72
|
+
- media/chrome.png
|
73
|
+
- media/safari.png
|
72
74
|
homepage: https://github.com/socketry/localhost
|
73
75
|
licenses: []
|
74
76
|
metadata: {}
|