ssh_data 1.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,79 @@
1
+ module SSHData
2
+ module PublicKey
3
+ class RSA < Base
4
+ attr_reader :e, :n, :openssl
5
+
6
+ ALGO_DIGESTS = {
7
+ ALGO_RSA => OpenSSL::Digest::SHA1,
8
+ ALGO_RSA_SHA2_256 => OpenSSL::Digest::SHA256,
9
+ ALGO_RSA_SHA2_512 => OpenSSL::Digest::SHA512
10
+ }
11
+
12
+ def initialize(algo:, e:, n:)
13
+ unless algo == ALGO_RSA
14
+ raise DecodeError, "bad algorithm: #{algo.inspect}"
15
+ end
16
+
17
+ @algo = algo
18
+ @e = e
19
+ @n = n
20
+
21
+ @openssl = OpenSSL::PKey::RSA.new(asn1.to_der)
22
+
23
+ super(algo: algo)
24
+ end
25
+
26
+ # Verify an SSH signature.
27
+ #
28
+ # signed_data - The String message that the signature was calculated over.
29
+ # signature - The binarty String signature with SSH encoding.
30
+ #
31
+ # Returns boolean.
32
+ def verify(signed_data, signature)
33
+ sig_algo, raw_sig, _ = Encoding.decode_signature(signature)
34
+ digest = ALGO_DIGESTS[sig_algo]
35
+
36
+ if digest.nil?
37
+ raise DecodeError, "bad signature algorithm: #{sig_algo.inspect}"
38
+ end
39
+
40
+ openssl.verify(digest.new, raw_sig, signed_data)
41
+ end
42
+
43
+ # RFC4253 binary encoding of the public key.
44
+ #
45
+ # Returns a binary String.
46
+ def rfc4253
47
+ Encoding.encode_fields(
48
+ [:string, algo],
49
+ [:mpint, e],
50
+ [:mpint, n]
51
+ )
52
+ end
53
+
54
+ # Is this public key equal to another public key?
55
+ #
56
+ # other - Another SSHData::PublicKey::Base instance to compare with.
57
+ #
58
+ # Returns boolean.
59
+ def ==(other)
60
+ super && other.e == e && other.n == n
61
+ end
62
+
63
+ private
64
+
65
+ def asn1
66
+ OpenSSL::ASN1::Sequence.new([
67
+ OpenSSL::ASN1::Sequence.new([
68
+ OpenSSL::ASN1::ObjectId.new("rsaEncryption"),
69
+ OpenSSL::ASN1::Null.new(nil),
70
+ ]),
71
+ OpenSSL::ASN1::BitString.new(OpenSSL::ASN1::Sequence.new([
72
+ OpenSSL::ASN1::Integer.new(n),
73
+ OpenSSL::ASN1::Integer.new(e),
74
+ ]).to_der),
75
+ ])
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module SSHData
2
+ VERSION = "1.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssh_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mastahyeti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ed25519
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.10'
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.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-mocks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ description:
70
+ email: opensource+ssh_data@github.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - "./LICENSE.md"
76
+ - "./lib/ssh_data.rb"
77
+ - "./lib/ssh_data/certificate.rb"
78
+ - "./lib/ssh_data/encoding.rb"
79
+ - "./lib/ssh_data/error.rb"
80
+ - "./lib/ssh_data/private_key.rb"
81
+ - "./lib/ssh_data/private_key/base.rb"
82
+ - "./lib/ssh_data/private_key/dsa.rb"
83
+ - "./lib/ssh_data/private_key/ecdsa.rb"
84
+ - "./lib/ssh_data/private_key/ed25519.rb"
85
+ - "./lib/ssh_data/private_key/rsa.rb"
86
+ - "./lib/ssh_data/public_key.rb"
87
+ - "./lib/ssh_data/public_key/base.rb"
88
+ - "./lib/ssh_data/public_key/dsa.rb"
89
+ - "./lib/ssh_data/public_key/ecdsa.rb"
90
+ - "./lib/ssh_data/public_key/ed25519.rb"
91
+ - "./lib/ssh_data/public_key/rsa.rb"
92
+ - "./lib/ssh_data/version.rb"
93
+ homepage: https://github.com/github/ssh_data
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
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: '2.3'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.0.4
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Library for parsing SSH certificates
116
+ test_files: []