Skip to content

Commit

Permalink
Detect filtered Tor controller commands
Browse files Browse the repository at this point in the history
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
alvasw committed May 19, 2024
1 parent afe249a commit 126f044
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package bisq.tor.controller;

public class TorCommandFilteredException extends RuntimeException {
}
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();
}
}
}

0 comments on commit 126f044

Please sign in to comment.