cacertreq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +20 -0
  3. data/README +19 -0
  4. data/Rakefile +16 -0
  5. data/VERSION +1 -0
  6. data/bin/cacertreq +40 -0
  7. data/lib/cacert-rq.rb +76 -0
  8. metadata +86 -0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "getopt"
4
+ gem "ruby-debug"
5
+
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ columnize (0.3.4)
5
+ getopt (1.4.0)
6
+ linecache (0.46)
7
+ rbx-require-relative (> 0.0.4)
8
+ rbx-require-relative (0.0.5)
9
+ ruby-debug (0.10.4)
10
+ columnize (>= 0.1)
11
+ ruby-debug-base (~> 0.10.4.0)
12
+ ruby-debug-base (0.10.4)
13
+ linecache (>= 0.3)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ getopt
20
+ ruby-debug
data/README ADDED
@@ -0,0 +1,19 @@
1
+ # Install guide
2
+
3
+ You need some dependancies like ruby1.8 or rubygems to install cacert-requester
4
+ You can install cacert-requester from
5
+ * github
6
+ * rubygems system
7
+
8
+ ## From github
9
+
10
+ $ git clone blabla
11
+ $ cd cacert_requester
12
+ $ sudo gem install bundler
13
+ $ sudo bundle install
14
+ $ ./cacert-requester -s -u user@domain.com
15
+
16
+ ## From rubygems
17
+
18
+ $ sudo gem install cacert-requester
19
+
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "cacertreq"
5
+ gemspec.summary = "Use cacert API for CSR or check an existing account"
6
+ gemspec.description = "Use cacert API for CSR or check an existing account"
7
+ gemspec.email = "thibaut.deloffre@gmail.com"
8
+ gemspec.homepage = "http://github.com/TibshoOT"
9
+ gemspec.authors = ["Thibaut Deloffre"]
10
+ end
11
+ Jeweler::GemcutterTasks.new
12
+ rescue LoadError
13
+ puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
14
+ end
15
+
16
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "rubygems"
4
+ require 'cgi'
5
+ require 'net/http'
6
+ require 'net/https'
7
+ require 'getopt/std'
8
+ require 'cacert-rq'
9
+
10
+ informations = {}
11
+
12
+ begin
13
+ opt = Getopt::Std.getopts("siu:f:e:n:cr:")
14
+ rescue Getopt::Std::Error => e
15
+ puts "Error: #{e}"
16
+ puts CacertApiRequester.usage
17
+ exit
18
+ end
19
+
20
+
21
+ if opt["i"] and !opt["s"]
22
+ informations[:action] = "issue"
23
+ elsif opt["s"] and !opt["i"]
24
+ informations[:action] = "status"
25
+ else
26
+ puts "Error: Which type of action do you like to do ?"
27
+ puts CacertApiRequester.usage
28
+ exit
29
+ end
30
+
31
+ informations[:username] = opt["u"]
32
+ informations[:password] = CacertApiRequester.ask_passwd
33
+ informations[:ca_file] = opt["f"]
34
+ informations[:email] = opt["e"]
35
+ informations[:name] = opt["n"]
36
+ informations[:codesign] = opt["c"]
37
+ informations[:csr] = opt["r"]
38
+
39
+ cacert_instance = CacertApiRequester.new(informations)
40
+ cacert_instance.request
@@ -0,0 +1,76 @@
1
+ class CacertApiRequester
2
+ def initialize(informations)
3
+ @username = informations[:username]
4
+ @password = informations[:password]
5
+ @ca_file = informations[:ca_file]
6
+ @email = email_to_str(informations[:email])
7
+ @name = CGI::escape(informations[:name])
8
+ @codesign = informations[:codesign] ? 1 : 0
9
+ @action = which_action(informations[:action])
10
+ @csr = informations[:csr] ? CGI::escapte(informations[:csr]) : ""
11
+ end
12
+
13
+ def request
14
+ http = Net::HTTP.new("www.cacert.org", 443)
15
+ req = Net::HTTP::Get.new(@action)
16
+ http.use_ssl = true
17
+ if !@ca_file.nil? and !@ca_file.empty? # Force SSL peer verification
18
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
19
+ http.ca_file = @ca_file
20
+ end
21
+ reponse = http.request(req)
22
+ p reponse.body
23
+ end
24
+
25
+ private
26
+
27
+ def self.usage
28
+ puts "To check account status: cacert -s -u user@test.com"
29
+ puts "To make new issue: cacert -i -u user@test.com -e email@lulz.com,email2@lulz.com,emailN@lulz.com -n name1,name2,nameN -c 1|0 [-f ca_file]"
30
+ end
31
+
32
+ def self.ask_passwd
33
+ password = ""
34
+ password_check = ""
35
+ while (password.empty? and password_check.empty?) or password != password_check
36
+ begin
37
+ puts "Password: (no echo)"
38
+ system "stty -echo"
39
+ password = gets.chomp!
40
+ puts "Password checking: (no echo)"
41
+ password_check = gets.chomp!
42
+ ensure
43
+ system "stty echo"
44
+ end
45
+ if password != password_check
46
+ puts "Error: fail to check password, retry."
47
+ end
48
+ end
49
+ password
50
+ end
51
+
52
+ def which_action(action)
53
+ if action == "status"
54
+ ac = "/api/cemails.php?username=#{@username}&password=#{@password}"
55
+ else
56
+ ac = "/api/ccsr.php?username=#{@username}&password=#{@password}#{@email}&name=#{@name}&codesign=#{@codesign}"
57
+ if @csr and !@csr.empty?
58
+ ac.concat("&optionalCSR=#{@csr}")
59
+ end
60
+ end
61
+ ac
62
+ end
63
+
64
+ def email_to_str(mails)
65
+ if !mails.nil?
66
+ i = 0
67
+ m = mails
68
+ mails = ""
69
+ m.strip.split(',').each{ |mail|
70
+ mails << "&email[#{i}]=".concat(mail)
71
+ i += 1
72
+ }
73
+ end
74
+ return mails
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cacertreq
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Thibaut Deloffre
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: getopt
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Use cacert API for CSR or check an existing account
35
+ email: thibaut.deloffre@gmail.com
36
+ executables:
37
+ - cacertreq
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/cacert-rq.rb
44
+ - bin/cacertreq
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - Rakefile
48
+ - README
49
+ - VERSION
50
+ homepage: http://github.com/TibshoOT
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 33
73
+ segments:
74
+ - 1
75
+ - 8
76
+ - 11
77
+ version: 1.8.11
78
+ requirements: []
79
+
80
+ rubyforge_project: cacertreq
81
+ rubygems_version: 1.8.11
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Use cacert API for CSR or check an existing account
85
+ test_files: []
86
+