fauthentic 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84920a8d49a40829e6ab3734dd23a98e74ac5b02
4
+ data.tar.gz: 94e5db1704ff2e23a04f5b3bda85c07d9d42ab1f
5
+ SHA512:
6
+ metadata.gz: 7f1af9c7a590ff5e2f2f08e89602c44c5d9de874d7a518029c2dfc44981b66126f9f117c0b89ff4bfa2dbb0534b706701edfa8c944d42f9400dcf301b0a92648
7
+ data.tar.gz: aa17d03bede3308c0d16f11b69672249b88a5302d97e465f11125344de75670722199800943d2fd6b2ff7e65e4854f1b3f67f4e061718e416d8b208c83195aef
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fauthentic.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Joe Marty
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # Fauthentic
2
+
3
+ Fauthentic is a gem designed for the sole purpose of making it easy to generate
4
+ and handle self-signed SSL certificates in Ruby.
5
+
6
+ It uses the OpenSSL library, and therefore the primary `generate` method returns
7
+ an object containing a cert and key represented as `OpenSSL::X509::Certificate`
8
+ and `OpenSSL::PKey::RSA`.
9
+
10
+ ## Thanks
11
+
12
+ Thanks to @nickyp for posting his original [script for generating a self-signed
13
+ certificate](https://gist.github.com/nickyp/886884), from which this library
14
+ grew.
15
+
16
+ ## Usage
17
+
18
+ It's pretty simple:
19
+
20
+ **Want a Certificate?**
21
+
22
+ ```ruby
23
+ ssl = Fauthentic.generate
24
+ puts ssl.cert.to_pem
25
+ # => -----BEGIN CERTIFICATE----- ...
26
+ puts ssl.key.to_s
27
+ # => -----BEGIN RSA PRIVATE KEY----- ...
28
+ ```
29
+
30
+ **Want to be more specific?**
31
+
32
+ ```ruby
33
+ opts = {
34
+ common_name: "my.domain.com", # Default: "example.com"
35
+ country: "BE", # "US"
36
+ state: "saddened", # nil
37
+ org: "MyOrg", # "Test"
38
+ org_unit: "Test", # "Test"
39
+ email: "totally-secure-team@my.domain.com", # nil
40
+ expire_in_days: 365 # 30
41
+ }
42
+ ssl = Fauthentic.generate(opts)
43
+ cert_string = ssl.cert.to_pem
44
+ # => "-----BEGIN CERTIFICATE-----..."
45
+ key_string = ssl.key.to_s
46
+ # => "-----BEGIN RSA PRIVATE KEY----- ..."
47
+ ```
48
+
49
+ **Want to read a certificate?**
50
+
51
+ ```ruby
52
+ cert = Fauthentic.parse_cert(cert_string)
53
+ puts Fauthentic.extract_subject(cert)
54
+ # => {C: "US", O: "MyOrg", CN: "my.domain.com", ...}
55
+ ```
56
+
57
+ **Want to make sure a key matches a certificate?**
58
+ Just use the openssl gem's `check_private_key` method:
59
+
60
+ ```ruby
61
+ key = Fauthentic.parse_key(key_string)
62
+ cert.check_private_key(key) # => true
63
+ ```
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fauthentic"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fauthentic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fauthentic"
8
+ spec.version = Fauthentic::VERSION
9
+ spec.authors = ["Joe Marty"]
10
+ spec.email = ["jmarty@iexposure.com"]
11
+
12
+ spec.summary = "A convenience library for self-signed SSL certificates"
13
+ spec.description = "Fauthentic allows you to easily generate, read, parse and verify OpenSSL certificates and keys"
14
+ spec.homepage = "https://github.com/mltsy/fauthentic"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.14"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.2"
26
+
27
+ spec.add_runtime_dependency 'openssl', '~> 2.0'
28
+ end
@@ -0,0 +1,61 @@
1
+ require 'fauthentic/version'
2
+ require 'openssl'
3
+
4
+ module Fauthentic
5
+ DEFAULT_OPTIONS = {
6
+ country: "US",
7
+ state: nil,
8
+ org: "Fauxthentic",
9
+ org_unit: "Test",
10
+ common_name: "test.example.com",
11
+ email: nil,
12
+ expire_in_days: 30
13
+ }
14
+
15
+ SslData = Struct.new(:cert, :key)
16
+
17
+ def self.generate(opts = {})
18
+ options = DEFAULT_OPTIONS.merge(opts)
19
+
20
+ key = OpenSSL::PKey::RSA.new(2048)
21
+
22
+ subject = ""
23
+ subject << "/C=#{options[:country]}" if options[:country]
24
+ subject << "/ST=#{options[:state]}" if options[:state]
25
+ subject << "/O=#{options[:org]}" if options[:org]
26
+ subject << "/OU=#{options[:org_unit]}" if options[:org_unit]
27
+ subject << "/CN=#{options[:common_name]}" if options[:common_name]
28
+ subject << "/emailAddress=#{options[:email]}" if options[:email]
29
+
30
+ cert = OpenSSL::X509::Certificate.new
31
+ cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject)
32
+ cert.not_before = Time.now
33
+ cert.not_after = Time.now + options[:expire_in_days] * 24 * 60 * 60
34
+ cert.public_key = key.public_key
35
+ cert.serial = 0x0
36
+ cert.version = 2
37
+
38
+ ef = OpenSSL::X509::ExtensionFactory.new
39
+ ef.subject_certificate = cert
40
+ ef.issuer_certificate = cert
41
+ cert.add_extension ef.create_extension("basicConstraints","CA:TRUE", true)
42
+ cert.add_extension ef.create_extension("subjectKeyIdentifier", "hash")
43
+ cert.add_extension ef.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
44
+
45
+ cert.sign key, OpenSSL::Digest::SHA256.new
46
+
47
+ return SslData.new(cert, key)
48
+ end
49
+
50
+ def self.parse_cert(string)
51
+ OpenSSL::X509::Certificate.new(string)
52
+ end
53
+
54
+ def self.parse_key(string, pass=nil)
55
+ OpenSSL::PKey.read(string, pass)
56
+ end
57
+
58
+ def self.extract_subject(cert)
59
+ Hash[cert.subject.to_a.map{|i| [i[0].to_sym, i[1]]}]
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Fauthentic
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fauthentic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe Marty
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-09 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: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: openssl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description: Fauthentic allows you to easily generate, read, parse and verify OpenSSL
70
+ certificates and keys
71
+ email:
72
+ - jmarty@iexposure.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - fauthentic.gemspec
85
+ - lib/fauthentic.rb
86
+ - lib/fauthentic/version.rb
87
+ homepage: https://github.com/mltsy/fauthentic
88
+ licenses: []
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A convenience library for self-signed SSL certificates
110
+ test_files: []