zwiebel 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zwiebel/control.rb +81 -0
- data/lib/zwiebel/version.rb +1 -1
- data/lib/zwiebel.rb +58 -0
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a178968188ad9e5311134ddd77ecba849f4f8708da9580800e55053f7e459355
|
4
|
+
data.tar.gz: 8bed48748a9f51a1236493e63c4b808d6e9ee55c621db83eb58b2b62cedc87e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f98941b8129bc0ad692a8a17e780311accafe7be99e62a056f6c2b831e2633dbf76fa643ddd8f593a4d89fe22fac18e243c8e75ecc5213624d315cbd4c0dde9a
|
7
|
+
data.tar.gz: 7ed879c1236fb10f54a672041878ad64f63a8175a45dcf9b4556f3203ae84a9e69e73ae1beb5fbda5d1e1075f395c0aaf372f80ef9954c0e016cf5053ec06357
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Copyright 2023, Kurt Meyerhofer
|
2
|
+
# This file is part of zwiebel.
|
3
|
+
|
4
|
+
# zwiebel is free software: you can redistribute it and/or modify it under the terms of
|
5
|
+
# the GNU Lesser General Public License as published by the Free Software Foundation,
|
6
|
+
# either version 3 of the License, or (at your option) any later version.
|
7
|
+
|
8
|
+
# zwiebel is distributed in the hope that it will be useful, but WITHOUT ANY
|
9
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
11
|
+
# more details.
|
12
|
+
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License along with zwiebel.
|
14
|
+
# If not, see <https://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module Zwiebel
|
17
|
+
class Control
|
18
|
+
attr_accessor :cookie, :host, :port
|
19
|
+
|
20
|
+
def initialize(host: "127.0.0.1", port: 9051, cookie: nil)
|
21
|
+
@host = host
|
22
|
+
@port = port
|
23
|
+
@cookie = cookie
|
24
|
+
connect
|
25
|
+
end
|
26
|
+
|
27
|
+
def connect
|
28
|
+
close
|
29
|
+
@socket = TCPSocket.new(host, port)
|
30
|
+
@socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
|
31
|
+
end
|
32
|
+
|
33
|
+
def connected?
|
34
|
+
!@socket.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def close
|
38
|
+
@socket.close unless @socket.nil?
|
39
|
+
@authenticated = false
|
40
|
+
@socket = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def quit
|
44
|
+
send_line("QUIT")
|
45
|
+
reply = read_reply
|
46
|
+
close
|
47
|
+
reply
|
48
|
+
end
|
49
|
+
|
50
|
+
def authenticate
|
51
|
+
send_line(@cookie ? "AUTHENTICATE #{cookie}" : "AUTHENTICATE")
|
52
|
+
reply = read_reply
|
53
|
+
@authenticated = reply == "250 OK"
|
54
|
+
end
|
55
|
+
|
56
|
+
def authenticated?
|
57
|
+
!!@authenticated
|
58
|
+
end
|
59
|
+
|
60
|
+
def version
|
61
|
+
send_command("GETINFO", "version")
|
62
|
+
reply = read_reply.split("=").last
|
63
|
+
read_reply
|
64
|
+
reply
|
65
|
+
end
|
66
|
+
|
67
|
+
def send_command(command, *args)
|
68
|
+
authenticate unless authenticated?
|
69
|
+
send_line([command, *args].join(" "))
|
70
|
+
end
|
71
|
+
|
72
|
+
def send_line(line)
|
73
|
+
@socket.write("#{line}\r\n")
|
74
|
+
@socket.flush
|
75
|
+
end
|
76
|
+
|
77
|
+
def read_reply
|
78
|
+
@socket.readline.chomp
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/zwiebel/version.rb
CHANGED
data/lib/zwiebel.rb
CHANGED
@@ -1,2 +1,60 @@
|
|
1
|
+
# Copyright 2023, Kurt Meyerhofer
|
2
|
+
# This file is part of zwiebel.
|
3
|
+
|
4
|
+
# zwiebel is free software: you can redistribute it and/or modify it under the terms of
|
5
|
+
# the GNU Lesser General Public License as published by the Free Software Foundation,
|
6
|
+
# either version 3 of the License, or (at your option) any later version.
|
7
|
+
|
8
|
+
# zwiebel is distributed in the hope that it will be useful, but WITHOUT ANY
|
9
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
11
|
+
# more details.
|
12
|
+
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License along with zwiebel.
|
14
|
+
# If not, see <https://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "base32"
|
17
|
+
require_relative "zwiebel/control"
|
18
|
+
require_relative "zwiebel/version"
|
19
|
+
|
1
20
|
module Zwiebel
|
21
|
+
|
22
|
+
def self.v3_address_valid?(address)
|
23
|
+
# tor address-spec
|
24
|
+
# onion_address = base32(PUBKEY | CHECKSUM | VERSION)
|
25
|
+
# CHECKSUM = H(".onion checksum" | PUBKEY | VERSION)[:2]
|
26
|
+
|
27
|
+
# where:
|
28
|
+
# - PUBKEY is the 32 bytes ed25519 master pubkey of the onion service.
|
29
|
+
# - VERSION is a one byte version field (default value '\x03')
|
30
|
+
# - ".onion checksum" is a constant string
|
31
|
+
# - H is SHA3-256
|
32
|
+
# - CHECKSUM is truncated to two bytes before inserting it in onion_address
|
33
|
+
|
34
|
+
return false unless address.is_a?(String) && address.end_with?(".onion") && address.length == 62
|
35
|
+
|
36
|
+
decoded_address = Base32.decode(address.gsub(".onion", "").upcase)
|
37
|
+
pubkey = decoded_address.byteslice(0, 32)
|
38
|
+
checksum = decoded_address.byteslice(32, 2)
|
39
|
+
version = decoded_address.byteslice(34)
|
40
|
+
|
41
|
+
onion_checksum = ".onion checksum"
|
42
|
+
calculated_checksum = onion_checksum + pubkey + version
|
43
|
+
|
44
|
+
digest = OpenSSL::Digest.digest("SHA3-256", calculated_checksum)
|
45
|
+
checksum_truncated = digest.byteslice(0, 2)
|
46
|
+
|
47
|
+
checksum_truncated == checksum
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.cookie_file_hash(file_path:)
|
51
|
+
if !File.exist?(file_path)
|
52
|
+
raise StandardError "cookie file not present"
|
53
|
+
elsif !File.readable?(file_path)
|
54
|
+
raise StandardError "not permitted to read cookie file"
|
55
|
+
else
|
56
|
+
data = IO.binread(file_path)
|
57
|
+
data.unpack("H*")[0]
|
58
|
+
end
|
59
|
+
end
|
2
60
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zwiebel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurt Meyerhofer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base32
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.12'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.12'
|
41
41
|
description: zwiebel is a Tor network hidden service connector for version 3 .onion
|
42
42
|
addresses.
|
43
43
|
email:
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- lib/zwiebel.rb
|
49
|
+
- lib/zwiebel/control.rb
|
49
50
|
- lib/zwiebel/version.rb
|
50
51
|
homepage: https://github.com/kmeyerhofer/zwiebel
|
51
52
|
licenses:
|