initial commit

This commit is contained in:
idk 2018-12-25 00:57:30 -05:00
parent 79335a30fa
commit 6260b4fe2b
No known key found for this signature in database
GPG key ID: D75C03B39B5E14E1
9 changed files with 302 additions and 1 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
README.md.asc
eeProxy

0
Dockerfile Normal file
View file

9
Makefile Normal file
View file

@ -0,0 +1,9 @@
build:
go build
fmt:
find . -name '*.go' -exec gofmt -w {} \;
clean:
go clean

View file

@ -1,2 +1,3 @@
# eeProxy
Yet another standalone, contextual-identity aware proxy for i2p. This time better organized and smaller.
Yet another standalone, contextual-identity aware proxy for i2p. This time
better organized and smaller.

159
main.go Normal file
View file

@ -0,0 +1,159 @@
package main
import (
"flag"
//"log"
"github.com/eyedeekay/eeproxy/socks"
"os"
"os/signal"
"strings"
)
import (
"github.com/eyedeekay/sam-forwarder/config"
"github.com/eyedeekay/samcatd-web"
)
type flagOpts []string
func (f *flagOpts) String() string {
r := ""
for _, s := range *f {
r += s + ","
}
return strings.TrimSuffix(r, ",")
}
func (f *flagOpts) Set(s string) error {
*f = append(*f, s)
return nil
}
func (f *flagOpts) StringSlice() []string {
var r []string
for _, s := range *f {
r = append(r, s)
}
return r
}
var (
startUp = flag.Bool("s", false,
"Start a tunnel with the passed parameters(Otherwise, they will be treated as default values.)")
encryptKeyFiles = flag.String("cr", "",
"Encrypt/decrypt the key files with a passfile")
inAllowZeroHop = flag.Bool("zi", false,
"Allow zero-hop, non-anonymous tunnels in(true or false)")
outAllowZeroHop = flag.Bool("zo", false,
"Allow zero-hop, non-anonymous tunnels out(true o false)")
useCompression = flag.Bool("z", false,
"Uze gzip(true or false)")
targetHost = flag.String("h", "127.0.0.1",
"Target host(Host of service to forward to i2p)")
targetPort = flag.String("p", "8081",
"Target port(Port of service to forward to i2p)")
reduceIdle = flag.Bool("r", false,
"Reduce tunnel quantity when idle(true or false)")
closeIdle = flag.Bool("x", false,
"Close tunnel idle(true or false)")
targetDir = flag.String("d", "./tunnels/",
"Directory to save tunnel configuration file in.")
targetDest = flag.String("de", "",
"Destination to connect client's to by default.")
iniFile = flag.String("f", "none",
"Use an ini file for configuration(config file options override passed arguments for now.)")
samHost = flag.String("sh", "127.0.0.1",
"SAM host")
samPort = flag.String("sp", "7656",
"SAM port")
tunName = flag.String("n", "socks",
"Tunnel name, this must be unique but can be anything.")
inLength = flag.Int("il", 3,
"Set inbound tunnel length(0 to 7)")
outLength = flag.Int("ol", 3,
"Set outbound tunnel length(0 to 7)")
inQuantity = flag.Int("iq", 2,
"Set inbound tunnel quantity(0 to 15)")
outQuantity = flag.Int("oq", 2,
"Set outbound tunnel quantity(0 to 15)")
inVariance = flag.Int("iv", 0,
"Set inbound tunnel length variance(-7 to 7)")
outVariance = flag.Int("ov", 0,
"Set outbound tunnel length variance(-7 to 7)")
inBackupQuantity = flag.Int("ib", 1,
"Set inbound tunnel backup quantity(0 to 5)")
outBackupQuantity = flag.Int("ob", 1,
"Set outbound tunnel backup quantity(0 to 5)")
reduceIdleTime = flag.Int("rt", 600000,
"Reduce tunnel quantity after X (milliseconds)")
closeIdleTime = flag.Int("ct", 600000,
"Reduce tunnel quantity after X (milliseconds)")
reduceIdleQuantity = flag.Int("rq", 1,
"Reduce idle tunnel quantity to X (0 to 5)")
readKeys = flag.String("conv", "", "Display the base32 and base64 values of a specified .i2pkeys file")
)
var (
webinterface *samcatweb.SAMWebConfig
webinterfaceerr error
err error
accessList flagOpts
config *i2ptunconf.Conf
)
func main() {
flag.Var(&accessList, "accesslist", "Specify an access list member(can be used multiple times)")
flag.Parse()
if *readKeys != "" {
}
config = i2ptunconf.NewI2PBlankTunConf()
if *iniFile != "none" && *iniFile != "" {
config, err = i2ptunconf.NewI2PTunConf(*iniFile)
} else {
*startUp = true
}
config.TargetHost = config.GetHost(*targetHost, "127.0.0.1")
config.TargetPort = config.GetPort(*targetPort, "8081")
config.SaveFile = config.GetSaveFile(true, true)
config.SaveDirectory = config.GetDir(*targetDir, "./tunnels/")
config.SamHost = config.GetSAMHost(*samHost, "127.0.0.1")
config.SamPort = config.GetSAMPort(*samPort, "7656")
config.TunName = config.GetKeys(*tunName, "socks")
config.InLength = config.GetInLength(*inLength, 3)
config.OutLength = config.GetOutLength(*outLength, 3)
config.InVariance = config.GetInVariance(*inVariance, 0)
config.OutVariance = config.GetOutVariance(*outVariance, 0)
config.InQuantity = config.GetInQuantity(*inQuantity, 2)
config.OutQuantity = config.GetOutQuantity(*outQuantity, 2)
config.InBackupQuantity = config.GetInBackups(*inBackupQuantity, 1)
config.OutBackupQuantity = config.GetOutBackups(*outBackupQuantity, 1)
config.InAllowZeroHop = config.GetInAllowZeroHop(*inAllowZeroHop, false)
config.OutAllowZeroHop = config.GetOutAllowZeroHop(*outAllowZeroHop, false)
config.UseCompression = config.GetUseCompression(*useCompression, true)
config.ReduceIdle = config.GetReduceOnIdle(*reduceIdle, true)
config.ReduceIdleTime = config.GetReduceIdleTime(*reduceIdleTime, 600000)
config.ReduceIdleQuantity = config.GetReduceIdleQuantity(*reduceIdleQuantity, 2)
config.CloseIdle = config.GetCloseOnIdle(*closeIdle, false)
config.CloseIdleTime = config.GetCloseIdleTime(*closeIdleTime, 600000)
config.KeyFilePath = config.GetKeyFile(*encryptKeyFiles, "")
config.ClientDest = config.GetClientDest(*targetDest, "", "")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
if tunsocks, tunerr := tunmanager.NewManager(); tunerr == nil {
go func() {
for sig := range c {
if sig == os.Interrupt {
//tunsocks.Cleanup()
}
}
}()
tunsocks.Serve()
} else {
panic(tunerr)
}
}

63
resolve/eepresolver.go Normal file
View file

@ -0,0 +1,63 @@
package resolver
import (
"context"
"fmt"
"net"
"strings"
)
import (
"github.com/eyedeekay/sam3"
)
type Resolver struct {
*sam3.SAMResolver
allowedSuffixes []string
}
func (r Resolver) Resolve(ctx context.Context, name string) (context.Context, net.Addr, error) {
return r.ResolveI2P(ctx, name)
}
func (r Resolver) ResolveI2P(ctx context.Context, name string) (context.Context, *sam3.I2PAddr, error) {
if r.ValidateI2PAddr(name) {
return ctx, nil, fmt.Errorf("Error, not an allowed suffix")
}
raddr, err := r.SAMResolver.Resolve(name)
if err != nil {
return ctx, nil, err
}
return ctx, &raddr, nil
}
func (r Resolver) ValidateI2PAddr(name string) bool {
noi2p := true
for _, suffix := range r.allowedSuffixes {
if strings.HasSuffix(name, suffix) {
if suffix == ".b32.i2p" {
if len(name) != 52 {
noi2p = true
break
}
}
noi2p = false
}
}
return noi2p
}
func NewResolver() (*Resolver, error) {
return NewResolverFromOptions()
}
func NewResolverFromOptions() (*Resolver, error) {
var r Resolver
r.allowedSuffixes = []string{".i2p", ".b32.i2p"}
var err error
r.SAMResolver, err = sam3.NewFullSAMResolver("127.0.0.1:7656")
if err != nil {
return nil, err
}
return &r, nil
}

65
socks/manager.go Normal file
View file

@ -0,0 +1,65 @@
package tunmanager
import (
"context"
"fmt"
"log"
"net"
)
import (
"github.com/eyedeekay/eeproxy/resolve"
"github.com/eyedeekay/go-socks5"
"github.com/eyedeekay/sam3"
)
type Manager struct {
resolver.Resolver
socks5.Config
sam3.StreamSession
conns []*sam3.SAMConn
}
func (m Manager) Serve() error {
return nil
}
func (m Manager) DialI2P(ctx context.Context, addr string) (*sam3.SAMConn, error) {
i2paddr, err := sam3.NewI2PAddrFromString(addr)
if err != nil {
return nil, err
}
for i, c := range m.conns {
if i2paddr.Base32() == c.RemoteAddr().(*sam3.I2PAddr).Base32() {
log.Println("Found destination for address:", i2paddr.Base32(), "at position", i)
return c, nil
}
}
newconn, err := m.StreamSession.DialI2P(i2paddr)
if err != nil {
return nil, err
}
m.conns = append(m.conns, newconn)
log.Println("Generated destination for address:", i2paddr.Base32(), "at position", len(m.conns)-1)
return m.conns[len(m.conns)-1], nil
}
func (m Manager) Dial(ctx context.Context, network, addr string) (net.Conn, error) {
return m.DialI2P(ctx, addr)
}
func NewManager() (*Manager, error) {
return NewManagerFromOptions()
}
func NewManagerFromOptions() (*Manager, error) {
var m Manager
if r, err := resolver.NewResolver(); err == nil {
m.Config = socks5.Config{
Resolver: r,
Dial: m.Dial,
}
return &m, nil
}
return nil, fmt.Errorf("Resolver creation error.")
}

1
socks/manager_options.go Normal file
View file

@ -0,0 +1 @@
package tunmanager

1
socks/manager_test.go Normal file
View file

@ -0,0 +1 @@
package tunmanager