openssl-ssh 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/openssl/ssh.rb +77 -0
- data/lib/openssl/ssh/version.rb +5 -0
- data/openssl-ssh.gemspec +42 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 201e86275b09b7955f5e65c8e20b77d3b824be8e
|
4
|
+
data.tar.gz: 4d04006494ec4c1f37f32647d0b19adb7a0484c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6a38328c4d02ce9bc2a9345c8b7526a49ca142acd28fe44dceb3ee957f5424607253917a0f61133cd328ace34b611e280f3b5603a5edc255d42dee276a85edc
|
7
|
+
data.tar.gz: 2f835b87e85e520d6c9456f5c1e8e439e48c9e0e6f2788aef58fad9ec539e674058c11521c113891c9713ca00fbc27f5cadbd560d7b3f5950e7d46b0f146da72
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
openssl-ssh (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
docile (1.3.1)
|
11
|
+
json (2.1.0)
|
12
|
+
rake (12.3.1)
|
13
|
+
rspec (3.8.0)
|
14
|
+
rspec-core (~> 3.8.0)
|
15
|
+
rspec-expectations (~> 3.8.0)
|
16
|
+
rspec-mocks (~> 3.8.0)
|
17
|
+
rspec-core (3.8.0)
|
18
|
+
rspec-support (~> 3.8.0)
|
19
|
+
rspec-expectations (3.8.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-mocks (3.8.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-support (3.8.0)
|
26
|
+
simplecov (0.16.1)
|
27
|
+
docile (~> 1.1)
|
28
|
+
json (>= 1.8, < 3)
|
29
|
+
simplecov-html (~> 0.10.0)
|
30
|
+
simplecov-html (0.10.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.16)
|
37
|
+
openssl-ssh!
|
38
|
+
rake (~> 12.3)
|
39
|
+
rspec (~> 3.8)
|
40
|
+
simplecov (~> 0.16)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.16.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Adam Ladachowski
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/76e285ab4467fa52bc70/maintainability)](https://codeclimate.com/github/aladac/openssl-ssh/maintainability)
|
2
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/76e285ab4467fa52bc70/test_coverage)](https://codeclimate.com/github/aladac/openssl-ssh/test_coverage)
|
3
|
+
|
4
|
+
# OpenSSL::SSH
|
5
|
+
|
6
|
+
This gem introduces `OpenSSL::PKey::SSH` class with the ability to parse **OpenSSH** format public keys and return a correct `OpenSSL::PKey` type object. This is a convenience class used to parse the specific format of the **OpenSSH** public key.
|
7
|
+
|
8
|
+
Private **OpenSSH** key strings are forwarderd without modification to `OpenSSL::PKey::RSA.new` and `OpenSSL::Pkey::DSA.new` respectively.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'openssl-ssh'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install openssl-ssh
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'openssl/ssh'
|
30
|
+
|
31
|
+
OpenSSL::PKey::SSH.new File.read('/path/to/openssh/public.key')
|
32
|
+
# <OpenSSL::PKey::RSA:0x00007fb93f9f8788>
|
33
|
+
|
34
|
+
```
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aladac/openssl-ssh.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
49
|
+
|
50
|
+
## Credits
|
51
|
+
|
52
|
+
This is almost entirely a refactored and gem packaged variation of a gist by @tombh
|
53
|
+
|
54
|
+
https://gist.github.com/tombh/f66de84fd3a63e670ad9
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'openssl/ssh'
|
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__)
|
data/bin/setup
ADDED
data/lib/openssl/ssh.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'openssl/ssh/version'
|
2
|
+
require 'base64'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module OpenSSL
|
6
|
+
module PKey
|
7
|
+
class SSH
|
8
|
+
RSA_COMPONENTS = ['ssh-rsa', :e, :n].freeze
|
9
|
+
DSA_COMPONENTS = ['ssh-dss', :p, :q, :g, :pub_key].freeze
|
10
|
+
|
11
|
+
def self.new(key, password = nil)
|
12
|
+
forward_private_key(key, password) || parse_public_ssh_key(key)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.forward_private_key(key, password)
|
16
|
+
case key
|
17
|
+
when /BEGIN RSA PRIVATE KEY/
|
18
|
+
OpenSSL::PKey::RSA.new(key, password)
|
19
|
+
when /BEGIN DSA PRIVATE KEY/
|
20
|
+
OpenSSL::PKey::DSA.new(key, password)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.parse_public_ssh_key(key)
|
25
|
+
if key && key.is_a?(String) && key.match?(/^ssh-/)
|
26
|
+
key = key.split[1]
|
27
|
+
key = decode_pubkey(key)
|
28
|
+
end
|
29
|
+
key
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.decode_pubkey(string)
|
33
|
+
components = unpack_pubkey_components Base64.decode64(string)
|
34
|
+
raise "Unsupported key type #{components.first}" unless components.first.match?(/#{RSA_COMPONENTS.first}|#{DSA_COMPONENTS.first}/)
|
35
|
+
|
36
|
+
ops, key = process_components(components)
|
37
|
+
process_ops(key, ops)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.key_type_components(components)
|
41
|
+
(components.first.match?(RSA_COMPONENTS.first) ? RSA_COMPONENTS : DSA_COMPONENTS).zip(components)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.key_type_object(components)
|
45
|
+
components.first.match?(RSA_COMPONENTS.first) ? OpenSSL::PKey::RSA.new : OpenSSL::PKey::DSA.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.process_components(components)
|
49
|
+
[key_type_components(components), key_type_object(components)]
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.process_ops(key, ops)
|
53
|
+
ops.each do |o|
|
54
|
+
next unless o.first.is_a? Symbol
|
55
|
+
|
56
|
+
key.send "#{o.first}=", decode_mpi(o.last)
|
57
|
+
end
|
58
|
+
key
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.unpack_pubkey_components(str)
|
62
|
+
cs = []
|
63
|
+
i = 0
|
64
|
+
while i < str.length
|
65
|
+
len = str[i, 4].unpack1('N')
|
66
|
+
cs << str[i + 4, len]
|
67
|
+
i += 4 + len
|
68
|
+
end
|
69
|
+
cs
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.decode_mpi(mpi_str)
|
73
|
+
mpi_str.unpack('C*').inject(0) { |a, e| (a << 8) | e }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/openssl-ssh.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'openssl/ssh/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'openssl-ssh'
|
7
|
+
spec.version = OpenSSL::SSH::VERSION
|
8
|
+
spec.authors = ['Adam Ladachowski']
|
9
|
+
spec.email = ['adam.ladachowski@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Handling for OpenSSH public keys'
|
12
|
+
spec.description = 'This gem adds an OpenSSL::PKey::SSH class with the ability to parse OpenSSH and resturn a correct OpenSSL::PKey type class'
|
13
|
+
spec.homepage = 'https://github.com/aladac/openssl-ssh'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = "TODO: Put your gem's public repo URL here."
|
23
|
+
spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
|
24
|
+
else
|
25
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
26
|
+
'public gem pushes.'
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
39
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
40
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
41
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openssl-ssh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Ladachowski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-16 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: '12.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.3'
|
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.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.16'
|
69
|
+
description: This gem adds an OpenSSL::PKey::SSH class with the ability to parse OpenSSH
|
70
|
+
and resturn a correct OpenSSL::PKey type class
|
71
|
+
email:
|
72
|
+
- adam.ladachowski@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/openssl/ssh.rb
|
88
|
+
- lib/openssl/ssh/version.rb
|
89
|
+
- openssl-ssh.gemspec
|
90
|
+
homepage: https://github.com/aladac/openssl-ssh
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
homepage_uri: https://github.com/aladac/openssl-ssh
|
95
|
+
source_code_uri: 'TODO: Put your gem''s public repo URL here.'
|
96
|
+
changelog_uri: 'TODO: Put your gem''s CHANGELOG.md URL here.'
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.6.14.1
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Handling for OpenSSH public keys
|
117
|
+
test_files: []
|