Permalink
Browse files

serve dotjs over local ssl

  • Loading branch information...
1 parent fe63c10 commit 130d106e732331ed46b580cd2c94169e0fb55aff @defunkt committed Jan 17, 2013
Showing with 52 additions and 4 deletions.
  1. +2 −0 README.markdown
  2. +2 −2 Rakefile
  3. +47 −1 bin/djsd
  4. +1 −1 ext/dotjs.js
View
@@ -68,6 +68,8 @@ the returned JavaScript.
cd dotjs
rake install
+Now open https://localhost:3131 in Chrome and enable the SSL.
+
Then install the Google Chrome extension:
http://bit.ly/dotjs
View
@@ -29,9 +29,9 @@ namespace :install do
end
task :done do
- if system("curl http://localhost:3131 &> /dev/null")
+ if system("curl -k https://localhost:3131 &> /dev/null")
puts "\e[1m\e[32mdotjs installation worked\e[0m"
- puts "drag builds/dotjs.crx to Google Chrome"
+ puts "open https://localhost:3131 in chrome to enable ssl"
puts "then drop files like google.com.js in ~/.js and enjoy hacking the web"
else
puts "\e[31mdotjs installation failed\e[0m"
View
@@ -12,6 +12,7 @@ if ARGV.include?('-v')
end
require 'webrick'
+require 'webrick/https'
dotjs = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
def do_GET(request, response)
@@ -55,11 +56,56 @@ dotjs = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
end
end
-server = WEBrick::HTTPServer.new(:BindAddress => "127.0.0.1", :Port => 3131, :AccessLog => [])
+ssl_info = DATA.read
+ssl_cert = ssl_info.scan(/(-----BEGIN CERTIFICATE-----.+?-----END CERTIFICATE-----)/m)[0][0]
+ssl_key = ssl_info.scan(/(-----BEGIN RSA PRIVATE KEY-----.+?-----END RSA PRIVATE KEY-----)/m)[0][0]
+
+server_options = {
+ :BindAddress => "127.0.0.1",
+ :Port => 3131,
+ :AccessLog => [],
+ :SSLEnable => true,
+ :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
+ :SSLPrivateKey => OpenSSL::PKey::RSA.new(ssl_key),
+ :SSLCertificate => OpenSSL::X509::Certificate.new(ssl_cert),
+ :SSLCertName => [["CN", WEBrick::Utils::getservername]],
+}
+
+server = WEBrick::HTTPServer.new(server_options)
server.mount('/', dotjs)
%w( INT TERM ).each do |sig|
trap(sig) { server.shutdown }
end
server.start
+
+__END__
+-----BEGIN CERTIFICATE-----
+MIIB9TCCAV4CCQCO1/0PIZhK/jANBgkqhkiG9w0BAQUFADA/MQswCQYDVQQGEwJV
+UzETMBEGA1UECBMKQ2FsaWZvcm5pYTELMAkGA1UEBxMCU0YxDjAMBgNVBAoTBWRv
+dGpzMB4XDTEzMDExNzE4MDQyNVoXDTE0MDExNzE4MDQyNVowPzELMAkGA1UEBhMC
+VVMxEzARBgNVBAgTCkNhbGlmb3JuaWExCzAJBgNVBAcTAlNGMQ4wDAYDVQQKEwVk
+b3RqczCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAzWNyNzpcDXkZMe3kZPHD
+9Uk3I/y/Ak3v4yavl7MvIFaLwjOE8lSBxnkhZJQx7/4SxME/dC2qBskAS9H9PCHa
+o5Ae8CDxgOrKQthhgQdiO3uSUhg1w8EpMxdzngU0pQdHPZNM0rEKfC6qG6dKeH7N
+vPIC4IYPiJqO+g6TIzWkklMCAwEAATANBgkqhkiG9w0BAQUFAAOBgQA5KDuyJmUf
+GOzglLQEXueRFEcHF7b+ltom3lZUtluhQk/wWLwJybs+VwHJFGtGOWrQkf4nRkwU
+HOQgbx0NCQgin1HPiPSOIRcRR0L4bJdvSt8sVBLhhTWZ0w4sa9lfNsbadGPpJPrr
+ywvVjgvlZ/3qa1O7r70Hwb5up4KAG65a2A==
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIICWwIBAAKBgQDNY3I3OlwNeRkx7eRk8cP1STcj/L8CTe/jJq+Xsy8gVovCM4Ty
+VIHGeSFklDHv/hLEwT90LaoGyQBL0f08IdqjkB7wIPGA6spC2GGBB2I7e5JSGDXD
+wSkzF3OeBTSlB0c9k0zSsQp8Lqobp0p4fs288gLghg+Imo76DpMjNaSSUwIDAQAB
+AoGAe2YHRlVC3zllwNDMCzYSZPmzLmT5IdpPiWtBzmPyqXw2BdzMQIgzXFqEjJhZ
+FHbTMfFlPVj+MYtsKSGmAw3X/J/ZwM/VOzjuAa9ygeJWW7EJwzxJmb4lG8yQeSbQ
+cBNCWPtgRRUflD7v1fCuOJ4DzEd5Bb3kTBfyEKShcVy8QVECQQDn35JjYtDkLF3U
+VkaF4QyCWqgOmr3X+pNoSW3Yx2I+jp2HG3qHY5fV0B0PNpdencdpWn/kG5+pMb00
+V8InmtV5AkEA4sJlFVxsaIXPB+45CZt2dLSkdyA4jaqv+rYi/jJZyDsXSd174ukM
+u0j4jPwiN9S2xAc79tf/q7mEdNh7yB2vKwJAD7AOpW7AF0/xITadGt25DPC5QhOy
+GHS5mGqvZeVHflgDzGpNhe91DGBCNw9IenxOS5B16qb7zGSzGmF9n1RYcQJAR0+e
+/mK8bPp3qyTNpynOzNDqT9RANL0S7qNMyegHuCJtJnuStD9aE6PVFnFMSYaJm4gy
+4WP4MYb8Esrp0nsTVQJAPvvZpLdYoDXPGtOHaMB19i3z7XEMohQpGiUvA+J5wjOa
+smJzPv9APXqdZoo6NB+4EOk6dwpkXo5k65SunSpO8Q==
+-----END RSA PRIVATE KEY-----
View
@@ -1,5 +1,5 @@
$.ajax({
- url: 'http://localhost:3131/'+location.hostname.replace(/^www\./,'')+'.js',
+ url: 'https://localhost:3131/'+location.hostname.replace(/^www\./,'')+'.js',
dataType: 'text',
success: function(d){
$(function(){ eval(d) })

1 comment on commit 130d106

@richo
richo commented on 130d106 Jun 7, 2013

Was this to avoid mixed content warnings?

Please sign in to comment.