zwiebel 0.0.1 → 0.0.2

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: 4ed9636194670d3f271d7617a51d3da0dfaf2b224a8eb3e6046af41eebfdd6ba
4
- data.tar.gz: ceccaf9cfe454e4f3cddd6d46698163353337db81ab31d05b61a14ccfd85b5be
3
+ metadata.gz: d20ac52d5ea64e997b8e609b6a45a695cee8603062060a129dd281e9eec1253c
4
+ data.tar.gz: 280ec7ab0310cfca61988e163b3b8fbdebb64d00fa216eb5904d6c948283d422
5
5
  SHA512:
6
- metadata.gz: 8906bafe70a0cf0f1314d0a05e0a5afc7ebf9674b0a0f310ea5c55ac20c34895b0048c0a09b08ca87b9259c44ff79995fa5788bb8e67ca817d04166a980ab327
7
- data.tar.gz: 89af7bf58f4f9a03c00666d04b3503d3460fe6657dd895af2b1878c7314ef8916a8b3029c508885f97f8865924a841a632092c8269d81a39467a0aefe5172a08
6
+ metadata.gz: bfc8f8480cd958c4eef39bab377bfb6ae5019c461cc53285f06075ca618899e4dfbb69cc7bf1576b05b39e7a8995b8ebf33eb7824b2cde37aadb786415abf616
7
+ data.tar.gz: 04c5f00b8fe9a4725b8030464f34654777d64d44d142aa7e81dc6634bbc44aae67534e755e0fd94885b09e251ebdbef26e58c969f9282a09600a1790ed024579
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Zwiebel
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.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.1
4
+ version: 0.0.2
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-04 00:00:00.000000000 Z
11
+ date: 2023-11-14 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: '0'
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: '0'
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: