Skip to content

Commit

Permalink
Merge pull request #932 from mattbrictson/fix-base64-warning
Browse files Browse the repository at this point in the history
Remove base64 runtime dependency
  • Loading branch information
mfazekas committed Jan 5, 2024
2 parents 2e65064 + a98673a commit add141b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/net/ssh/authentication/ed25519.rb
Expand Up @@ -46,7 +46,7 @@ def self.read(datafull, password)
raise ArgumentError.new("Expected #{MEND} at end of private key") unless datafull.end_with?(MEND)

datab64 = datafull[MBEGIN.size...-MEND.size]
data = Base64.decode64(datab64)
data = datab64.unpack1("m")
raise ArgumentError.new("Expected #{MAGIC} at start of decoded private key") unless data.start_with?(MAGIC)

buffer = Net::SSH::Buffer.new(data[MAGIC.size + 1..-1])
Expand Down Expand Up @@ -134,7 +134,7 @@ def ssh_do_verify(sig, data, options = {})

def to_pem
# TODO this is not pem
ssh_type + Base64.encode64(@verify_key.to_bytes)
ssh_type + [@verify_key.to_bytes].pack("m")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/net/ssh/authentication/pub_key_fingerprint.rb
Expand Up @@ -32,7 +32,7 @@ def self.fingerprint(blob, algorithm = 'MD5')
when 'MD5'
OpenSSL::Digest.hexdigest(algorithm, blob).scan(/../).join(":")
when 'SHA256'
"SHA256:#{Base64.encode64(OpenSSL::Digest.digest(algorithm, blob)).chomp.gsub(/=+\z/, '')}"
"SHA256:#{[OpenSSL::Digest.digest(algorithm, blob)].pack('m').chomp.gsub(/=+\z/, '')}"
else
raise OpenSSL::Digest::DigestError, "unsupported ssh key digest #{algorithm}"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/net/ssh/known_hosts.rb
Expand Up @@ -241,11 +241,11 @@ def match(host, pattern)
def known_host_hash?(hostlist, entries)
if hostlist.size == 1 && hostlist.first =~ /\A\|1(\|.+){2}\z/
chunks = hostlist.first.split(/\|/)
salt = Base64.decode64(chunks[2])
salt = chunks[2].unpack1("m")
digest = OpenSSL::Digest.new('sha1')
entries.each do |entry|
hmac = OpenSSL::HMAC.digest(digest, salt, entry)
return true if Base64.encode64(hmac).chomp == chunks[3]
return true if [hmac].pack("m").chomp == chunks[3]
end
end
false
Expand Down
1 change: 1 addition & 0 deletions net-ssh.gemspec
Expand Up @@ -38,6 +38,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency('rbnacl', '~> 7.1') unless ENV['NET_SSH_NO_RBNACL']

spec.add_development_dependency "base64"
spec.add_development_dependency "bundler", ">= 1.17"
spec.add_development_dependency "minitest", "~> 5.19"
spec.add_development_dependency "mocha", "~> 2.1.0"
Expand Down

0 comments on commit add141b

Please sign in to comment.