ekey 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ tags
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ekey.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dmitry Koprov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Ekey
2
+
3
+ A ruby wrapper for API of the ekey.ru
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ekey'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ekey
18
+
19
+ ## Usage
20
+
21
+ ### api_key setup
22
+
23
+ First of all, setup `api_key`. To do this, put a file `ekey.rb` into rails config/initializers directory.
24
+
25
+ Ekey::Config.api_key = <your_api_key>
26
+
27
+ If you aren't using rails, just make shure, api_key fills in before any API methods calls.
28
+
29
+ ### Sending certificate request
30
+
31
+ To send certificate request (csr) to the certificate authority CA, use the `CSR.issue` method
32
+
33
+ Ekey::Certificate.issue(csr)
34
+
35
+ Where the `csr` parameter is the signed certificate request in the `pem` format.
36
+ Here is shortened example of the csr in pem format:
37
+
38
+ -----BEGIN CERTIFICATE REQUEST-----\nMIICTzCCAfwCAQAwggFEMT0wOwYDVQQDHjQEEAQ7BDUEOgRBBDAEPQQ0BEAAIAQfBDAEMgQ7BD4EMgQ4BEcAIAQSBDAEMgQ4BDsEPgQyMRUwEwYYVQUHHgwGHPQ\n-----END CERTIFICATE REQUEST-----
39
+
40
+ Result: a ruby Hash, in format: `{"created_request_id" => <number>}` or `{"error" => <message>}`.
41
+
42
+ ### Getting issued certificates by request ids
43
+
44
+ In order to get issued certificates use
45
+
46
+ Ekey::Certificate.get_certificates(request_ids)
47
+
48
+ Where request_ids is a collection of all request ids of the pending certificates in your application. It can be a String, Array or just one Fixnum.
49
+
50
+ Response: a JSON in format `[{"id" => <request_id>, "certificate" => <certificate_body>}]`, or if the certificate is'n issued yet - `[{"id" => <request_id>, "error" => "certificate is not ready yet"}]`. Response can contain both of this as well.
51
+
52
+ Note, that certificate is the only base64 string without BEGIN CERTIFICATE/END CERTIFICATE splitted by 64 characters.
53
+ Here is the shortened sample of the certificate value:
54
+
55
+ MIIDZjCCAxOgAwIBAgIKXaz9BwAAAADF1jAKBgYqhQMCAgMFADCBkjEeMBwGCSqG\nSIb3DQEJARYPY29udGFjdEBla2V5LnJ1MQswCQYDVQQGEwJSVTEVMBMGA1UEBwwM\n0JzQvtGB0LrQstCwMTcwNQYDVQQKn8HsQFSfy9BDG+A==\n
56
+
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork.
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
65
+
66
+
67
+ Copyright (c) 2012 by Dmitry Koprov (dkoprov), evrone.com
68
+
69
+ This project uses MIT LICENSE
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/ekey.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ekey/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dmitry Koprov"]
6
+ gem.email = ["dmitry.koprov@gmail.com"]
7
+ gem.description = %q{A ruby wrapper for API of the ekey.ru}
8
+ gem.summary = %q{A ruby wrapper for API of the ekey.ru}
9
+ gem.homepage = "https://github.com/dkoprov/ekey"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "ekey"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Ekey::VERSION
17
+
18
+ gem.add_dependency "json_pure"
19
+ gem.add_dependency "rest-client"
20
+
21
+ end
@@ -0,0 +1,47 @@
1
+ # Модуль Certificate отвечает за отправление запроса на сертификат (CSR) и получение готового сертификата.
2
+ #
3
+ # Комплекс взаимодействия с ekey.ru:
4
+ # - issue -- отправляет запрос на выпуск сертификата
5
+ # на вход: csr в формате pem
6
+ # ответ: ruby hash в формате {"created_request_id" => <number>} или {"error" => <message>}
7
+ # - get_certificates -- забирает с Удостоверяющего центра (УЦ, CA) готовые сертификаты
8
+ # на вход: id сертификатов в очереди на выпуск (request_ids)
9
+ # ответ: json в формате [{"id" => <request_id>, "certificate" => <certificate_body>},
10
+ # если серт. еще не выпущен - {"id" => <request_id>, "error" => "certificate is not ready yet"}]
11
+
12
+ require 'rest_client'
13
+ require 'json'
14
+
15
+ module Ekey
16
+ class Certificate
17
+ CA_UPLOAD_PAGE_URL = "http://cabinet.ekey.ru/api/1.0/request/put"
18
+ CA_DOWNLOAD_PAGE_URL = "http://cabinet.ekey.ru/api/1.0/certificates/get"
19
+
20
+ CERTIFICATE_LINE_LENGTH = 64
21
+
22
+ # Делит длинную строку base64 на строки по 64 символа.
23
+ # Это требование cabinet.ekey.ru к запросам на выпуск сертификата (CSR).
24
+ def self.add_container_to_csr(cert_req)
25
+ stripted_body = cert_req.gsub("-----BEGIN CERTIFICATE REQUEST-----", '').gsub("-----END CERTIFICATE REQUEST-----", '').gsub(/[\r\n\s]/, '')
26
+ parts = stripted_body.scan(/.{1,#{CERTIFICATE_LINE_LENGTH}}/)
27
+ csr_with_container = "-----BEGIN CERTIFICATE REQUEST-----\n#{parts.join("\n")}\n-----END CERTIFICATE REQUEST-----"
28
+ end
29
+
30
+ def self.issue(csr)
31
+ upload_responce = RestClient.post(CA_UPLOAD_PAGE_URL,
32
+ { :api_key => Ekey::Config.api_key,
33
+ :pkcs10 => add_container_to_csr(csr) },
34
+ :multipart => true)
35
+ JSON(upload_responce)
36
+ end
37
+
38
+ def self.get_certificates(ca_request_ids)
39
+ id_list = Array(ca_request_ids).join(', ')
40
+ ca_responce = RestClient.post(CA_DOWNLOAD_PAGE_URL, { :api_key => Ekey::Config.api_key,
41
+ :id_list => id_list })
42
+ JSON(ca_responce)
43
+ end
44
+
45
+ end
46
+ end
47
+
@@ -0,0 +1,3 @@
1
+ module Ekey
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ekey.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "ekey/certificate"
2
+
3
+ module Ekey
4
+ module Config
5
+ # API_KEY for cabinet.ekey.ru.
6
+ mattr_accessor :api_key
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ekey
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Dmitry Koprov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-13 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json_pure
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
+ - !ruby/object:Gem::Dependency
35
+ name: rest-client
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: A ruby wrapper for API of the ekey.ru
49
+ email:
50
+ - dmitry.koprov@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - ekey.gemspec
64
+ - lib/ekey.rb
65
+ - lib/ekey/certificate.rb
66
+ - lib/ekey/version.rb
67
+ homepage: https://github.com/dkoprov/ekey
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.10
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: A ruby wrapper for API of the ekey.ru
100
+ test_files: []
101
+