sparoid 1.0.6 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9c9e31643c35e5466c71be88339a2c7999e401d893b6c7364597380def920cf
4
- data.tar.gz: 237a5a03c2b3a306b25ad947754ce92acb866dcf2985650e27720773edc1f39e
3
+ metadata.gz: b933d6729f0ce76259c272550548532b15a206218239b9f824cd58b0deec6ee3
4
+ data.tar.gz: 61a1ec401ecebf13674e3b66e684df99ea5007f051e91b5bf98cc783e9f91c15
5
5
  SHA512:
6
- metadata.gz: a417c0b53950536d98a43f417690952e2b4bf41b3bcb72b13e8bd52e367f9a0a814b7e10ce9072b57098b48cd8ee36c41166f354f6eb6b0782430e4a945e7bf3
7
- data.tar.gz: fc30ef678295a18379cd770840f702c2c328047fcbe9bbaa6fd65514c95105a29b88fd946a0c7bcf0cf93703dba2a6cd547a81ec6dc9c31e73f7bf06626e9c45
6
+ metadata.gz: 173cb6c71c46ba88153306d5124879ade2f53eedda41da85b58475abc3fddc0e0d5dee00ab459e546ab0b283411044dbaa016369ccb74a791a22126dc5dc99dd
7
+ data.tar.gz: 71318184eb58dbcbcc713aebd1c2e22375562af77ae29083b90f0933bc078991f1860fc00fbccad5e55396f37845b098f3c4494cae381c71e79b30a8e6a8124a
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.5
3
3
  NewCops: enable
4
4
 
5
5
  Style/StringLiterals:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [1.0.11] - 2021-06-14
2
+
3
+ - Log hostname when reporting unhandled exceptions
4
+
5
+ ## [1.0.10] - 2021-06-09
6
+
7
+ - Cache public IP in /tmp/.sparoid_public_ip for 1 min
8
+
9
+ ## [1.0.9] - 2021-05-23
10
+
11
+ - Exit gracefully on abort (ctrl-c) instead of dumping huge stacktrace
12
+ - Sleep 20ms aftering sending UDP package to allow for remote host to open its firewall
13
+
14
+ ## [1.0.8] - 2021-04-27
15
+
16
+ - Get ENV variables if config file is missing
17
+
18
+ ## [1.0.7] - 2021-04-27
19
+
20
+ - Get key and hmac key from ENV variables
21
+
1
22
  ## [1.0.6] - 2021-04-13
2
23
 
3
24
  - Use static IP for opendns resolver, saves one DNS lookup
data/README.md CHANGED
@@ -26,7 +26,7 @@ Can be used with OpenSSH's ProxyCommand/ProxyUseFdpass to send the packet before
26
26
 
27
27
  ```
28
28
  Host *.example.com
29
- ProxyCommand sparoid send %h --passfd %p
29
+ ProxyCommand sparoid connect %h %p
30
30
  ProxyUseFdpass yes
31
31
  ```
32
32
 
data/exe/sparoid CHANGED
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "../lib/sparoid/cli"
5
- Sparoid::CLI.start
4
+ begin
5
+ require_relative "../lib/sparoid/cli"
6
+ Sparoid::CLI.start
7
+ rescue Interrupt
8
+ exit 1
9
+ end
data/lib/sparoid.rb CHANGED
@@ -11,9 +11,14 @@ module Sparoid
11
11
 
12
12
  # Send an authorization packet
13
13
  def auth(key, hmac_key, host, port)
14
- msg = message(public_ip)
14
+ msg = message(cached_public_ip)
15
15
  data = prefix_hmac(hmac_key, encrypt(key, msg))
16
16
  sendmsg(host, port, data)
17
+
18
+ # wait some time for the server to actually open the port
19
+ # if we don't wait the next SYN package will be dropped
20
+ # and it have to be redelivered, adding 1 second delay
21
+ sleep 0.02
17
22
  end
18
23
 
19
24
  # Generate new aes and hmac keys, print to stdout
@@ -67,7 +72,27 @@ module Sparoid
67
72
  version = 1
68
73
  ts = (Time.now.utc.to_f * 1000).floor
69
74
  nounce = OpenSSL::Random.random_bytes(16)
70
- [version, ts, nounce, ip.address].pack("Nq>a16a4")
75
+ [version, ts, nounce, ip.address].pack("N q> a16 a4")
76
+ end
77
+
78
+ def cached_public_ip
79
+ File.open("/tmp/.sparoid_public_ip", "a+") do |f|
80
+ if f.size.zero? || (Time.now - f.mtime) > 60 # cache for 1min max
81
+ update_cache(f)
82
+ else
83
+ Resolv::IPv4.create f.read
84
+ end
85
+ end
86
+ rescue StandardError => e
87
+ warn "Sparoid: #{e.inspect}"
88
+ public_ip
89
+ end
90
+
91
+ def update_cache(file)
92
+ ip = public_ip
93
+ file.truncate(0)
94
+ file.write ip.to_s
95
+ ip
71
96
  end
72
97
 
73
98
  def public_ip
data/lib/sparoid/cli.rb CHANGED
@@ -13,7 +13,7 @@ module Sparoid
13
13
  rescue Errno::ENOENT
14
14
  abort "Sparoid: Config not found"
15
15
  rescue StandardError => e
16
- abort "Sparoid: #{e.message}"
16
+ abort "Sparoid: #{e.message} (#{host})"
17
17
  end
18
18
 
19
19
  desc "connect HOST PORT [SPA-PORT]", "Send a SPA, TCP connect, and then pass the FD back to the parent"
@@ -26,7 +26,7 @@ module Sparoid
26
26
  end
27
27
  Sparoid.fdpass(host, port)
28
28
  rescue StandardError => e
29
- abort "Sparoid: #{e.message}"
29
+ abort "Sparoid: #{e.message} (#{host})"
30
30
  end
31
31
 
32
32
  desc "keygen", "Generate an encryption key and a HMAC key"
@@ -47,6 +47,11 @@ module Sparoid
47
47
 
48
48
  def parse_ini(path)
49
49
  File.readlines(File.expand_path(path)).map! { |line| line.split("=", 2).map!(&:strip) }.to_h
50
+ rescue Errno::ENOENT
51
+ {
52
+ "key" => ENV["SPAROID_KEY"],
53
+ "hmac-key" => ENV["SPAROID_HMAC_KEY"]
54
+ }
50
55
  end
51
56
 
52
57
  def get_keys(config)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sparoid
4
- VERSION = "1.0.6"
4
+ VERSION = "1.0.11"
5
5
  end
data/sparoid.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Single Packet Authorisation client"
12
12
  spec.homepage = "https://github.com/84codes/sparoid.rb"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = spec.homepage
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Hörberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-13 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -62,14 +62,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 2.4.0
65
+ version: 2.5.0
66
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.2.3
72
+ rubygems_version: 3.2.15
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Single Packet Authorisation client