csr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d258820a2f7415cff125530786bebbe2cfec58a
4
+ data.tar.gz: 637aa9daa45c9b0357a716e125b7312c3e4d6663
5
+ SHA512:
6
+ metadata.gz: 36cacfabcf3dc150b31c4b4b139b2edd6ccffa29f0576e5505488371f5559b86d5e05fee3ffa60a248332eb01e565950aa6fb71a4125edd7f2778e70233b9f47
7
+ data.tar.gz: 3d11866339acd93406738a1436f673c00eca84b11a187c6c729cbacb719ab66a146153154519d30f28a5ab38746a1ab4efb542175125e05ea2e44f429b25775b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - '2.2'
6
+ - '2.1'
7
+ addons:
8
+ code_climate:
9
+ repo_token:
10
+ secure: "BPmBX98i6pzGOmJfgvXNuCxK1uftL8x8nLKpsuwVx+XM6t2wmtiiTTiT4xUJC0u429+M+7tdIs82KxvkRxu649sK4OFrzaxNKLtVa2cO8Lz8aGQdToJkhEADfaqTlJUn4/GS6gU67C/iPx3I7UYT5s4mK5jNY2Q18glwXrS50GA="
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in csr.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nando Vieira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ # CSR
2
+
3
+ [![Build Status](https://travis-ci.org/fnando/csr.svg)](https://travis-ci.org/fnando/csr)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/csr/badges/gpa.svg)](https://codeclimate.com/github/fnando/csr)
5
+ [![Test Coverage](https://codeclimate.com/github/fnando/csr/badges/coverage.svg)](https://codeclimate.com/github/fnando/csr)
6
+
7
+ Generate CSR (Certificate Signing Request) using Ruby and OpenSSL.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'csr'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install csr
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require 'csr'
29
+
30
+ csr = CSR.new(
31
+ country: 'US',
32
+ state: 'CA',
33
+ city: 'San Francisco',
34
+ department: 'Web',
35
+ organization: 'Example Inc.',
36
+ common_name: 'example.com',
37
+ email: 'john@example.com'
38
+ )
39
+
40
+ csr.pem
41
+ csr.private_key_pem
42
+ csr.save_to '/tmp', 'server'
43
+ #=> creates /tmp/server.csr and /tmp/server.key
44
+ ```
45
+
46
+ To use a passphrase on your private key, do it like this:
47
+
48
+ ```ruby
49
+ csr = CSR.new(
50
+ country: 'US',
51
+ state: 'CA',
52
+ city: 'San Francisco',
53
+ department: 'Web',
54
+ organization: 'Example Inc.',
55
+ common_name: 'example.com',
56
+ email: 'john@example.com',
57
+ passphrase: 'sekret'
58
+ )
59
+ ```
60
+
61
+ You can also verifiy CSR.
62
+
63
+ ```ruby
64
+ # If you did not use a passphrase on your private key
65
+ CSR.verify?(csr_content, pk_content)
66
+
67
+ # If you did use a passphrase on your private key
68
+ CSR.verify?(csr_content, pk_content, passphrase)
69
+ ```
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it ( https://github.com/fnando/csr/fork )
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << 'spec'
6
+ t.test_files = Dir['./spec/**/*_spec.rb']
7
+ end
8
+
9
+ task :default => :spec
10
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "csr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ require './lib/csr/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'csr'
5
+ spec.version = CSR::VERSION
6
+ spec.authors = ['Nando Vieira']
7
+ spec.email = ['fnando.vieira@gmail.com']
8
+ spec.summary = 'Generate CSR (Certificate Signing Request) using Ruby and OpenSSL'
9
+ spec.description = spec.summary
10
+ spec.homepage = 'http://rubygems.org/gems/csr'
11
+ spec.license = 'MIT'
12
+ spec.required_ruby_version = '>= 2.1.0'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.bindir = 'bin'
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler'
20
+ spec.add_development_dependency 'rake'
21
+ spec.add_development_dependency 'minitest'
22
+ spec.add_development_dependency 'minitest-rg'
23
+ spec.add_development_dependency 'pry-meta'
24
+ spec.add_development_dependency 'codeclimate-test-reporter'
25
+ end
@@ -0,0 +1,94 @@
1
+ require 'openssl'
2
+ require 'fileutils'
3
+ require 'csr/version'
4
+
5
+ class CSR
6
+ attr_reader :bits, :country, :state, :city, :department, :organization,
7
+ :common_name, :email, :passphrase, :cipher, :digest
8
+
9
+ def self.verify?(request_key, private_key, passphrase = nil)
10
+ private_key = OpenSSL::PKey::RSA.new(private_key, passphrase)
11
+ csr = OpenSSL::X509::Request.new(request_key)
12
+ csr.public_key = private_key.public_key
13
+ csr.verify(csr.public_key)
14
+ end
15
+
16
+ def initialize(country:, state:, city:, department:, organization:,
17
+ common_name:, email:, bits: 4096, private_key: nil,
18
+ passphrase: nil, cipher: nil, digest: nil)
19
+
20
+ cipher ||= OpenSSL::Cipher::Cipher.new('des-ede3-cbc')
21
+ digest ||= OpenSSL::Digest::SHA256.new
22
+ @country = country
23
+ @state = state
24
+ @city = city
25
+ @department = department
26
+ @organization = organization
27
+ @common_name = common_name
28
+ @email = email
29
+ @bits = bits
30
+ @passphrase = passphrase
31
+ @private_key = OpenSSL::PKey::RSA.new(private_key) if private_key
32
+ @cipher = cipher
33
+ @digest = digest
34
+ end
35
+
36
+ def private_key
37
+ @private_key ||= OpenSSL::PKey::RSA.new(bits)
38
+ end
39
+
40
+ def request
41
+ @request ||= OpenSSL::X509::Request.new.tap do |request|
42
+ request.version = 0
43
+ request.subject = OpenSSL::X509::Name.new([
44
+ ['C', country, OpenSSL::ASN1::PRINTABLESTRING],
45
+ ['ST', state, OpenSSL::ASN1::PRINTABLESTRING],
46
+ ['L', city, OpenSSL::ASN1::PRINTABLESTRING],
47
+ ['O', organization, OpenSSL::ASN1::UTF8STRING],
48
+ ['OU', department, OpenSSL::ASN1::UTF8STRING],
49
+ ['CN', common_name, OpenSSL::ASN1::UTF8STRING],
50
+ ['emailAddress', email, OpenSSL::ASN1::UTF8STRING]
51
+ ])
52
+
53
+ request.public_key = private_key.public_key
54
+ request.sign(private_key, digest)
55
+ end
56
+ end
57
+
58
+ def save_to(directory, name)
59
+ FileUtils.mkdir_p(directory)
60
+ base_path = File.join(directory, name)
61
+ save_private_key_to("#{base_path}.key")
62
+ save_csr_to("#{base_path}.csr")
63
+ true
64
+ end
65
+
66
+ def private_key_pem
67
+ args = []
68
+
69
+ if passphrase
70
+ args << cipher
71
+ args << passphrase
72
+ end
73
+
74
+ private_key.to_pem(*args)
75
+ end
76
+
77
+ def pem
78
+ request.to_pem
79
+ end
80
+
81
+ private
82
+
83
+ def save_private_key_to(path)
84
+ File.open(path, 'w') do |file|
85
+ file << private_key_pem
86
+ end
87
+ end
88
+
89
+ def save_csr_to(path)
90
+ File.open(path, 'w') do |file|
91
+ file << pem
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ class CSR
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nando Vieira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-rg
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-meta
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Generate CSR (Certificate Signing Request) using Ruby and OpenSSL
98
+ email:
99
+ - fnando.vieira@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - csr.gemspec
114
+ - lib/csr.rb
115
+ - lib/csr/version.rb
116
+ homepage: http://rubygems.org/gems/csr
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.1.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.6
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Generate CSR (Certificate Signing Request) using Ruby and OpenSSL
140
+ test_files: []