Skip to content

Commit 09724b8

Browse files
authored
Merge pull request #19 from systemli/remove_onion_v2_support
Remove support for onion services in version 2
2 parents 687c204 + c78fcce commit 09724b8

File tree

5 files changed

+16
-94
lines changed

5 files changed

+16
-94
lines changed

README.md

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ Hint: It may take up to one minute, until the service is announced in the tor ne
1212

1313
Be careful: Using the default 127.0.0.1 as Onion Service IP-address could possibly leak meta data: https://help.riseup.net/en/security/network-security/tor/onionservices-best-practices#be-careful-of-localhost-bypasses
1414

15-
Supports [Next Gen Onion Services](https://trac.torproject.org/projects/tor/wiki/doc/NextGenOnions#Howtosetupyourownprop224service) only if tor version >= [0.3.2.1](https://blog.torproject.org/tor-0321-alpha-released-support-next-gen-onion-services-and-kist-scheduler)!
16-
Since Tor 0.3.5.0 HiddenServices v3 is the default. You have to set `onion_version: 2` if you want to use former onion services.
15+
Only supports Onion Services in version 3 previously known as [Next Gen Onion Services](https://trac.torproject.org/projects/tor/wiki/doc/NextGenOnions#Howtosetupyourownprop224service) only if tor version >= [0.3.2.1](https://blog.torproject.org/tor-0321-alpha-released-support-next-gen-onion-services-and-kist-scheduler)!
16+
17+
Version 2 Onion Services are currently in a [deprecation phase](https://blog.torproject.org/v2-deprecation-timeline).
18+
If you need an v2 onion service, please use a previous release of this role!
1719

1820
Role Variables
1921
--------------
@@ -66,56 +68,26 @@ onion_active: True
6668
onion_ipaddr: 192.168.3.12
6769
6870
onion_services:
69-
ssh:
70-
onion_hostname:
71-
onion_version: 2
72-
onion_ports:
73-
- [22, 22]
74-
onion_private_key:
75-
mail:
76-
onion_hostname:
77-
onion_version: 2
78-
onion_ports:
79-
- [25, 25] #[redirected_from, redirected_to]
80-
- [587,587]
81-
onion_private_key:
82-
examplewithhostname:
83-
onion_hostname: onionurl.onion
84-
onion_version: 2
71+
#
72+
# nextgeneration onion (v3) only available in tor >= 0.3.2.1
73+
# https://trac.torproject.org/projects/tor/wiki/doc/NextGenOnions#Howtosetupyourownprop224service
74+
#
75+
nextgenonion:
76+
onion_hostname: onionv3url.onion
8577
onion_ports:
8678
- [25, 25]
8779
- [587,587]
88-
onion_private_key: |
89-
-----BEGIN RSA PRIVATE KEY-----
90-
the
91-
private
92-
key
93-
-----END RSA PRIVATE KEY-----
80+
onion_public_key_b64encoded: "\nPT0gZWQyNTUxOaYxLXB1YmxpYzogdHlwZTAgPT0AAABADSX6gVbfuClP6aBXz8V00oMw5Sovn0ZU\nftKei9UWmw==\n"
81+
onion_secret_key_b64encoded: "\nPT0gZWQyNTUxOaYxLXNlY3JldDogdHlwZTAgPT0AAAAYzbVMulElZeorlRoSKWG4VVVwWQN0lHac\nhpR5jLcqb2iuHQu7K9yrdRUrSUWW42gFUvl7lCDQPV7aGWQcf9TI\n"
82+
9483
absentonion:
9584
onion_state: absent
96-
onion_version: 2
97-
onion_hostname: onionurl.onion
98-
onion_ports:
99-
- [25, 25]
100-
- [587,587]
101-
onion_private_key: |
102-
-----BEGIN RSA PRIVATE KEY-----
103-
the
104-
private
105-
key
106-
-----END RSA PRIVATE KEY-----
107-
#
108-
# nextgeneration onion only available in tor >= 0.3.2.1
109-
# https://trac.torproject.org/projects/tor/wiki/doc/NextGenOnions#Howtosetupyourownprop224service
110-
#
111-
nextgenonion:
11285
onion_hostname: onionv3url.onion
11386
onion_ports:
11487
- [25, 25]
11588
- [587,587]
11689
onion_public_key_b64encoded: "\nPT0gZWQyNTUxOaYxLXB1YmxpYzogdHlwZTAgPT0AAABADSX6gVbfuClP6aBXz8V00oMw5Sovn0ZU\nftKei9UWmw==\n"
11790
onion_secret_key_b64encoded: "\nPT0gZWQyNTUxOaYxLXNlY3JldDogdHlwZTAgPT0AAAAYzbVMulElZeorlRoSKWG4VVVwWQN0lHac\nhpR5jLcqb2iuHQu7K9yrdRUrSUWW42gFUvl7lCDQPV7aGWQcf9TI\n"
118-
11991
12092
#
12193
# Example for torrc with special onion configurations
@@ -160,7 +132,7 @@ For developing and testing the role we use Github Actions, Molecule, and Vagrant
160132
Run local tests with:
161133

162134
```
163-
molecule test
135+
molecule test
164136
```
165137

166138
License

molecule/default/molecule.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ driver:
66
platforms:
77
- name: buster64
88
box: debian/buster64
9-
# - name: stretch64
10-
# box: debian/stretch64
11-
# - name: jessie64
12-
# box: debian/jessie64
13-
# - name: xenial64
14-
# box: ubuntu/xenial64
159
# - name: bionic64
1610
# box: ubuntu/bionic64
1711
lint: |

tasks/main.yml

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
---
2-
# tasks file for onion
3-
42
- name: Ensure gpg is present
53
apt:
64
pkg: gnupg
@@ -31,18 +29,6 @@
3129
pkg: tor
3230
state: "{{ onion_tor_apt_state }}"
3331

34-
#
35-
# - removed trailing 0: 0.3.2.1 --> 3.2.1
36-
# - jinja2 filter compare version is allowing max. two dots (https://pizjix.com/version-numbers-in-ansible-code/)
37-
# - comparision is needed as safety, to not deploy onions in version 3,
38-
# if the tor version does not support it
39-
#
40-
- name: register version of tor
41-
shell: "executable=/bin/bash set -o pipefail && tor --version | cut -d' ' -f3 | cut -d. -f2- | sed 's/\\.$//'"
42-
register: tor_version
43-
check_mode: no
44-
changed_when: false
45-
4632
- name: install extra tor packages
4733
apt:
4834
pkg: "{{ onion_apt_packages }}"
@@ -83,22 +69,6 @@
8369
- item.value.onion_state|default('present') == 'present'
8470
notify: restart tor
8571

86-
- name: ensure private_key file are present (for onion v2)
87-
template:
88-
src: private_key.j2
89-
dest: "/var/lib/tor/{{ item.key }}/private_key"
90-
owner: debian-tor
91-
group: debian-tor
92-
mode: 0600
93-
backup: yes
94-
with_dict: "{{ onion_services }}"
95-
when:
96-
- item.value.onion_private_key is defined
97-
- item.value.onion_private_key
98-
- item.value.onion_version|default(3) == 2
99-
- item.value.onion_state|default('present') == 'present'
100-
notify: restart tor
101-
10272
- name: copy encoded public_key (only for onion v3)
10373
shell: "executable=/bin/bash set -o pipefail &&\
10474
echo \"{{ item.value.onion_public_key_b64encoded }}\" | base64 -d >/var/lib/tor/{{ item.key }}/hs_ed25519_public_key"
@@ -108,7 +78,6 @@ echo \"{{ item.value.onion_public_key_b64encoded }}\" | base64 -d >/var/lib/tor/
10878
when:
10979
- item.value.onion_public_key_b64encoded is defined
11080
- item.value.onion_public_key_b64encoded
111-
- item.value.onion_version|default(3) == 3
11281
- item.value.onion_state|default('present') == 'present'
11382
notify: restart tor
11483

@@ -122,7 +91,6 @@ echo \"{{ item.value.onion_public_key_b64encoded }}\" | base64 -d >/var/lib/tor/
12291
when:
12392
- item.value.onion_public_key_b64encoded is defined
12493
- item.value.onion_public_key_b64encoded
125-
- item.value.onion_version|default(3) == 3
12694
- item.value.onion_state|default('present') == 'present'
12795

12896
- name: copy encoded secret_key (only for onion v3)
@@ -134,7 +102,6 @@ echo \"{{ item.value.onion_secret_key_b64encoded }}\" | base64 -d >/var/lib/tor/
134102
when:
135103
- item.value.onion_secret_key_b64encoded is defined
136104
- item.value.onion_secret_key_b64encoded
137-
- item.value.onion_version|default(3) == 3
138105
- item.value.onion_state|default('present') == 'present'
139106
notify: restart tor
140107

@@ -148,25 +115,22 @@ echo \"{{ item.value.onion_secret_key_b64encoded }}\" | base64 -d >/var/lib/tor/
148115
when:
149116
- item.value.onion_secret_key_b64encoded is defined
150117
- item.value.onion_secret_key_b64encoded
151-
- item.value.onion_version|default(3) == 3
152118
- item.value.onion_state|default('present') == 'present'
153119

154120
- name: ensure onion directory is absent
155121
file:
156122
path: "/var/lib/tor/{{ item.key }}/"
157-
owner: debian-tor
158-
group: debian-tor
159123
mode: 0700
160124
state: absent
161125
with_dict: "{{ onion_services }}"
162126
when: item.value.onion_state|default('present') == "absent"
163127

164128
# The hostname file won't be created until the tor service
165-
# is reloaded, so bounce it before the `wait_for` task.
129+
# is restarted, so bounce it before the `wait_for` task.
166130
- name: restart tor if service was created
167131
service:
168132
name: tor
169-
state: reloaded
133+
state: restarted
170134
when: onion_directory_creation_result is changed
171135

172136
- name: wait for onion
@@ -192,7 +156,6 @@ echo \"{{ item.value.onion_secret_key_b64encoded }}\" | base64 -d >/var/lib/tor/
192156
when:
193157
- not item.value.onion_secret_key_b64encoded|default(false)
194158
- item.value.onion_state|default('present') != "absent"
195-
- item.value.onion_version|default(3) == 3
196159

197160
- name: read onion v3 public key
198161
command: base64 "/var/lib/tor/{{ item.key }}/hs_ed25519_public_key"
@@ -202,7 +165,6 @@ echo \"{{ item.value.onion_secret_key_b64encoded }}\" | base64 -d >/var/lib/tor/
202165
when:
203166
- not item.value.onion_public_key_b64encoded|default(false)
204167
- item.value.onion_state|default('present') != "absent"
205-
- item.value.onion_version|default(3) == 3
206168

207169
- name: display onion url
208170
debug:

templates/private_key.j2

Lines changed: 0 additions & 1 deletion
This file was deleted.

templates/torrc.j2

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@ HidServAuth {{ client }}
7979
{% for servicename, hsproperties in onion_services|dictsort %}
8080
{% if hsproperties['onion_state']|default('present') != 'absent' %}
8181
HiddenServiceDir /var/lib/tor/{{ servicename }}/
82-
{% if hsproperties['onion_version']|default(2) == 3 and tor_version.stdout is version_compare('3.2.1', '>=', strict=True) and tor_version.stdout is version_compare('3.2.5', '<', strict=True) %}
8382
HiddenServiceVersion 3
84-
{% endif %}
85-
{% if hsproperties['onion_version']|default(3) == 2 and tor_version.stdout is version_compare('3.2.5', '>=', strict=True) %}
86-
HiddenServiceVersion 2
87-
{% endif %}
8883
{% for port in hsproperties['onion_ports'] %}
8984
HiddenServicePort {{ port.0 }} {{ onion_ipaddr }}:{{ port.1}}
9085
{% endfor %}

0 commit comments

Comments
 (0)