From 6157c5653e8e468c5d6f33a997d66ed38f2d625a Mon Sep 17 00:00:00 2001
From: Benjamin Erhart <berhart@netzarchitekten.com>
Date: Tue, 11 Oct 2022 11:14:59 +0200
Subject: [PATCH] Added `Obfs4proxyLogFile()`, which returns Obfs4proxy's
constant used as log file name.
---
IPtProxy.go/IPtProxy.go | 86 +++++++++++++++++++--------------
IPtProxy.xcframework/Info.plist | 12 ++---
obfs4.patch | 21 ++++----
3 files changed, 66 insertions(+), 53 deletions(-)
diff --git a/IPtProxy.go/IPtProxy.go b/IPtProxy.go/IPtProxy.go
index c2b9b2f..9fea4f3 100644
--- a/IPtProxy.go/IPtProxy.go
+++ b/IPtProxy.go/IPtProxy.go
@@ -9,10 +9,11 @@ import (
"log"
"net"
"os"
+ "path/filepath"
"runtime"
+ "runtime/debug"
"strconv"
"time"
- "runtime/debug"
)
var meekPort = 47000
@@ -89,37 +90,46 @@ func init() {
StateLocation = os.Getenv("TMPDIR")
}
- StateLocation += "/pt_state"
+ StateLocation = filepath.Join(StateLocation, "pt_state")
}
// Obfs4ProxyVersion - The version of Obfs4Proxy bundled with IPtProxy.
//
//goland:noinspection GoUnusedExportedFunction
func Obfs4ProxyVersion() string {
- return obfs4proxy.Obfs4proxyVersion
+ return obfs4proxy.Obfs4proxyVersion
}
-// SnowflakeVersion - The version of Snowflake bundled with IPtProxy.
+// SnowflakeVersion - The version of Snowflake bundled with IPtProxy.
//
//goland:noinspection GoUnusedExportedFunction
func SnowflakeVersion() string {
- bi, ok := debug.ReadBuildInfo()
- if !ok {
- log.Printf("Failed to read build info")
- return ""
- }
-
- for _, dep := range bi.Deps {
- if dep.Path == "git.torproject.org/pluggable-transports/snowflake.git/v2" {
- if dep.Version[0:1] == "v" {
- return dep.Version[1:len(dep.Version)]
- } else {
- return dep.Version
- }
- }
- }
-
- return ""
+ bi, ok := debug.ReadBuildInfo()
+ if !ok {
+ log.Printf("Failed to read build info")
+ return ""
+ }
+
+ for _, dep := range bi.Deps {
+ if dep.Path == "git.torproject.org/pluggable-transports/snowflake.git/v2" {
+ if dep.Version[0:1] == "v" {
+ return dep.Version[1:len(dep.Version)]
+ } else {
+ return dep.Version
+ }
+ }
+ }
+
+ return ""
+}
+
+// Obfs4proxyLogFile - The log file name used by Obfs4proxy.
+//
+// The Obfs4proxy log file can be found at `filepath.Join(StateLocation, Obfs4proxyLogFile())`.
+//
+//goland:noinspection GoUnusedExportedFunction
+func Obfs4proxyLogFile() string {
+ return obfs4proxy.Obfs4proxyLogFile
}
// StartObfs4Proxy - Start the Obfs4Proxy.
@@ -136,6 +146,7 @@ func SnowflakeVersion() string {
// @param proxy HTTP, SOCKS4 or SOCKS5 proxy to be used behind Obfs4proxy. E.g. "socks5://127.0.0.1:12345"
//
// @return Port number where Obfs4Proxy will listen on for Obfs4(!), if no error happens during start up.
+//
// If you need the other ports, check MeekPort, Obfs2Port, Obfs3Port and ScramblesuitPort properties!
//
//goland:noinspection GoUnusedExportedFunction
@@ -217,7 +228,8 @@ func StopObfs4Proxy() {
// @param front Front domain.
//
// @param ampCache OPTIONAL. URL of AMP cache to use as a proxy for signaling.
-// Only needed when you want to do the rendezvous over AMP instead of a domain fronted server.
+//
+// Only needed when you want to do the rendezvous over AMP instead of a domain fronted server.
//
// @param logFile Name of log file. OPTIONAL. Defaults to no log.
//
@@ -289,8 +301,9 @@ type SnowflakeClientConnected interface {
// @param unsafeLogging Prevent logs from being scrubbed.
//
// @param clientConnected A delegate which is called when a client successfully connected.
-// Will be called on its own thread! You will need to switch to your own UI thread,
-// if you want to do UI stuff!! OPTIONAL
+//
+// Will be called on its own thread! You will need to switch to your own UI thread,
+// if you want to do UI stuff!! OPTIONAL
//
//goland:noinspection GoUnusedExportedFunction
func StartSnowflakeProxy(capacity int, broker, relay, stun, natProbe, logFile string, keepLocalAddresses, unsafeLogging bool, clientConnected SnowflakeClientConnected) {
@@ -302,16 +315,16 @@ func StartSnowflakeProxy(capacity int, broker, relay, stun, natProbe, logFile st
capacity = 0
}
- snowflakeProxy = &sfp.SnowflakeProxy {
- Capacity: uint(capacity),
- STUNURL: stun,
- BrokerURL: broker,
- KeepLocalAddresses: keepLocalAddresses,
- RelayURL: relay,
- NATProbeURL: natProbe,
- ProxyType: "iptproxy",
+ snowflakeProxy = &sfp.SnowflakeProxy{
+ Capacity: uint(capacity),
+ STUNURL: stun,
+ BrokerURL: broker,
+ KeepLocalAddresses: keepLocalAddresses,
+ RelayURL: relay,
+ NATProbeURL: natProbe,
+ ProxyType: "iptproxy",
RelayDomainNamePattern: "snowflake.torproject.net$",
- AllowNonTLSRelay: false,
+ AllowNonTLSRelay: false,
ClientConnectedCallback: func() {
if clientConnected != nil {
clientConnected.Connected()
@@ -326,7 +339,7 @@ func StartSnowflakeProxy(capacity int, broker, relay, stun, natProbe, logFile st
log.SetFlags(log.LstdFlags | log.LUTC)
if logFile != "" {
- f, err := os.OpenFile(logFile, os.O_CREATE | os.O_WRONLY | os.O_APPEND, 0600)
+ f, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
log.Fatal(err)
}
@@ -352,6 +365,7 @@ func StartSnowflakeProxy(capacity int, broker, relay, stun, natProbe, logFile st
func IsSnowflakeProxyRunning() bool {
return snowflakeProxy != nil
}
+
// StopSnowflakeProxy - Stop the Snowflake proxy.
//
//goland:noinspection GoUnusedExportedFunction
@@ -364,7 +378,7 @@ func StopSnowflakeProxy() {
snowflakeProxy.Stop()
}(snowflakeProxy)
- snowflakeProxy = nil
+ snowflakeProxy = nil
}
// IsPortAvailable - Checks to see if a given port is not in use.
@@ -373,7 +387,7 @@ func StopSnowflakeProxy() {
func IsPortAvailable(port int) bool {
address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
- conn, err := net.DialTimeout("tcp", address, 500 * time.Millisecond)
+ conn, err := net.DialTimeout("tcp", address, 500*time.Millisecond)
if err != nil {
return true
diff --git a/IPtProxy.xcframework/Info.plist b/IPtProxy.xcframework/Info.plist
index 48ebd66..12a4244 100644
--- a/IPtProxy.xcframework/Info.plist
+++ b/IPtProxy.xcframework/Info.plist
@@ -6,7 +6,7 @@
<array>
<dict>
<key>LibraryIdentifier</key>
- <string>ios-arm64_x86_64-simulator</string>
+ <string>macos-arm64_x86_64</string>
<key>LibraryPath</key>
<string>IPtProxy.framework</string>
<key>SupportedArchitectures</key>
@@ -15,9 +15,7 @@
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
- <string>ios</string>
- <key>SupportedPlatformVariant</key>
- <string>simulator</string>
+ <string>macos</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
@@ -33,7 +31,7 @@
</dict>
<dict>
<key>LibraryIdentifier</key>
- <string>macos-arm64_x86_64</string>
+ <string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>IPtProxy.framework</string>
<key>SupportedArchitectures</key>
@@ -42,7 +40,9 @@
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
- <string>macos</string>
+ <string>ios</string>
+ <key>SupportedPlatformVariant</key>
+ <string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
diff --git a/obfs4.patch b/obfs4.patch
index f10da57..09ad0a4 100644
--- a/obfs4.patch
+++ b/obfs4.patch
@@ -1,5 +1,5 @@
diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go
-index f295926..5a2ce99 100644
+index f295926..df9627e 100644
--- a/obfs4proxy/obfs4proxy.go
+++ b/obfs4proxy/obfs4proxy.go
@@ -27,10 +27,9 @@
@@ -22,15 +22,14 @@ index f295926..5a2ce99 100644
"sync"
"syscall"
-@@ -51,6 +51,7 @@ import (
-
- const (
+@@ -53,12 +53,14 @@ const (
obfs4proxyVersion = "0.0.14"
-+ Obfs4proxyVersion = obfs4proxyVersion
obfs4proxyLogFile = "obfs4proxy.log"
socksAddr = "127.0.0.1:0"
++ Obfs4proxyVersion = obfs4proxyVersion
++ Obfs4proxyLogFile = obfs4proxyLogFile
)
-@@ -58,7 +59,7 @@ const (
+
var stateDir string
var termMon *termMonitor
@@ -39,7 +38,7 @@ index f295926..5a2ce99 100644
ptClientInfo, err := pt.ClientSetup(transports.Transports())
if err != nil {
golog.Fatal(err)
-@@ -85,7 +86,20 @@ func clientSetup() (launched bool, listeners []net.Listener) {
+@@ -85,7 +87,20 @@ func clientSetup() (launched bool, listeners []net.Listener) {
continue
}
@@ -61,7 +60,7 @@ index f295926..5a2ce99 100644
if err != nil {
_ = pt.CmethodError(name, err.Error())
continue
-@@ -304,22 +318,16 @@ func getVersion() string {
+@@ -304,22 +319,16 @@ func getVersion() string {
return fmt.Sprintf("obfs4proxy-%s", obfs4proxyVersion)
}
@@ -90,7 +89,7 @@ index f295926..5a2ce99 100644
if err := log.SetLogLevel(*logLevelStr); err != nil {
golog.Fatalf("[ERROR]: %s - failed to set log level: %s", execName, err)
}
-@@ -338,8 +346,7 @@ func main() {
+@@ -338,8 +347,7 @@ func main() {
golog.Fatalf("[ERROR]: %s - failed to initialize logging", execName)
}
if err = transports.Init(); err != nil {
@@ -100,7 +99,7 @@ index f295926..5a2ce99 100644
}
log.Noticef("%s - launched", getVersion())
-@@ -347,7 +354,7 @@ func main() {
+@@ -347,7 +355,7 @@ func main() {
// Do the managed pluggable transport protocol configuration.
if isClient {
log.Infof("%s - initializing client transport listeners", execName)
@@ -109,7 +108,7 @@ index f295926..5a2ce99 100644
} else {
log.Infof("%s - initializing server transport listeners", execName)
launched, ptListeners = serverSetup()
-@@ -379,3 +386,11 @@ func main() {
+@@ -379,3 +387,11 @@ func main() {
}
termMon.wait(true)
}
--
GitLab