Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DirectoryAuthorityTorrcGenerator #926

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class DirectoryAuthorityKeyGenerationTests {
@Test
public void generateKeys(@TempDir Path tempDir) throws IOException, InterruptedException {
var torDAKeyGenProcess = new TorDAKeyGenProcess(tempDir, "127.0.0.1:8080");
var torDAKeyGenProcess = new DirectoryIdentityKeyGenProcess(tempDir, "127.0.0.1:8080");
var directoryAuthorityKeyGenerator = new DirectoryAuthorityKeyGenerator(torDAKeyGenProcess);
directoryAuthorityKeyGenerator.generate("my_passphrase");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@
@Getter
public class DirectoryAuthority {
private final String nickname;

private final Path dataDir;

private final int controlPort;
private final int orPort;
private final int dirPort;

private final String v3LongTermSigningKeyFingerprint;
private final String torKeyFingerprint;

private final String exitPolicy = "ExitPolicy accept *:*";

public Path getTorrcPath() {
return dataDir.resolve("torrc");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class DirectoryAuthorityKeyGenerator {
private static final String PEM_PASSPHRASE_PROMPT = "Enter PEM pass phrase:";
private static final String PEM_VERIFY_PASSPHRASE_PROMPT = "\nVerifying - Enter PEM pass phrase:";

private final TorDAKeyGenProcess keyGenProcess;
private final DirectoryIdentityKeyGenProcess keyGenProcess;

public DirectoryAuthorityKeyGenerator(TorDAKeyGenProcess keyGenProcess) {
public DirectoryAuthorityKeyGenerator(DirectoryIdentityKeyGenProcess keyGenProcess) {
this.keyGenProcess = keyGenProcess;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.tor.local_network;

import java.io.IOException;
import java.nio.file.Files;
import java.util.Set;

/**
* The configuration settings are from the Chutney (<a href="https://gitweb.torproject.org/chutney.git/">project</a>) and
* Antitree's private-tor-network (<a href="https://github.com/antitree/private-tor-network">project</a>).
*/
public class DirectoryAuthorityTorrcGenerator {
private final DirectoryAuthority thisDirectoryAuthority;
private final Set<DirectoryAuthority> allDirAuthorities;

public DirectoryAuthorityTorrcGenerator(DirectoryAuthority thisDirectoryAuthority, Set<DirectoryAuthority> allDirAuthorities) {
this.thisDirectoryAuthority = thisDirectoryAuthority;
this.allDirAuthorities = allDirAuthorities;
}

public void generate() throws IOException {
var stringBuilder = new StringBuilder();
stringBuilder.append("TestingTorNetwork 1\n")

.append("PathsNeededToBuildCircuits 0.67\n")
.append("TestingDirAuthVoteExit *\n")
.append("TestingDirAuthVoteHSDir *\n")
.append("V3AuthNIntervalsValid 2\n")

.append("TestingDirAuthVoteGuard *\n")
.append("TestingMinExitFlagThreshold 0\n")

.append("DataDirectory ").append(thisDirectoryAuthority.getDataDir()).append("\n")
.append("RunAsDaemon 1\n")
.append("Nickname ").append(thisDirectoryAuthority.getNickname()).append("\n")

.append("ShutdownWaitLength 2\n")
.append("DisableDebuggerAttachment 0\n")

.append("ControlPort 127.0.0.1:").append(thisDirectoryAuthority.getControlPort()).append("\n")
.append("CookieAuthentication 1\n")

.append("Log debug file ").append(thisDirectoryAuthority.getDataDir().resolve("debug.log").toAbsolutePath()).append("\n")
.append("ProtocolWarnings 1\n")
.append("SafeLogging 0\n")
.append("LogTimeGranularity 1\n")

.append("SocksPort 0\n")
.append("OrPort ").append(thisDirectoryAuthority.getOrPort()).append("\n")
.append("Address 127.0.0.1\n")

.append("ServerDNSDetectHijacking 0\n")
.append("ServerDNSTestAddresses\n")

.append("DirPort ").append(thisDirectoryAuthority.getDirPort()).append("\n")

.append("AuthoritativeDirectory 1\n")
.append("V3AuthoritativeDirectory 1\n")
.append("ContactInfo auth-").append(thisDirectoryAuthority.getNickname()).append("@test.test\n")

.append("AssumeReachable 1\n")

.append("TestingV3AuthInitialVotingInterval 20\n")
.append("TestingV3AuthInitialVoteDelay 4\n")
.append("TestingV3AuthInitialDistDelay 4\n")

.append("V3AuthVotingInterval 20\n")
.append("V3AuthVoteDelay 4\n")
.append("V3AuthDistDelay 4\n")

.append(thisDirectoryAuthority.getExitPolicy()).append("\n");

allDirAuthorities.forEach(dirAuthority ->
stringBuilder.append("DirAuthority ").append(dirAuthority.getNickname())
.append(" orport=").append(dirAuthority.getOrPort())
.append(" v3ident=").append(dirAuthority.getV3LongTermSigningKeyFingerprint())
.append(" 127.0.0.1:").append(dirAuthority.getDirPort())
.append(" ").append(dirAuthority.getTorKeyFingerprint())
.append("\n"));


Files.writeString(thisDirectoryAuthority.getTorrcPath(), stringBuilder.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.concurrent.TimeUnit;

@Slf4j
public class TorDAKeyGenProcess {
public class DirectoryIdentityKeyGenProcess {
private final Path torKeyDirPath;
private final String directoryAddress;

Expand All @@ -38,7 +38,7 @@ public class TorDAKeyGenProcess {
@Getter
private Optional<OutputStream> outputStream = Optional.empty();

public TorDAKeyGenProcess(Path torKeyDirPath, String directoryAddress) {
public DirectoryIdentityKeyGenProcess(Path torKeyDirPath, String directoryAddress) {
this.torKeyDirPath = torKeyDirPath;
this.directoryAddress = directoryAddress;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.tor.local_network;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

public class DirectoryAuthorityTorrcGeneratorTests {
@Test
void basicTest(@TempDir Path tempDir) throws IOException {
Path daAPath = tempDir.resolve("DA_A");
assertThat(daAPath.toFile().mkdir()).isTrue();

DirectoryAuthority firstDirAuth = DirectoryAuthority.builder()
.nickname("A")
.dataDir(daAPath)

.controlPort(1)
.orPort(2)
.dirPort(3)

.v3LongTermSigningKeyFingerprint("AAAA_v3")
.torKeyFingerprint("AAAA_fp")
.build();

DirectoryAuthority secondDirAuth = DirectoryAuthority.builder()
.nickname("B")
.dataDir(tempDir.resolve("DA_B"))

.controlPort(1)
.orPort(2)
.dirPort(3)

.v3LongTermSigningKeyFingerprint("BBBB_v3")
.torKeyFingerprint("BBBB_fp")
.build();

var allDirAuthorities = Set.of(firstDirAuth, secondDirAuth);

var torDaTorrcGenerator = new DirectoryAuthorityTorrcGenerator(firstDirAuth, allDirAuthorities);
torDaTorrcGenerator.generate();

assertThat(firstDirAuth.getTorrcPath())
.isNotEmptyFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void waitForPasswordPromptFullString() throws IOException, InterruptedExc

@Test
@Timeout(value = 30)
public void waitForPasswordPromptPartialReads() throws IOException, InterruptedException {
public void waitForPasswordPromptPartialReads() throws IOException {
var pipedOutputStream = new PipedOutputStream();
var pipedInputStream = new PipedInputStream(pipedOutputStream);

Expand Down