sparoid 1.0.8 → 1.0.13
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +22 -0
- data/Gemfile +2 -5
- data/README.md +1 -1
- data/exe/sparoid +6 -2
- data/lib/sparoid.rb +48 -2
- data/lib/sparoid/cli.rb +2 -2
- data/lib/sparoid/version.rb +1 -1
- data/sparoid.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f5904f6b6c520213811268420efad5fd5a387942352d8def32b722cd14420da
|
4
|
+
data.tar.gz: 6f7e19f1515979078635ff1e862bc9bcbb6fb2172ac631d94b986dd1b95984fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6043c439103ae404d9dfc6855b0273777b3e1e505d768e36b7d5bf514abc6c2a0498ecda76ddf89994d4d3fb426394fc3994566e659842e377bab643b8edfcfd
|
7
|
+
data.tar.gz: d95a3908952eb8134f1c68bd22a6f13f05ca99a8f1bda888c0adf6cbc77e882f65e4097a12b3db8a28ec74c624d8cee0821827ee12e54953da567606605f1e96
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## [1.0.13] - 2021-06-30
|
2
|
+
|
3
|
+
- Do not warn on empty public ip cache file
|
4
|
+
- The public ip cache file path can be controlled using the `SPAROID_CACHE_PATH` environment variable
|
5
|
+
|
6
|
+
## [1.0.12] - 2021-06-14
|
7
|
+
|
8
|
+
- Use file locking to prevent multiple processes/threads to write to the public ip cache file
|
9
|
+
|
10
|
+
## [1.0.11] - 2021-06-14
|
11
|
+
|
12
|
+
- Log hostname when reporting unhandled exceptions
|
13
|
+
|
14
|
+
## [1.0.10] - 2021-06-09
|
15
|
+
|
16
|
+
- Cache public IP in `/tmp/.sparoid_public_ip` for 1 min
|
17
|
+
|
18
|
+
## [1.0.9] - 2021-05-23
|
19
|
+
|
20
|
+
- Exit gracefully on abort (ctrl-c) instead of dumping huge stacktrace
|
21
|
+
- Sleep 20ms aftering sending UDP package to allow for remote host to open its firewall
|
22
|
+
|
1
23
|
## [1.0.8] - 2021-04-27
|
2
24
|
|
3
25
|
- Get ENV variables if config file is missing
|
data/Gemfile
CHANGED
@@ -5,12 +5,9 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in sparoid.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
8
|
gem "minitest", "~> 5.0"
|
11
|
-
|
9
|
+
gem "minitest-stub-const"
|
10
|
+
gem "rake", "~> 13.0"
|
12
11
|
gem "rubocop", "~> 1.7"
|
13
|
-
|
14
12
|
gem "rubocop-minitest", require: false
|
15
|
-
|
16
13
|
gem "rubocop-rake", require: false
|
data/README.md
CHANGED
data/exe/sparoid
CHANGED
data/lib/sparoid.rb
CHANGED
@@ -9,11 +9,18 @@ require "resolv"
|
|
9
9
|
module Sparoid
|
10
10
|
extend self
|
11
11
|
|
12
|
+
SPAROID_CACHE_PATH = ENV.fetch("SPAROID_CACHE_PATH", "/tmp/.sparoid_public_ip")
|
13
|
+
|
12
14
|
# Send an authorization packet
|
13
15
|
def auth(key, hmac_key, host, port)
|
14
|
-
msg = message(
|
16
|
+
msg = message(cached_public_ip)
|
15
17
|
data = prefix_hmac(hmac_key, encrypt(key, msg))
|
16
18
|
sendmsg(host, port, data)
|
19
|
+
|
20
|
+
# wait some time for the server to actually open the port
|
21
|
+
# if we don't wait the next SYN package will be dropped
|
22
|
+
# and it have to be redelivered, adding 1 second delay
|
23
|
+
sleep 0.02
|
17
24
|
end
|
18
25
|
|
19
26
|
# Generate new aes and hmac keys, print to stdout
|
@@ -67,7 +74,46 @@ module Sparoid
|
|
67
74
|
version = 1
|
68
75
|
ts = (Time.now.utc.to_f * 1000).floor
|
69
76
|
nounce = OpenSSL::Random.random_bytes(16)
|
70
|
-
[version, ts, nounce, ip.address].pack("
|
77
|
+
[version, ts, nounce, ip.address].pack("N q> a16 a4")
|
78
|
+
end
|
79
|
+
|
80
|
+
def cached_public_ip
|
81
|
+
if up_to_date_cache?
|
82
|
+
read_cache
|
83
|
+
else
|
84
|
+
write_cache
|
85
|
+
end
|
86
|
+
rescue StandardError => e
|
87
|
+
warn "Sparoid: #{e.inspect}"
|
88
|
+
public_ip
|
89
|
+
end
|
90
|
+
|
91
|
+
def up_to_date_cache?
|
92
|
+
mtime = File.mtime(SPAROID_CACHE_PATH)
|
93
|
+
(Time.now - mtime) <= 60 # cache is valid for 1 min
|
94
|
+
rescue Errno::ENOENT
|
95
|
+
false
|
96
|
+
end
|
97
|
+
|
98
|
+
def read_cache
|
99
|
+
File.open(SPAROID_CACHE_PATH, "r") do |f|
|
100
|
+
f.flock(File::LOCK_SH)
|
101
|
+
Resolv::IPv4.create f.read
|
102
|
+
end
|
103
|
+
rescue ArgumentError => e
|
104
|
+
return write_cache if e.message =~ /cannot interpret as IPv4 address/
|
105
|
+
|
106
|
+
raise e
|
107
|
+
end
|
108
|
+
|
109
|
+
def write_cache
|
110
|
+
File.open(SPAROID_CACHE_PATH, File::WRONLY | File::CREAT, 0o0644) do |f|
|
111
|
+
f.flock(File::LOCK_EX)
|
112
|
+
ip = public_ip
|
113
|
+
f.truncate(0)
|
114
|
+
f.write ip.to_s
|
115
|
+
ip
|
116
|
+
end
|
71
117
|
end
|
72
118
|
|
73
119
|
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"
|
data/lib/sparoid/version.rb
CHANGED
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.
|
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.
|
4
|
+
version: 1.0.13
|
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-
|
11
|
+
date: 2021-06-30 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.
|
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.
|
72
|
+
rubygems_version: 3.1.6
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Single Packet Authorisation client
|