open_ssl_pkey_ed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94e8930e0c9671de7248cc6c1f212c38e9013c70a21134a6882186d40a1b95fe
4
+ data.tar.gz: 5565874ff5292ec6f3e28ff7101206085de16ae54b21d5a88923ffb88011c744
5
+ SHA512:
6
+ metadata.gz: 29c047ac6002312d2f4b0ff1d139f6867d076389d3c853ce8794c34ca0a585e4b8d901fca24a7ed045a659dbce062077e9f05cf850f99175fd4e7c0e23341647
7
+ data.tar.gz: 512a5a18f2fcdaef76cb384a091ccfe2a3f8ac2bf017724e52c0938d671c796850d27815a28abaf737b56ab0d0647c54c08e231840811804737220ae00c33cf8
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in open_ssl_ec_pubkey_utils.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 potato2003
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,31 @@
1
+ # OpenSSLPKeyED
2
+
3
+ This gem can encode/decode OpenSSL::PKey (EC/RSA) to der/pem format
4
+
5
+ OpenSSL::PKey::EC class API is inconsistent with RSA, DSA and DH.
6
+ - refs: https://github.com/ruby/openssl/issues/29
7
+ - refs: https://github.com/ruby/openssl/issues/233
8
+
9
+ Also, OpenSSL::PKey::EC#public_key returns EC::Point class that does not has `to_der` / `to_pem`.
10
+ This gem provieds `to_der` method to solve it problem.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'open_ssl_pkey_ed'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ encode to der format
23
+
24
+ ```ruby
25
+ OpenSSLPKeyED.to_der(pubkey)
26
+ ```
27
+
28
+ ## TODO
29
+
30
+ - add support for EC to pem format
31
+ - add support for DSA/DH
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "open_ssl_ec_pubkey_utils"
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,43 @@
1
+ require 'openssl'
2
+
3
+ module OpenSSLPKeyED
4
+ def self.to_der(key)
5
+ case key
6
+ when OpenSSL::PKey::EC::Point # EC public key
7
+ asn1(key).to_der
8
+ when OpenSSL::PKey::EC, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, OpenSSL::PKey::DH
9
+ key.to_der
10
+ end
11
+ end
12
+
13
+ def self.to_pem(key)
14
+ case key
15
+ when OpenSSL::PKey::EC::Point # EC public key
16
+ raise "not supported OpenSSL::PKey::EC's public key yet", NotImplementedError
17
+ when OpenSSL::PKey::EC, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, OpenSSL::PKey::DH
18
+ key.to_pem
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ PUBLIC_KEY_ALGORITHM = 'id-ecPublicKey'
25
+
26
+ def self.asn1(public_key)
27
+ curve_name = public_key.group.curve_name
28
+
29
+ asn1 = OpenSSL::ASN1::Sequence([
30
+ OpenSSL::ASN1::Sequence([
31
+ OpenSSL::ASN1::ObjectId(PUBLIC_KEY_ALGORITHM),
32
+ OpenSSL::ASN1::ObjectId(curve_name)
33
+ ]),
34
+ OpenSSL::ASN1::BitString(
35
+ public_key.to_octet_string(:uncompressed)
36
+ )
37
+ ])
38
+ end
39
+
40
+ def self.public_key?(key)
41
+ key.is_a? OpenSSL::PKey::EC::Point
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "open_ssl_pkey_ed"
6
+ spec.version = "0.0.1"
7
+ spec.authors = ["potato2003"]
8
+ spec.email = ["potato2003@gmail.com"]
9
+
10
+ spec.summary = "encode OpenSSL::PKey to der/pem"
11
+ spec.description = ""
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
+ f.match(%r{^(test|spec|features)/})
15
+ end
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.16"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_ssl_pkey_ed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - potato2003
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-19 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: ''
56
+ email:
57
+ - potato2003@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/open_ssl_pkey_ed.rb
72
+ - open_ssl_pkey_ed.gemspec
73
+ homepage:
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.7.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: encode OpenSSL::PKey to der/pem
96
+ test_files: []