-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect filtered Tor controller commands
Tails and Whonix use onion-grater to filter dangerous Tor control protocol commands. Therefore, users need to enable the Bisq onion-grater profile on those operating systems. We should detect filtered commands and help users to setup their operating system. Ref: #1894
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
network/tor/tor/src/main/java/bisq/tor/controller/TorCommandFilteredException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package bisq.tor.controller; | ||
|
||
public class TorCommandFilteredException extends RuntimeException { | ||
} |
41 changes: 41 additions & 0 deletions
41
network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package bisq.tor.controller; | ||
|
||
import bisq.security.keys.TorKeyPair; | ||
|
||
import java.io.*; | ||
import java.net.Socket; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class WhonixTorController implements AutoCloseable { | ||
private final Socket controlSocket; | ||
private final BufferedReader bufferedReader; | ||
private final OutputStream outputStream; | ||
|
||
public WhonixTorController() throws IOException { | ||
controlSocket = new Socket("127.0.0.1", 9051); | ||
|
||
InputStream inputStream = controlSocket.getInputStream(); | ||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.US_ASCII)); | ||
|
||
outputStream = controlSocket.getOutputStream(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
controlSocket.close(); | ||
} | ||
|
||
public void addOnion(TorKeyPair torKeyPair, int onionPort, int localPort) throws IOException { | ||
String base64SecretScalar = torKeyPair.getBase64SecretScalar(); | ||
String command = "ADD_ONION " + "ED25519-V3:" + base64SecretScalar + " Port=" + onionPort + "," + localPort + "\r\n"; | ||
byte[] commandBytes = command.getBytes(StandardCharsets.US_ASCII); | ||
|
||
outputStream.write(commandBytes); | ||
outputStream.flush(); | ||
|
||
String reply = bufferedReader.readLine(); | ||
if (reply.equals("510 Command filtered")) { | ||
throw new TorCommandFilteredException(); | ||
} | ||
} | ||
} |