Skip to content

Commit

Permalink
Moving towards a working application.
Browse files Browse the repository at this point in the history
These commits are very lazy :/
  • Loading branch information
James Hannah committed Nov 21, 2011
1 parent 3c3d9f3 commit 7f15a63
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
uploads/*
*.swp
log/*
*.patch
21 changes: 15 additions & 6 deletions README.mdown
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
SSL Format Converter
====================

A simple web application which allows users to upload SSL
certificates/keys as X509 PEM files or password-protected PKCS7
.DER/.PFX files, and then allows them to download them as PEM or DER
files, regardless of the original upload format.

OpenSSL is used for all the SSL certificate conversion.

Requirements:
* sinatra
* haml
* json
* sqlite3
* openssl (should be included with your ruby distribution)

+ sinatra
+ haml
+ json
+ sqlite3
+ openssl (should be included with your ruby distribution)

Optional:
* httparty (for the client)

+ httparty (for the client)
14 changes: 14 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
environment: production
chdir: /home/jhan/SSL-Converter-Web
address: 127.0.0.1
user: jhan
group: jhan
port: 4567
pid: /home/jhan/SSL-Conveter-Web/sslcon.pid
rackup: /home/jhan/SSL-Converter-Web/sslcon.ru
log: /home/jhan/SSL-Converter-Web/log/sslcon-log
max_conns: 1024
timeout: 30
max_persistent_conns: 512
daemonize: true
2 changes: 1 addition & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ body {
}

.hidden {
display: none;
color: red;
}

#title #nav {
Expand Down
18 changes: 18 additions & 0 deletions read.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h1>SSL Format Converter</h1>
<p>A simple web application which allows users to upload SSL
certificates/keys as X509 PEM files or password-protected PKCS7
.DER/.PFX files, and then allows them to download them as PEM or DER
files, regardless of the original upload format.</p>
<p>OpenSSL is used for all the SSL certificate conversion.</p>
<p>Requirements:</p>
<ul>
<li>sinatra</li>
<li>haml</li>
<li>json</li>
<li>sqlite3</li>
<li>openssl (should be included with your ruby distribution)</li>
</ul>
<p>Optional:</p>
<ul>
<li>httparty (for the client)</li>
</ul>
37 changes: 20 additions & 17 deletions sslcon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ def uniq_name
end
end

enable :sessions

set :public_folder, File.dirname(__FILE__) +'/public'
configure do
enable :sessions
set :static_cache_control, :public
set :public_folder, File.dirname(__FILE__) +'/public'
set :session_secret, '47d292ec431cae6bf26cb772a56ca82859f3766f'
end

helpers do
def init_db
Expand All @@ -52,31 +55,33 @@ def cert_type(filename)
end

def valid_session?
return 401 unless session[:skey]
return 401 unless session[:session_id]
return true # TODO: Implement
end

def user_certificates(key)
ucerts = {}
dbc = get_db
dbc.execute("select cert_pem,key_pem from certs where owner == ?", session[:skey]) do |row|
dbc.execute("select cert_pem,key_pem from certs where owner == ?", session[:session_id]) do |row|
cert_pem = row[0]
cert = OpenSSL::X509::Certificate.new(cert_pem)
key_pem = row[1]
key = OpenSSL::PKey::RSA.new(key_pem)
ucerts[cert.uniq_name] = [cert,key]
end
dbc.close unless dbc.closed?
return ucerts
end

def get_certdata(cert_id)
return 401 unless valid_session?
dbc = get_db
dbc.execute("select cert_pem,key_pem from certs where owner == ?", session[:skey]) do |row|
dbc.execute("select cert_pem,key_pem from certs where owner == ?", session[:session_id]) do |row|
ucert = OpenSSL::X509::Certificate.new(row[0])
ukey = OpenSSL::PKey::RSA.new(row[1])
return [ucert,ukey] if(ucert.uniq_name == cert_id)
end
dbc.close unless dbc.closed?
return false
end
end
Expand All @@ -90,15 +95,10 @@ def get_certdata(cert_id)
before do
cache_control :private
@title = 'SSL Converter!'
logger.info session
end

get '/' do
if session[:skey]
@key = session[:skey]
else
session[:skey] = rand(36**8).to_s(36)
@key = "NEWNEWNEW"
end
haml :index, :format => :html5
end

Expand All @@ -124,7 +124,7 @@ def get_certdata(cert_id)
xcert.not_after.to_i,
xcert.to_pem,
xkey.to_pem,
session[:skey])
session[:session_id])
certok = true
when :pkcs12
raise ArgumentError unless params[:certpass]
Expand All @@ -138,13 +138,14 @@ def get_certdata(cert_id)
xcert.not_after.to_i,
xcert.to_pem,
xkey.to_pem,
session[:skey])
session[:session_id])
certok = true
else
certok = false
# TODO: error?
end
ensure
dbc.close unless dbc.closed?
tempfile.close
end
redirect "/process" if certok
Expand Down Expand Up @@ -204,7 +205,7 @@ def get_certdata(cert_id)
return 401 unless valid_session?
targetid = -1
dbc = get_db
rows = dbc.execute("select cert_pem,id from certs where owner == ?", session[:skey])
rows = dbc.execute("select cert_pem,id from certs where owner == ?", session[:session_id])
p rows
rows.each do |row|
ucert = OpenSSL::X509::Certificate.new(row[0])
Expand All @@ -217,11 +218,13 @@ def get_certdata(cert_id)
end
logger.info "TARGETID is #{targetid}"
if targetid.to_i >= 0
res = dbc.execute("delete from certs where owner == ? and id == ?", session[:skey],targetid)
res = dbc.execute("delete from certs where owner == ? and id == ?", session[:session_id],targetid)
dbc.close unless dbc.closed?
return "OK" if res.length > 0
status 404
"Certificate Not Deleted"
end
dbc.close unless dbc.closed?
status 404
"Certificate Not in DB"
end
Expand All @@ -232,7 +235,7 @@ def get_certdata(cert_id)
end

get '/process' do
@key = session[:skey]
@key = session[:session_id]
@certs = user_certificates(@key)
redirect "/" unless valid_session?
haml :process
Expand Down
7 changes: 7 additions & 0 deletions sslcon.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'sinatra'

set :environment, :production
disable :run

require 'sslcon'
run Sinatra::Application
Binary file modified sslconverter.sqlite3.db
Binary file not shown.

0 comments on commit 7f15a63

Please sign in to comment.