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

Whonix only: Bind/listen on 0.0.0.0 instead of 127.0.0.1 #15

Merged
merged 1 commit into from Feb 6, 2023
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
1 change: 1 addition & 0 deletions tor/src/main/kotlin/org/berndpruenster/netlayer/tor/Tor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import java.security.MessageDigest


const val LOCAL_IP = "127.0.0.1"
const val EXTERNAL_IP = "0.0.0.0"
private const val LOCAL_ADDR_FRAGMENT = "\"" + LOCAL_IP + ":"
private const val NET_LISTENERS_SOCKS = "net/listeners/socks"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.runjva.sourceforge.jsocks.protocol.SocksSocket
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.io.*
import java.net.*
import java.nio.channels.SocketChannel
import java.util.*
Expand Down Expand Up @@ -190,10 +191,21 @@ class HiddenServiceSocket @JvmOverloads constructor(internalPort: Int,
val (name, handler) = mgr.publishHiddenService(hiddenServiceDir, hiddenServicePort, internalPort)
serviceName = name
socketAddress = HiddenServiceSocketAddress(name, hiddenServicePort)
bind(InetSocketAddress(LOCAL_IP, internalPort))
bind(InetSocketAddress(if (isWhonixWorkstation()) EXTERNAL_IP else LOCAL_IP, internalPort))
handler.attachReadyListeners(this, listeners)
}

private fun isWhonixWorkstation() : Boolean {
val testFile1 = File("/usr/share/whonix", "marker")
val testFile2 = File("/usr/share/anon-ws-base-files", "workstation")
return if (testFile1.exists() && testFile2.exists()) {
logger?.info("Whonix WS detected, binding to external interface.")
true
} else {
false
}
}

fun addReadyListener(listener: (socket: HiddenServiceSocket) -> Unit) {
synchronized(listeners) {
listeners.add(listener)
Expand Down