sparoid 1.0.5 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +21 -0
- data/README.md +1 -1
- data/exe/sparoid +6 -2
- data/lib/sparoid.rb +28 -3
- data/lib/sparoid/cli.rb +5 -0
- 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: 864cabc794097c6a5f46cef69a72031f133d4bb1534193fce13319030ee09181
|
4
|
+
data.tar.gz: c5c7a75a8eea8eca65e29cea1e82f82aa16643d36a42dcbbceb7cf061d9755c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bfe6cfcd4dd1ad2b4577eda01b6972b7c36f8f418d64b5bbc2966e5cfc3538a1cf647ec8389108c5ecfc082cd420bb5d3483d4ae9f4d76e9b62709e865e4683
|
7
|
+
data.tar.gz: 82e84fc4deb3251d6c6c270cf5404da15ab91746bfd9d8de3a7f62152e8cccffa30dd43da7a8157f2a10627cefae79cc4dea5160fabfec3c0005c46202568568
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## [1.0.10] - 2021-06-09
|
2
|
+
|
3
|
+
- Cache public IP in /tmp/.sparoid_public_ip for 1 min
|
4
|
+
|
5
|
+
## [1.0.9] - 2021-05-23
|
6
|
+
|
7
|
+
- Exit gracefully on abort (ctrl-c) instead of dumping huge stacktrace
|
8
|
+
- Sleep 20ms aftering sending UDP package to allow for remote host to open its firewall
|
9
|
+
|
10
|
+
## [1.0.8] - 2021-04-27
|
11
|
+
|
12
|
+
- Get ENV variables if config file is missing
|
13
|
+
|
14
|
+
## [1.0.7] - 2021-04-27
|
15
|
+
|
16
|
+
- Get key and hmac key from ENV variables
|
17
|
+
|
18
|
+
## [1.0.6] - 2021-04-13
|
19
|
+
|
20
|
+
- Use static IP for opendns resolver, saves one DNS lookup
|
21
|
+
|
1
22
|
## [1.0.5] - 2021-04-12
|
2
23
|
|
3
24
|
- Prefix all logging with `Sparoid: `
|
data/README.md
CHANGED
data/exe/sparoid
CHANGED
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(
|
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,11 +72,31 @@ 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("
|
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
|
74
|
-
Resolv::DNS.open(nameserver: ["
|
99
|
+
Resolv::DNS.open(nameserver: ["208.67.222.222", "208.67.220.220"]) do |dns|
|
75
100
|
dns.getresource("myip.opendns.com", Resolv::DNS::Resource::IN::A).address
|
76
101
|
end
|
77
102
|
end
|
data/lib/sparoid/cli.rb
CHANGED
@@ -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)
|
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.10
|
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-09 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.2.
|
72
|
+
rubygems_version: 3.2.15
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Single Packet Authorisation client
|