Initial work on encryption support
This commit is contained in:
parent
9c221f8f5e
commit
7946d26e37
3
Gemfile
3
Gemfile
|
@ -1,10 +1,13 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
gem 'sinatra'
|
||||
gem 'encryption'
|
||||
gem 'public_suffix'
|
||||
|
||||
group :test do
|
||||
gem 'minitest'
|
||||
gem 'mina'
|
||||
gem 'rerun'
|
||||
end
|
||||
|
||||
group :production do
|
||||
|
|
18
Gemfile.lock
18
Gemfile.lock
|
@ -2,16 +2,29 @@ GEM
|
|||
remote: https://rubygems.org/
|
||||
specs:
|
||||
daemons (1.2.3)
|
||||
encryption (1.1.8)
|
||||
eventmachine (1.0.8)
|
||||
ffi (1.9.14)
|
||||
listen (3.1.5)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
ruby_dep (~> 1.2)
|
||||
mina (0.3.7)
|
||||
open4 (~> 1.3.4)
|
||||
rake
|
||||
minitest (5.7.0)
|
||||
open4 (1.3.4)
|
||||
public_suffix (2.0.3)
|
||||
rack (1.6.4)
|
||||
rack-protection (1.5.3)
|
||||
rack
|
||||
rake (10.4.2)
|
||||
rb-fsevent (0.9.8)
|
||||
rb-inotify (0.9.7)
|
||||
ffi (>= 0.5.0)
|
||||
rerun (0.11.0)
|
||||
listen (~> 3.0)
|
||||
ruby_dep (1.5.0)
|
||||
sinatra (1.4.6)
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
|
@ -26,10 +39,13 @@ PLATFORMS
|
|||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
encryption
|
||||
mina
|
||||
minitest
|
||||
public_suffix
|
||||
rerun
|
||||
sinatra
|
||||
thin
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.5
|
||||
1.13.6
|
||||
|
|
18
app.rb
18
app.rb
|
@ -2,6 +2,8 @@ require 'rubygems'
|
|||
require 'bundler/setup'
|
||||
require 'sinatra'
|
||||
require 'yaml'
|
||||
require 'encryption'
|
||||
require './lightsaber'
|
||||
|
||||
def get_url(domain_object, rel_route)
|
||||
if domain_object.is_a? Hash
|
||||
|
@ -11,6 +13,22 @@ def get_url(domain_object, rel_route)
|
|||
end
|
||||
end
|
||||
|
||||
get '/lightsaber' do
|
||||
# pass unless request.host == 'lightsaber.captnemo.in'
|
||||
|
||||
erb :index
|
||||
end
|
||||
|
||||
post '/lightsaber/encrypt' do
|
||||
domain = request.params['domain']
|
||||
status = request.params['status']
|
||||
redirect = request.params['redirect_url']
|
||||
root = request.params['root']
|
||||
|
||||
puts [domain, status, redirect, root]
|
||||
Lightsaber.encrypt(domain, status, redirect, root)
|
||||
end
|
||||
|
||||
get '/*' do
|
||||
hostname = request.host
|
||||
route = params[:splat][0]
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,9C69FE6141CA092A
|
||||
|
||||
ES5GygH8ozr/+ZwWYCXltOFIZYNhjxOEqrbANraZBfpzNpsrERoc96GHEiKcnxro
|
||||
tACEsRj7M+ywmRYBnXh+3i+mCcfFgfeqxITo7WO9U1kP9eo8woUTKrFDND6YrwA9
|
||||
RU47j1xOifPmUnx2sFXiwRe2eDGrxgf1K/13ADEnQZDnIi8rjFgv6Ix6RfzvmFH0
|
||||
90b13e3JuLHb/QwN0LDet9W1ceIhinxO6vwYW9C6Plst4JgejIzmvz9vP8TsuIaH
|
||||
1VKjb/3SaAONVmE1T2vpa2K51jlnRMuLQZKuZwA6J7HvSoUcbhEjwH8+4ifZjAUz
|
||||
aq0YbWHE8kvJvQ+mFxvmZvfUso9PSqU6bTIcpW2wJ8hqjeQjzqaBc2V0viw2lIcn
|
||||
aIMIL10z81D36H4BLKiI+kxhqQUYR3GWCGLlVYLGO+yDXFdnfLb3vcUgyiWkJMfk
|
||||
8R8Y/1zvDctvBrqAvo1Ee0R1P6kLrXYla2oOSUzJ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y6+hRJw5YR9R
|
||||
xKHJxDyUkbWU2AzQc+ERZV69pOvFlj0dIc39hCu1DTGdyWyd5ljSnqGmiKfrrMoA
|
||||
x9c2kSK3DgUuZa5rDVkOvm1/5I+NthvGTm2ktRv9iKkbsR0hFcXTic9suZCKsrvi
|
||||
-----END RSA PRIVATE KEY-----
|
|
@ -0,0 +1,9 @@
|
|||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArw/B62WeQ+5XQbfVAZNb
|
||||
S0Opia9+pAyBnODE1eMpB6/3heE/HdTIexYP9B0uuwbM/aQyEBEs60u8G8JvwSMd
|
||||
+FO7nLT0PcC2uQi9RrNeuapkirWo9+QRso1Gd06N0vZAwZVf8Zn7qGBY4k3wGMbP
|
||||
Aw+ujQH1G2aBpoOqH2bqf0nSG+15jUSaQNOyhL8q+4GmBpu8hWHxCSU5uTOFUszn
|
||||
J8bAIKuokhl/pPsyXVMxGkWs81d7/oXvZfvJkw9aeGrKgOmsEsYJlI7QNH8j0tC/
|
||||
ED5H0f+uaKDz7rsDYCeUvKfgd9m5PI7utLDL7Di4C8/c/bGf129SIoyufb32nWqG
|
||||
IwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
|
@ -0,0 +1,27 @@
|
|||
require 'public_suffix'
|
||||
require 'json'
|
||||
require 'base64'
|
||||
|
||||
class Lightsaber
|
||||
def self.encrypt(domain, status, redirect, root)
|
||||
status = status.to_s
|
||||
raise 'Either redirect or root must be provided' if redirect.nil? and root.nil?
|
||||
raise 'Invalid Status' if (status!='301' and status !='302')
|
||||
raise 'Invalid Domain' unless PublicSuffix.valid?(domain, ignore_private: true)
|
||||
|
||||
str = prepare_private_hash(domain, status, redirect, root)
|
||||
|
||||
public_key = Encryption::PublicKey.new('keys/public.pem')
|
||||
return Base64.encode64 public_key.encrypt str
|
||||
end
|
||||
|
||||
def self.prepare_private_hash(domain, status, redirect, root)
|
||||
h = Hash.new
|
||||
if redirect.nil?
|
||||
h[domain] = {status: status, root: root, contact: '@captn3m0'}
|
||||
else
|
||||
h[domain] = {status: status, redirect: redirect, contact: '@captn3m0'}
|
||||
end
|
||||
str = h.to_json
|
||||
end
|
||||
end
|
|
@ -15,3 +15,9 @@
|
|||
fb.captnemo.in: https://facebook.com/captn3m0
|
||||
where.rzp.io: https://goo.gl/maps/1A9nhMPzehS2
|
||||
where.razorpay.com: https://goo.gl/maps/1A9nhMPzehS2
|
||||
# encrypted:
|
||||
# - domain:
|
||||
# location: https://google.com
|
||||
# status: 3xx
|
||||
# root: https://twitter.com
|
||||
# contact: @captn3m0
|
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://yegor256.github.io/tacit/tacit.min.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<section>
|
||||
<header>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><code><h2>lightsaber</h2></code></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<article>
|
||||
<h3>Encryption</h3>
|
||||
<p>You can find more about lightsaber at
|
||||
<a href="https://lightsaber.captnemo.in">lightsaber.captnemo.in</a>.
|
||||
</p>
|
||||
<p>This page exists to help you with the encryption</p>
|
||||
<form action="/lightsaber/encrypt" method="post">
|
||||
<fieldset>
|
||||
<label for="domain">
|
||||
Domain to redirect
|
||||
<input type="text" name="domain" size="60" placeholder="code.captnemo.in">
|
||||
</label>
|
||||
|
||||
<label for="status">
|
||||
Redirect Type:
|
||||
<select name="status">
|
||||
<option value="301">Permanent (301)</option>
|
||||
<option value="302">Temporary (302)</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<h3>You must fill either the Redirect URL or the Root</h3>
|
||||
<label for="redirect_url">
|
||||
Redirect URL (Must be a link)
|
||||
<input type="url" name="redirect_url" size="60" placeholder="https://github.com/captn3m0">
|
||||
</label>
|
||||
|
||||
|
||||
<label for="root">
|
||||
Optional Root:
|
||||
<input type="text" name="root" size="60" placeholder="https://github.com/captn3m0">
|
||||
<span>No leading slash needed</span>
|
||||
</label>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
</fieldset>
|
||||
</form>
|
||||
</article>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue