Skip to content

Commit

Permalink
Merge branch 'master' into verify-principal
Browse files Browse the repository at this point in the history
  • Loading branch information
walro authored Sep 23, 2024
2 parents 3ba4c06 + 6fe0040 commit e7bae87
Show file tree
Hide file tree
Showing 50 changed files with 1,077 additions and 117 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [mfazekas]
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
ruby-version: [2.6.10, 2.7.7, 3.0.5, 3.1.3, 3.2.1]
ruby-version: [2.6.10, 2.7.7, 3.0.6, 3.1.3, 3.2.1, 3.3.0]
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -39,13 +39,14 @@ jobs:
${{ runner.os }}-pip-v1
- name: Bundle install
run: |
gem install bundler
gem install bundler ${{ (startsWith(matrix.ruby-version, '2.6.') || startsWith(matrix.ruby-version, '2.7.')) && '-v 2.4.22' || '' }}
bundle config set path 'vendor/bundle'
bundle config set --local path 'vendor/bundle'
bundle install --jobs 4 --retry 3 --path vendor/bundle
BUNDLE_GEMFILE=./Gemfile.noed25519 bundle install --jobs 4 --retry 3 --path vendor/bundle
env:
BUNDLE_PATH: vendor/bundle


- name: Add to etc/hosts
run: |
Expand Down Expand Up @@ -77,6 +78,12 @@ jobs:
env:
NET_SSH_RUN_INTEGRATION_TESTS: 1
CI: 1
- name: Run tests (without rbnacl)
run: bundle exec rake test
env:
BUNDLE_GEMFILE: ./Gemfile.norbnacl
NET_SSH_RUN_INTEGRATION_TESTS: 1
CI: 1
- name: Run Tests (without ed25519)
run: bundle exec rake test
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pkg
test/integration/.vagrant
test/integration/playbook.retry

lib/net/ssh/version.rb.old

.byebug_history

tryout
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Lint/UselessTimes:
# Offense count: 205
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 74
Max: 75

# Offense count: 16
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Expand All @@ -251,7 +251,7 @@ Metrics/BlockNesting:
# Offense count: 33
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 488
Max: 350

# Offense count: 38
# Configuration parameters: IgnoredMethods.
Expand Down
24 changes: 24 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
=== 7.3.0 rc0

* aes(128|256)gcm [#946]

=== 7.2.2

* ruby 3.3.0: base64 fix

=== 7.2.1 rc1

* feat: allow load of certkey from string [#926]
* fix: fix for Socket#recv returning nil on ruby 3.3.0 [#928]

=== 7.2.0

* Add debugging information for algorithm of pubkey in use [#918]

=== 7.2.0 rc1

* Allow IdentityAgent as option to Net::SSH.start [#912]

=== 7.2.0 beta1

* Support `[email protected]` cypher if `RbNaCl` gem is installed [#908]

=== 7.1.0

Expand Down
23 changes: 23 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### Development notes

## Building/running ssh server in debug mode

clone the openssh server from `https://github.com/openssh/openssh-portable`

```sh
brew install openssl
/usr/local/Cellar/openssl@3/3.1.0/bin/openssl

autoreconf
./configure --with-ssl-dir=/usr/local/Cellar/openssl@3/3.1.0/ --with-audit=debug --enable-debug CPPFLAGS="-DDEBUG -DPACKET_DEBUG" CFLAGS="-g -O0"
make
```

To run server in debug mode:
```sh
echo '#' > /tmp/sshd_config
ssh-keygen -t rsa -f /tmp/ssh_host_rsa_key
# /Users/boga/Work/OSS/NetSSH/openssh-portable/sshd -p 2222 -D -d -d -d -e -f /tmp/sshd_config
/Users/boga/Work/OSS/NetSSH/openssh-portable/sshd -p 2222 -D -d -d -d -e -f /tmp/sshd_config -h /tmp/ssh_host_rsa_key

```
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG RUBY_VERSION=3.1
FROM ruby:${RUBY_VERSION}

ARG BUNDLERV=

RUN apt update && apt install -y openssh-server sudo netcat-openbsd \
&& useradd --create-home --shell '/bin/bash' --comment 'NetSSH' 'net_ssh_1' \
&& useradd --create-home --shell '/bin/bash' --comment 'NetSSH' 'net_ssh_2' \
Expand All @@ -20,7 +22,7 @@ COPY Gemfile net-ssh.gemspec $INSTALL_PATH/

COPY lib/net/ssh/version.rb $INSTALL_PATH/lib/net/ssh/version.rb

RUN gem install bundler && bundle install
RUN gem install bundler ${BUNDLERV} && bundle install

COPY . $INSTALL_PATH/

Expand Down
12 changes: 12 additions & 0 deletions Gemfile.norbnacl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source 'https://rubygems.org'

ENV['NET_SSH_NO_RBNACL'] = 'true'
# Specify your gem's dependencies in mygem.gemspec
gemspec

if ENV["CI"] && !Gem.win_platform?
gem 'simplecov', require: false, group: :test
gem 'codecov', require: false, group: :test
end

gem 'webrick', group: %i[development test] if RUBY_VERSION.split(".")[0].to_i >= 3
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Unsecure algoritms will definitely be removed in Net::SSH 8.*.
| Name | Support | Details |
|--------------------------------------|-----------------------|----------|
| aes256-ctr / aes192-ctr / aes128-ctr | OK | |
| [email protected] | OK. | Requires the gem `rbnacl` |
| aes256-cbc / aes192-cbc / aes128-cbc | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
| [email protected] | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
| blowfish-ctr blowfish-cbc | Deprecated in 6.0 | unsecure, will be removed in 8.0 |
Expand Down Expand Up @@ -247,6 +248,8 @@ mv gem-public_cert.pem net-ssh-public_cert.pem
gem cert --add net-ssh-public_cert.pem
```

or `rake cert:update_public_when_expired`

## Security contact information

See [SECURITY.md](SECURITY.md)
Expand All @@ -271,6 +274,9 @@ Support this project by becoming a sponsor. Your logo will show up here with a l

[![Sponsor](https://opencollective.com/net-ssh/sponsor/0/avatar.svg)](https://opencollective.com/net-ssh/sponsor/0/website)

[<img src="https://github.com/net-ssh/net-ssh/assets/52435/9690bf3e-34ea-4c52-8aea-1cc4cb5bcb6d" width="320">](https://ubicloud.com)


## LICENSE:

(The MIT License)
Expand Down
69 changes: 51 additions & 18 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,48 @@ def change_version(&block)
version_file = 'lib/net/ssh/version.rb'
require_relative version_file
pre = Net::SSH::Version::PRE
result = block[pre: pre]
raise "Version change logic should always return a pre", ArgumentError unless result.key?(:pre)
tiny = Net::SSH::Version::TINY
result = block[pre: pre, tiny: Net::SSH::Version::TINY]
raise ArgumentError, "Version change logic should always return a pre" unless result.key?(:pre)

new_pre = result[:pre]
found = false
new_tiny = result[:tiny] || tiny
found = { pre: false, tiny: false }
File.open("#{version_file}.new", "w") do |f|
File.readlines(version_file).each do |line|
match = /^(\s+PRE\s+=\s+")#{pre}("\s*)$/.match(line)
match =
if pre.nil?
/^(\s+PRE\s+=\s+)nil(\s*)$/.match(line)
else
/^(\s+PRE\s+=\s+")#{pre}("\s*)$/.match(line)
end
if match
prefix = match[1]
postfix = match[2]
if new_pre.nil?
prefix.delete_suffix!('"')
postfix.delete_prefix!('"')
end
prefix.delete_suffix!('"')
postfix.delete_prefix!('"')
new_line = "#{prefix}#{new_pre.inspect}#{postfix}"
puts "Changing:\n - #{line} + #{new_line}"
line = new_line
found = true
found[:pre] = true
end

if new_tiny != tiny
match = /^(\s+TINY\s+=\s+)#{tiny}(\s*)$/.match(line)
if match
prefix = match[1]
postfix = match[2]
new_line = "#{prefix}#{new_tiny}#{postfix}"
puts "Changing:\n - #{line} + #{new_line}"
line = new_line
found[:tiny] = true
end
end

f.write(line)
end
raise ArugmentError, "Cound not find line: PRE = \"#{pre}\" in #{version_file}" unless found
raise ArgumentError, "Cound not find line: PRE = \"#{pre}\" in #{version_file}" unless found[:pre]
raise ArgumentError, "Cound not find line: TINY = \"#{tiny}\" in #{version_file}" unless found[:tiny] || new_tiny == tiny
end

FileUtils.mv version_file, "#{version_file}.old"
Expand All @@ -91,20 +110,34 @@ end
namespace :vbump do
desc "Final release"
task :final do
change_version do |pre:|
raise ArgumentError, "Unexpected pre: #{pre}" if pre.nil?

{ pre: nil }
change_version do |pre:, tiny:|
_ = tiny
if pre.nil?
{ tiny: tiny + 1, pre: nil }
else
raise ArgumentError, "Unexpected pre: #{pre}" if pre.nil?

{ pre: nil }
end
end
end

desc "Increment prerelease"
task :pre do
change_version do |pre:|
task :pre, [:type] do |_t, args|
change_version do |pre:, tiny:|
puts " PRE => #{pre.inspect}"
match = /^([a-z]+)(\d+)/.match(pre)
raise ArgumentError, "Unexpected pre: #{pre}" if match.nil?
raise ArgumentError, "Unexpected pre: #{pre}" if match.nil? && args[:type].nil?

{ pre: "#{match[1]}#{match[2].to_i + 1}" }
if match.nil? || (!args[:type].nil? && args[:type] != match[1])
if pre.nil?
{ pre: "#{args[:type]}1", tiny: tiny + 1 }
else
{ pre: "#{args[:type]}1" }
end
else
{ pre: "#{match[1]}#{match[2].to_i + 1}" }
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ services:
context: .
args:
RUBY_VERSION: 2.7
BUNDLERV: "-v 2.2.28"
ruby-2.6:
build:
context: .
args:
RUBY_VERSION: 2.6
BUNDLERV: "-v 2.4.22"
7 changes: 5 additions & 2 deletions lib/net/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ module SSH
# Net::SSH.start for a description of each option.
VALID_OPTIONS = %i[
auth_methods bind_address compression compression_level config
encryption forward_agent hmac host_key remote_user
encryption forward_agent hmac host_key identity_agent remote_user
keepalive keepalive_interval keepalive_maxcount kex keys key_data
keycerts languages logger paranoid password port proxy
keycerts keycert_data languages logger paranoid password port proxy
rekey_blocks_limit rekey_limit rekey_packet_limit timeout verbose
known_hosts global_known_hosts_file user_known_hosts_file host_key_alias
host_name user properties passphrase keys_only max_pkt_size
Expand Down Expand Up @@ -146,6 +146,8 @@ module SSH
# and hostbased authentication
# * :keycerts => an array of file names of key certificates to use
# with publickey authentication
# * :keycert_data => an array of strings, which each element of the array
# being a key certificate to use with publickey authentication
# * :key_data => an array of strings, with each element of the array being
# a raw private key in PEM format.
# * :keys_only => set to +true+ to use only private keys from +keys+ and
Expand Down Expand Up @@ -192,6 +194,7 @@ module SSH
# Defaults to %w(~/.ssh/known_hosts ~/.ssh/known_hosts2).
# * :use_agent => Set false to disable the use of ssh-agent. Defaults to
# true
# * :identity_agent => the path to the ssh-agent's UNIX socket
# * :verbose => how verbose to be (Logger verbosity constants, Logger::DEBUG
# is very verbose, Logger::FATAL is all but silent). Logger::FATAL is the
# default. The symbols :debug, :info, :warn, :error, and :fatal are also
Expand Down
6 changes: 2 additions & 4 deletions lib/net/ssh/authentication/ed25519.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

require 'ed25519'

require 'base64'

require 'net/ssh/transport/cipher_factory'
require 'net/ssh/authentication/pub_key_fingerprint'
require 'bcrypt_pbkdf' unless RUBY_PLATFORM == "java"
Expand Down Expand Up @@ -46,7 +44,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 +132,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
Loading

0 comments on commit e7bae87

Please sign in to comment.