diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e2a3834..7245a44 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,10 +17,10 @@ jobs: uses: actions/checkout@v2 - name: Build tar.gz - run: tar zcf gpgbridge.tar.gz gpgbridge.rb Gemfile README.md ReleaseNotes.md + run: tar zcf gpgbridge.tar.gz gpgbridge.rb Gemfile Gemfile.lock README.md ReleaseNotes.md - name: Build zip - run: zip gpgbridge.zip gpgbridge.rb Gemfile README.md ReleaseNotes.md + run: zip gpgbridge.zip gpgbridge.rb Gemfile Gemfile.lock README.md ReleaseNotes.md - name: Create release id: create_release @@ -35,7 +35,7 @@ jobs: prerelease: ${{ contains(github.ref, '-pre') }} - name: Upload tar.gz - uses: actions/upload-release-asset@v1.0.2 + uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -45,7 +45,7 @@ jobs: asset_content_type: application/gzip - name: Upload zip - uses: actions/upload-release-asset@v1.0.2 + uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/.gitignore b/.gitignore index 0c06cd4..5043d0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ #* -Gemfile.lock +**/vendor/bundle +**/.bundle diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cf03332 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +inherit_from: + - <%= ENV['HOME'] %>/.config/rubocop/config.yml diff --git a/.vscode/Gemfile b/.vscode/Gemfile new file mode 100644 index 0000000..07a53d4 --- /dev/null +++ b/.vscode/Gemfile @@ -0,0 +1,9 @@ +# This file can be used with the "ruby-lsp" extension in VS Code. +# Set "Bundle Gemfile" in the "Ruby LSP" Workspace settings to "./.Gemfile.dev" + +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +gem 'ruby-lsp' +gem 'rubocop' +gem 'rubocop-performance' diff --git a/.vscode/Gemfile.lock b/.vscode/Gemfile.lock new file mode 100644 index 0000000..7f5089b --- /dev/null +++ b/.vscode/Gemfile.lock @@ -0,0 +1,49 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + json (2.7.1) + language_server-protocol (3.17.0.3) + parallel (1.24.0) + parser (3.3.0.2) + ast (~> 2.4.1) + racc + prism (0.19.0) + racc (1.7.3) + rainbow (3.1.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.2.2.4) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-lsp (0.13.2) + language_server-protocol (~> 3.17.0) + prism (>= 0.19.0, < 0.20) + sorbet-runtime (>= 0.5.5685) + ruby-progressbar (1.13.0) + sorbet-runtime (0.5.11188) + unicode-display_width (2.5.0) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + rubocop + rubocop-performance + ruby-lsp + +BUNDLED WITH + 2.4.10 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e4b86e3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rubyLsp.bundleGemfile": ".vscode/Gemfile" +} diff --git a/Gemfile b/Gemfile index f02524f..15bc2bd 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,6 @@ source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } -gem 'sys-proctable', '~> 1.2.5' -gem 'ptools', '~> 1.3.7', platforms: :ruby -gem 'net-ssh', '~> 6.1.0', platforms: :x64_mingw +gem 'sys-proctable', '~> 1.3.0' +gem 'ptools', '~> 1.5.0', platforms: :ruby +gem 'net-ssh', '~> 7.2.1', platforms: :x64_mingw diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..947b1b9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,18 @@ +GEM + remote: https://rubygems.org/ + specs: + ffi (1.16.3) + ptools (1.5.0) + sys-proctable (1.3.0) + ffi (~> 1.1) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + net-ssh (~> 7.2.1) + ptools (~> 1.5.0) + sys-proctable (~> 1.3.0) + +BUNDLED WITH + 2.4.10 diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 9e910f6..b1bb466 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,3 +1,7 @@ +## Changes in v1.4 + +* Verified with ruby 3.2 & 3.3, and updated gems. + ## Changes in v1.3 * Updates to the helper functions to support zsh (contributed by @tetov). diff --git a/gpgbridge.rb b/gpgbridge.rb index efe632f..3883181 100644 --- a/gpgbridge.rb +++ b/gpgbridge.rb @@ -12,8 +12,8 @@ FIRST_PORT = 6910 BUFSIZ = 4096 -# WslBridge runs in WSL. It receives requests through local sockets -# requests from WSL clients and forwards them to WindowsBridge in Windows. +# WslBridge runs in WSL. It receives requests from WSL clients through +# local sockets and forwards them to WindowsBridge in Windows. class WslBridge def initialize(options, logger) @pidfile = options[:pidfile] @@ -96,10 +96,16 @@ def start_listener(socket_name, remote_address, port, noncefile) Thread.new do # get WindowsBridge nonce nonce = get_nonce noncefile - @logger.debug 'connect with remote' - winbridge = TCPSocket.new remote_address, port - # send the nonce to authenticate, if the nonce is wrong the connection will be closed immediately - winbridge.send nonce, 0 + winbridge = nil + begin + @logger.debug 'connect with winbridge' + winbridge = TCPSocket.new remote_address, port + # send the nonce to authenticate, if the nonce is wrong the connection will be closed immediately + winbridge.send nonce, 0 + rescue Errno::ETIMEDOUT => e + @logger.error "Exception while connecting with winbridge: #{e.inspect}" + Thread.exit + end @logger.debug 'connected' begin loop = true @@ -108,20 +114,30 @@ def start_listener(socket_name, remote_address, port, noncefile) readable = ready[0] if readable.include?(sock) @logger.debug 'msg from client' - msg = sock.recv BUFSIZ - if msg.length > 0 - winbridge.send msg, 0 - else - loop = false + begin + msg = sock.recv BUFSIZ + if msg.length > 0 + winbridge.send msg, 0 + else + loop = false + end + rescue Errno::ECONNRESET => e + @logger.error "Exception while receiving msg from client: #{e.inspect}" + Thread.exit end end if readable.include?(winbridge) - @logger.debug 'msg from bridge' - msg = winbridge.recv BUFSIZ - if msg.length > 0 - sock.send msg, 0 - else - loop = false + @logger.debug 'msg from winbridge' + begin + msg = winbridge.recv BUFSIZ + if msg.length > 0 + sock.send msg, 0 + else + loop = false + end + rescue Errno::ECONNRESET => e + @logger.error "Exception while receiving msg from winbridge: #{e.inspect}" + Thread.exit end end end @@ -191,7 +207,7 @@ def initialize(options, logger) socket_names = options[:socket_names] @threads = socket_names.collect do |socket_name, port| Thread.start(socket_name, remote_address, port, nonce) do |s, r, p, n| - if socket_name == 'agent-ssh-socket' + if s == 'agent-ssh-socket' start_pageant_proxy s, r, p, n else start_assuan_proxy s, r, p, n