fix permissions on ruby agent
[monkeysphere-validation-agent.git] / msva.rb
1 #!/usr/bin/env ruby
2
3 require 'rubygems'
4
5 require 'json'
6 require 'openssl'
7 require 'sinatra'
8
9 configure do
10   git_dir = File.join(File.dirname(__FILE__), ".git")
11   if File.directory?(git_dir)
12     head = File.read("#{git_dir}/HEAD").strip.split[-1]
13     @@git_rev = File.read(File.join(git_dir, head))
14   end
15 end
16
17 get '/' do
18   content_type "application/json"
19
20   result = { :available => true, :protoversion => 1, :server => "MSVA-Ruby 0.00001" }
21   result[:git_revision] = @@git_rev if @@git_rev
22   result.to_json
23 end
24
25 post '/reviewcert' do
26   content_type "application/json"
27
28   begin
29     params = JSON.parse(request.body.string)
30   rescue JSON::ParserError
31     halt({ :valid => false, :message => "couldn't parse JSON query"}.to_json)
32   end
33
34   unless (params["pkc"] && params["pkc"]["type"] == "x509der")
35     halt({ :valid => false, :message => "pkc not present or of not-understood type" }.to_json)
36   end
37
38   data = params["pkc"]["data"].pack("C*")
39   pkey = OpenSSL::X509::Certificate.new(data).public_key
40
41   { :valid => false, :message => "Just testing!!" }.to_json
42 end
43
44 # TODO: fill in if we need to do so
45 # post '/extracerts' do
46 # end
47
48 not_found do
49   content_type "application/json"
50
51   { :status => 404, :message => "not found" }.to_json
52 end