summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modes/transparent_tcp/transparent_tcp.go62
-rw-r--r--shapeshifter-dispatcher/shapeshifter-dispatcher.go34
2 files changed, 47 insertions, 49 deletions
diff --git a/modes/transparent_tcp/transparent_tcp.go b/modes/transparent_tcp/transparent_tcp.go
index ad85cff..e91eb3a 100644
--- a/modes/transparent_tcp/transparent_tcp.go
+++ b/modes/transparent_tcp/transparent_tcp.go
@@ -45,6 +45,7 @@ import (
"github.com/OperatorFoundation/shapeshifter-transports/transports/meeklite"
"github.com/OperatorFoundation/shapeshifter-transports/transports/obfs2"
"github.com/OperatorFoundation/shapeshifter-transports/transports/obfs4"
+ "github.com/OperatorFoundation/shapeshifter-transports/transports/shadow"
)
const (
@@ -56,7 +57,6 @@ var stateDir string
func ClientSetup(termMon *termmon.TermMonitor, target string, ptClientProxy *url.URL, names []string, options string) (launched bool, listeners []net.Listener) {
// Launch each of the client listeners.
for _, name := range names {
- fmt.Println("Listening ", socksAddr)
ln, err := net.Listen("tcp", socksAddr)
if err != nil {
log.Errorf("failed to listen %s %s", name, err.Error())
@@ -78,7 +78,6 @@ func clientAcceptLoop(target string, termMon *termmon.TermMonitor, name string,
defer ln.Close()
for {
conn, err := ln.Accept()
- fmt.Println("Accepted")
if err != nil {
if e, ok := err.(net.Error); ok && !e.Temporary() {
return err
@@ -94,15 +93,10 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt
termMon.OnHandlerStart()
defer termMon.OnHandlerFinish()
- fmt.Println("handling...")
-
- fmt.Println("Transport is", name, options)
-
var transport base.Transport
args, argsErr := pt.ParsePT2ClientParameters(options)
if argsErr != nil {
- fmt.Println("Bad client args")
log.Errorf("Error parsing transport options: %s", options)
return
}
@@ -123,13 +117,11 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt
return
}
case "obfs4":
- fmt.Println("Checking options")
if cert, ok := args["cert"]; ok {
if iatModeStr, ok2 := args["iatMode"]; ok2 {
iatMode, err := strconv.Atoi(iatModeStr[0])
if err == nil {
transport = obfs4.NewObfs4Client(cert[0], iatMode)
- fmt.Println("new client")
} else {
log.Errorf("obfs4 transport bad iatMode value: %s %s", iatModeStr[0], err)
return
@@ -142,6 +134,18 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt
log.Errorf("obfs4 transport missing cert argument: %s", args)
return
}
+ case "shadow":
+ if password, ok := args["password"]; ok {
+ if cipher, ok2 := args["cipherName"]; ok2 {
+ transport = shadow.NewShadowClient(password[0], cipher[0])
+ } else {
+ log.Errorf("shadow transport missing cipher argument: %s", args)
+ return
+ }
+ } else {
+ log.Errorf("shadow transport missing password argument: %s", args)
+ return
+ }
default:
log.Errorf("Unknown transport: %s", name)
return
@@ -149,8 +153,6 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt
f := transport.Dial
- fmt.Println("Making dialer...")
-
// Obtain the proxy dialer if any, and create the outgoing TCP connection.
// dialFn := proxy.Direct.Dial
// if proxyURI != nil {
@@ -158,19 +160,15 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt
// if err != nil {
// // This should basically never happen, since config protocol
// // verifies this.
- // fmt.Println("failed to obtain dialer", proxyURI, proxy.Direct)
// log.Errorf("%s(%s) - failed to obtain proxy dialer: %s", name, target, log.ElideError(err))
// return
// }
// dialFn = dialer.Dial
// }
- fmt.Println("Dialing...")
-
// FIXME - use dialFn if a proxy is needed to connect to the network
remote := f(target)
// if err != nil {
- // fmt.Println("outgoing connection failed")
// log.Errorf("%s(%s) - outgoing connection failed: %s", name, target, log.ElideError(err))
// return
// }
@@ -181,37 +179,28 @@ func clientHandler(target string, termMon *termmon.TermMonitor, name string, opt
defer remote.Close()
- fmt.Println("copying...")
-
if err := copyLoop(conn, remote); err != nil {
log.Warnf("%s(%s) - closed connection: %s", name, target, log.ElideError(err))
} else {
log.Infof("%s(%s) - closed connection", name, target)
}
- fmt.Println("done")
-
return
}
func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerInfo pt.ServerInfo, statedir string, options string) (launched bool, listeners []base.TransportListener) {
- fmt.Println("ServerSetup", bindaddrString, ptServerInfo, options)
-
// Launch each of the server listeners.
for _, bindaddr := range ptServerInfo.Bindaddrs {
name := bindaddr.MethodName
- fmt.Println("bindaddr", bindaddr)
var transport base.Transport
- args, argsErr := pt.ParsePT2ClientParameters(options)
+ args, argsErr := pt.ParsePT2ServerParameters(options)
if argsErr != nil {
log.Errorf("Error parsing transport options: %s", options)
return
}
- fmt.Println("Initializing transport", name, args)
-
// Deal with arguments.
switch name {
case "obfs2":
@@ -221,9 +210,26 @@ func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, ptServerIn
return
case "obfs4":
transport = obfs4.NewObfs4Server(statedir, options)
+ case "shadow":
+ shargs, aok := args["shadow"]
+ if !aok {
+ return false, nil
+ }
+
+ password, ok := shargs.Get("password")
+ if !ok {
+ return false, nil
+ }
+
+ cipherName, ok2 := shargs.Get("cipherName")
+ if !ok2 {
+ return false, nil
+ }
+
+ transport = shadow.NewShadowServer(password, cipherName)
default:
log.Errorf("Unknown transport: %s", name)
- return
+ return false, nil
}
f := transport.Listen
@@ -270,7 +276,6 @@ func serverAcceptLoop(termMon *termmon.TermMonitor, name string, ln base.Transpo
defer ln.Close()
for {
conn, err := ln.TransportAccept()
- fmt.Println("accepted")
if err != nil {
if e, ok := err.(net.Error); ok && !e.Temporary() {
return err
@@ -287,13 +292,12 @@ func serverHandler(termMon *termmon.TermMonitor, name string, remote base.Transp
defer termMon.OnHandlerFinish()
addrStr := log.ElideAddr(remote.NetworkConn().RemoteAddr().String())
- fmt.Println("handling", name)
log.Infof("%s(%s) - new connection", name, addrStr)
// Connect to the orport.
orConn, err := pt.DialOr(info, remote.NetworkConn().RemoteAddr().String(), name)
if err != nil {
- fmt.Println("OR conn failed", info, remote.NetworkConn().RemoteAddr(), name)
+ fmt.Println("OR conn failed", info, remote.NetworkConn().RemoteAddr(), name, err)
log.Errorf("%s(%s) - failed to connect to ORPort: %s", name, addrStr, log.ElideError(err))
return
}
diff --git a/shapeshifter-dispatcher/shapeshifter-dispatcher.go b/shapeshifter-dispatcher/shapeshifter-dispatcher.go
index 7fbdcdb..6821f32 100644
--- a/shapeshifter-dispatcher/shapeshifter-dispatcher.go
+++ b/shapeshifter-dispatcher/shapeshifter-dispatcher.go
@@ -145,7 +145,6 @@ func main() {
}
log.Noticef("%s - launched", getVersion())
- fmt.Println("launching")
if *transparent {
// Do the transparent proxy configuration.
@@ -157,7 +156,6 @@ func main() {
if *target == "" {
log.Errorf("%s - transparent mode requires a target", execName)
} else {
- fmt.Println("transparent udp client")
ptClientProxy, names := getClientNames(ptversion, transportsList, proxy)
launched = transparent_udp.ClientSetup(termMon, *target, ptClientProxy, names, *options)
@@ -167,13 +165,10 @@ func main() {
if *bindAddr == "" {
fmt.Println("%s - transparent mode requires a bindaddr", execName)
} else {
- fmt.Println("transparent udp server")
// launched = transparent_udp.ServerSetup(termMon, *bindAddr, *target)
- // fmt.Println("launched", launched, ptListeners)
ptServerInfo := getServerInfo(ptversion, bindAddr, options, transportsList, orport, extorport, authcookie)
launched, serverListeners = transparent_udp.ServerSetup(termMon, *bindAddr, ptServerInfo, *options)
- fmt.Println("launched", launched, serverListeners)
}
}
} else {
@@ -194,7 +189,6 @@ func main() {
} else {
ptServerInfo := getServerInfo(ptversion, bindAddr, options, transportsList, orport, extorport, authcookie)
launched, serverListeners = transparent_tcp.ServerSetup(termMon, *bindAddr, ptServerInfo, *statePath, *options)
- fmt.Println("launched", launched, serverListeners)
}
}
}
@@ -245,8 +239,6 @@ func main() {
os.Exit(-1)
}
- fmt.Println("launched")
-
log.Infof("%s - accepting connections", execName)
defer func() {
log.Noticef("%s - terminated", execName)
@@ -273,7 +265,6 @@ func main() {
termMon.Wait(true)
- fmt.Println("waiting")
for {
// FIXME - block because termMon.Wait is not blocking
}
@@ -319,7 +310,6 @@ func getClientNames(ptversion *string, transportsList *string, proxy *string) (c
}
ptClientProxy, err := pt_extras.PtGetProxy(proxy)
- fmt.Println("ptclientproxy", ptClientProxy)
if err != nil {
golog.Fatal(err)
} else if ptClientProxy != nil {
@@ -336,7 +326,7 @@ func getServerInfo(ptversion *string, bindaddrList *string, options *string, tra
bindaddrs, err = getServerBindaddrs(bindaddrList, options, transportList)
if err != nil {
- fmt.Println("Error parsing bindaddrs")
+ fmt.Println("Error parsing bindaddrs", *bindaddrList, *options, *transportList)
return ptServerInfo
}
@@ -384,16 +374,21 @@ func getServerBindaddrs(bindaddrList *string, options *string, transports *strin
// Parse the list of server transport options.
if options == nil {
serverTransportOptions = pt.Getenv("TOR_PT_SERVER_TRANSPORT_OPTIONS")
+ if serverTransportOptions != "" {
+ optionsMap, err = pt.ParseServerTransportOptions(serverTransportOptions)
+ if err != nil {
+ fmt.Println("Error parsing options map", serverTransportOptions, err)
+ return nil, errors.New(fmt.Sprintf("TOR_PT_SERVER_TRANSPORT_OPTIONS: %q: %s", serverTransportOptions, err.Error()))
+ }
+ }
} else {
serverTransportOptions = *options
- }
-
- if serverTransportOptions != "" {
- fmt.Println(serverTransportOptions)
- optionsMap, err = pt.ParseServerTransportOptions(serverTransportOptions)
- if err != nil {
- fmt.Println("Error parsing options map")
- return nil, errors.New(fmt.Sprintf("TOR_PT_SERVER_TRANSPORT_OPTIONS: %q: %s", serverTransportOptions, err.Error()))
+ if serverTransportOptions != "" {
+ optionsMap, err = pt.ParsePT2ServerParameters(serverTransportOptions)
+ if err != nil {
+ fmt.Println("Error parsing options map", serverTransportOptions, err)
+ return nil, errors.New(fmt.Sprintf("TOR_PT_SERVER_TRANSPORT_OPTIONS: %q: %s", serverTransportOptions, err.Error()))
+ }
}
}
@@ -407,7 +402,6 @@ func getServerBindaddrs(bindaddrList *string, options *string, transports *strin
serverBindaddr = *bindaddrList
}
for _, spec := range strings.Split(serverBindaddr, ",") {
- fmt.Println(spec)
var bindaddr pt.Bindaddr
parts := strings.SplitN(spec, "-", 2)