mostly UDP fixes, move all the code from kpetku/sam3 to eyedeekay/sam3, move key saving to common
This commit is contained in:
17
LICENSE.md
17
LICENSE.md
@ -1,7 +1,18 @@
|
||||
Copyright 2018 eyedeekay <eyedeekay@safe-mail.net>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
@ -83,12 +83,12 @@ I'm eventually going to make the manager implement net.Conn. This won't be
|
||||
exposed in the default application probably though, but rather as a library.
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAlwDM+QACgkQ11wDs5te
|
||||
FOF9ygf9EfvsVR3DhkxnYnDIpfYFJkmTl5L7htxOaRF+uaXvmmod7/l95o/qhQ8S
|
||||
6djlq6j7IV5qOwxCrCsXBxNUG42ywiCl694cTY6kZoNStxWJrnguXlmrmVJHcK1C
|
||||
DwcGdHyGItKgAoAeVHdzP+/Ipq0CUn7YeOLVP4W3S9EjiVtySJfecqjEDLZwd1m7
|
||||
9Jn08qrTpvrgPTTWWjQQIESwl4WRdSa/DDmjAMd1+rgefpIIDWKgtZajItHPFH7I
|
||||
7FhZAl190RVpqwhrf33aQu18j5Ls+M3rFUugUR5TY3QDdEZvIRKxyUoujbb84jDY
|
||||
Jylz2WbrhtCNfychz+DM8ZY4D730Mg==
|
||||
=5e8t
|
||||
iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAlwD/mcACgkQ11wDs5te
|
||||
FOEadggAnkDsnQ6LVRNV0ZYPHS64/tjtggYD+Db0SBroJNDNk4VpMfJRN1jto7Aq
|
||||
0tpY6IjtUD1UYhUDrQuFyNaCPUlGcR5ie8ENgJgHyeggaDy06IYYsKmv5l7+lv7K
|
||||
+2VYM2FnTsGqUrAjcN6QIhELI25mpj5o7VCJoZLIDfBE146b26sdTn5w0ay7KAbQ
|
||||
TGFVPvLIrSfZrn/+7a/5lYHkanW0degh/yJQ7R3fJp8En3PganQuwhYQCXLDe8Tk
|
||||
BeQvviPSEJZaMi6/MSknb8L8XFRt3jXgnEvFYoqm2qWxCvIKL22NGzS/UCqTxYxx
|
||||
UMUAIlxOp69MzSO2Jhsqf6RwBXxzIQ==
|
||||
=RtpV
|
||||
-----END PGP SIGNATURE-----
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
//"os"
|
||||
//"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -68,7 +68,7 @@ type SAMClientForwarder struct {
|
||||
accessList []string
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) print() []string {
|
||||
func (f SAMClientForwarder) print() []string {
|
||||
lsk, lspk, lspsk := f.leasesetsettings()
|
||||
return []string{
|
||||
//f.targetForPort443(),
|
||||
@ -97,13 +97,13 @@ func (f *SAMClientForwarder) print() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) Cleanup() {
|
||||
func (f SAMClientForwarder) Cleanup() {
|
||||
f.connectStream.Close()
|
||||
f.publishConnection.Close()
|
||||
f.samConn.Close()
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) Print() string {
|
||||
func (f SAMClientForwarder) Print() string {
|
||||
var r string
|
||||
r += "name=" + f.TunName + "\n"
|
||||
r += "type=" + f.Type + "\n"
|
||||
@ -118,7 +118,7 @@ func (f *SAMClientForwarder) Print() string {
|
||||
return r
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) Search(search string) string {
|
||||
func (f SAMClientForwarder) Search(search string) string {
|
||||
terms := strings.Split(search, ",")
|
||||
if search == "" {
|
||||
return f.Print()
|
||||
@ -131,7 +131,7 @@ func (f *SAMClientForwarder) Search(search string) string {
|
||||
return f.Print()
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) accesslisttype() string {
|
||||
func (f SAMClientForwarder) accesslisttype() string {
|
||||
if f.accessListType == "whitelist" {
|
||||
return "i2cp.enableAccessList=true"
|
||||
} else if f.accessListType == "blacklist" {
|
||||
@ -142,7 +142,7 @@ func (f *SAMClientForwarder) accesslisttype() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) accesslist() string {
|
||||
func (f SAMClientForwarder) accesslist() string {
|
||||
if f.accessListType != "" && len(f.accessList) > 0 {
|
||||
r := ""
|
||||
for _, s := range f.accessList {
|
||||
@ -153,7 +153,7 @@ func (f *SAMClientForwarder) accesslist() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) leasesetsettings() (string, string, string) {
|
||||
func (f SAMClientForwarder) leasesetsettings() (string, string, string) {
|
||||
var r, s, t string
|
||||
if f.leaseSetKey != "" {
|
||||
r = "i2cp.leaseSetKey=" + f.leaseSetKey
|
||||
@ -168,30 +168,30 @@ func (f *SAMClientForwarder) leasesetsettings() (string, string, string) {
|
||||
}
|
||||
|
||||
// Target returns the host:port of the local service you want to forward to i2p
|
||||
func (f *SAMClientForwarder) Target() string {
|
||||
func (f SAMClientForwarder) Target() string {
|
||||
return f.TargetHost + ":" + f.TargetPort
|
||||
}
|
||||
|
||||
// Destination returns the destination of the i2p service you want to forward locally
|
||||
func (f *SAMClientForwarder) Destination() string {
|
||||
func (f SAMClientForwarder) Destination() string {
|
||||
return f.addr.Base32()
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) sam() string {
|
||||
func (f SAMClientForwarder) sam() string {
|
||||
return f.SamHost + ":" + f.SamPort
|
||||
}
|
||||
|
||||
//Base32 returns the base32 address of the local destination
|
||||
func (f *SAMClientForwarder) Base32() string {
|
||||
func (f SAMClientForwarder) Base32() string {
|
||||
return f.SamKeys.Addr().Base32()
|
||||
}
|
||||
|
||||
//Base64 returns the base64 address of the local destiantion
|
||||
func (f *SAMClientForwarder) Base64() string {
|
||||
func (f SAMClientForwarder) Base64() string {
|
||||
return f.SamKeys.Addr().Base64()
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) forward(conn net.Conn) {
|
||||
func (f SAMClientForwarder) forward(conn net.Conn) {
|
||||
client, err := f.connectStream.DialI2P(f.addr)
|
||||
if err != nil {
|
||||
log.Fatalf("Dial failed: %v", err)
|
||||
@ -210,7 +210,7 @@ func (f *SAMClientForwarder) forward(conn net.Conn) {
|
||||
}
|
||||
|
||||
//Serve starts the SAM connection and and forwards the local host:port to i2p
|
||||
func (f *SAMClientForwarder) Serve() error {
|
||||
func (f SAMClientForwarder) Serve() error {
|
||||
if f.addr, err = f.samConn.Lookup(f.dest); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -231,7 +231,7 @@ func (f *SAMClientForwarder) Serve() error {
|
||||
}
|
||||
|
||||
//Close shuts the whole thing down.
|
||||
func (f *SAMClientForwarder) Close() error {
|
||||
func (f SAMClientForwarder) Close() error {
|
||||
var err error
|
||||
err = f.samConn.Close()
|
||||
err = f.connectStream.Close()
|
||||
@ -297,34 +297,7 @@ func NewSAMClientForwarderFromOptions(opts ...func(*SAMClientForwarder) error) (
|
||||
}
|
||||
log.Println("Destination keys generated, tunnel name:", s.TunName)
|
||||
if s.save {
|
||||
if _, err := os.Stat(filepath.Join(s.FilePath, s.TunName+".i2pkeys")); os.IsNotExist(err) {
|
||||
s.file, err = os.Create(filepath.Join(s.FilePath, s.TunName+".i2pkeys"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = sam3.StoreKeysIncompat(s.SamKeys, s.file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Encrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
s.file, err = os.Open(filepath.Join(s.FilePath, s.TunName+".i2pkeys"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Decrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.SamKeys, err = sam3.LoadKeysIncompat(s.file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Encrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
if err := i2pkeys.Save(s.FilePath, s.TunName, s.passfile, &s.SamKeys); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
71
forwarder.go
71
forwarder.go
@ -7,8 +7,8 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
//"os"
|
||||
//"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -79,21 +79,21 @@ type SAMForwarder struct {
|
||||
|
||||
var err error
|
||||
|
||||
func (f *SAMForwarder) Cleanup() {
|
||||
func (f SAMForwarder) Cleanup() {
|
||||
f.publishStream.Close()
|
||||
f.publishListen.Close()
|
||||
f.publishConnection.Close()
|
||||
f.samConn.Close()
|
||||
}
|
||||
|
||||
/*func (f *SAMForwarder) targetForPort443() string {
|
||||
/*func (f SAMForwarder) targetForPort443() string {
|
||||
if f.TargetForPort443 != "" {
|
||||
return "targetForPort.4443=" + f.TargetHost + ":" + f.TargetForPort443
|
||||
}
|
||||
return ""
|
||||
}*/
|
||||
|
||||
func (f *SAMForwarder) print() []string {
|
||||
func (f SAMForwarder) print() []string {
|
||||
lsk, lspk, lspsk := f.leasesetsettings()
|
||||
return []string{
|
||||
//f.targetForPort443(),
|
||||
@ -122,7 +122,7 @@ func (f *SAMForwarder) print() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) Print() string {
|
||||
func (f SAMForwarder) Print() string {
|
||||
var r string
|
||||
r += "name=" + f.TunName + "\n"
|
||||
r += "type=" + f.Type + "\n"
|
||||
@ -139,7 +139,7 @@ func (f *SAMForwarder) Print() string {
|
||||
return strings.Replace(r, "\n\n", "\n", -1)
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) Search(search string) string {
|
||||
func (f SAMForwarder) Search(search string) string {
|
||||
terms := strings.Split(search, ",")
|
||||
if search == "" {
|
||||
return f.Print()
|
||||
@ -152,7 +152,7 @@ func (f *SAMForwarder) Search(search string) string {
|
||||
return f.Print()
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) accesslisttype() string {
|
||||
func (f SAMForwarder) accesslisttype() string {
|
||||
if f.accessListType == "whitelist" {
|
||||
return "i2cp.enableAccessList=true"
|
||||
} else if f.accessListType == "blacklist" {
|
||||
@ -163,7 +163,7 @@ func (f *SAMForwarder) accesslisttype() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) accesslist() string {
|
||||
func (f SAMForwarder) accesslist() string {
|
||||
if f.accessListType != "" && len(f.accessList) > 0 {
|
||||
r := ""
|
||||
for _, s := range f.accessList {
|
||||
@ -174,7 +174,7 @@ func (f *SAMForwarder) accesslist() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) leasesetsettings() (string, string, string) {
|
||||
func (f SAMForwarder) leasesetsettings() (string, string, string) {
|
||||
var r, s, t string
|
||||
if f.leaseSetKey != "" {
|
||||
r = "i2cp.leaseSetKey=" + f.leaseSetKey
|
||||
@ -189,15 +189,15 @@ func (f *SAMForwarder) leasesetsettings() (string, string, string) {
|
||||
}
|
||||
|
||||
// Target returns the host:port of the local service you want to forward to i2p
|
||||
func (f *SAMForwarder) Target() string {
|
||||
func (f SAMForwarder) Target() string {
|
||||
return f.TargetHost + ":" + f.TargetPort
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) sam() string {
|
||||
func (f SAMForwarder) sam() string {
|
||||
return f.SamHost + ":" + f.SamPort
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) HTTPRequestBytes(conn *sam3.SAMConn) ([]byte, *http.Request, error) {
|
||||
func (f SAMForwarder) HTTPRequestBytes(conn *sam3.SAMConn) ([]byte, *http.Request, error) {
|
||||
var request *http.Request
|
||||
var retrequest []byte
|
||||
var err error
|
||||
@ -215,7 +215,7 @@ func (f *SAMForwarder) HTTPRequestBytes(conn *sam3.SAMConn) ([]byte, *http.Reque
|
||||
return retrequest, request, nil
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) HTTPResponseBytes(conn net.Conn, req *http.Request) ([]byte, error) {
|
||||
func (f SAMForwarder) HTTPResponseBytes(conn net.Conn, req *http.Request) ([]byte, error) {
|
||||
var response *http.Response
|
||||
var retresponse []byte
|
||||
var err error
|
||||
@ -231,7 +231,7 @@ func (f *SAMForwarder) HTTPResponseBytes(conn net.Conn, req *http.Request) ([]by
|
||||
return retresponse, nil
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) clientUnlockAndClose(cli, conn bool, client net.Conn) {
|
||||
func (f SAMForwarder) clientUnlockAndClose(cli, conn bool, client net.Conn) {
|
||||
if cli {
|
||||
f.clientLock = cli
|
||||
}
|
||||
@ -245,7 +245,7 @@ func (f *SAMForwarder) clientUnlockAndClose(cli, conn bool, client net.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) connUnlockAndClose(cli, conn bool, connection *sam3.SAMConn) {
|
||||
func (f SAMForwarder) connUnlockAndClose(cli, conn bool, connection *sam3.SAMConn) {
|
||||
if cli {
|
||||
f.connClientLock = cli
|
||||
}
|
||||
@ -259,7 +259,7 @@ func (f *SAMForwarder) connUnlockAndClose(cli, conn bool, connection *sam3.SAMCo
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) forward(conn *sam3.SAMConn) { //(conn net.Conn) {
|
||||
func (f SAMForwarder) forward(conn *sam3.SAMConn) { //(conn net.Conn) {
|
||||
var request *http.Request
|
||||
var requestbytes []byte
|
||||
var responsebytes []byte
|
||||
@ -307,17 +307,17 @@ func (f *SAMForwarder) forward(conn *sam3.SAMConn) { //(conn net.Conn) {
|
||||
}
|
||||
|
||||
//Base32 returns the base32 address where the local service is being forwarded
|
||||
func (f *SAMForwarder) Base32() string {
|
||||
func (f SAMForwarder) Base32() string {
|
||||
return f.SamKeys.Addr().Base32()
|
||||
}
|
||||
|
||||
//Base64 returns the base64 address where the local service is being forwarded
|
||||
func (f *SAMForwarder) Base64() string {
|
||||
func (f SAMForwarder) Base64() string {
|
||||
return f.SamKeys.Addr().Base64()
|
||||
}
|
||||
|
||||
//Serve starts the SAM connection and and forwards the local host:port to i2p
|
||||
func (f *SAMForwarder) Serve() error {
|
||||
func (f SAMForwarder) Serve() error {
|
||||
//lsk, lspk, lspsk := f.leasesetsettings()
|
||||
if f.publishStream, err = f.samConn.NewStreamSession(f.TunName, f.SamKeys, f.print()); err != nil {
|
||||
log.Println("Stream Creation error:", err.Error())
|
||||
@ -342,7 +342,7 @@ func (f *SAMForwarder) Serve() error {
|
||||
}
|
||||
|
||||
//Close shuts the whole thing down.
|
||||
func (f *SAMForwarder) Close() error {
|
||||
func (f SAMForwarder) Close() error {
|
||||
var err error
|
||||
err = f.samConn.Close()
|
||||
err = f.publishStream.Close()
|
||||
@ -406,34 +406,7 @@ func NewSAMForwarderFromOptions(opts ...func(*SAMForwarder) error) (*SAMForwarde
|
||||
}
|
||||
log.Println("Destination keys generated, tunnel name:", s.TunName)
|
||||
if s.save {
|
||||
if _, err := os.Stat(filepath.Join(s.FilePath, s.TunName+".i2pkeys")); os.IsNotExist(err) {
|
||||
s.file, err = os.Create(filepath.Join(s.FilePath, s.TunName+".i2pkeys"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = sam3.StoreKeysIncompat(s.SamKeys, s.file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Encrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
s.file, err = os.Open(filepath.Join(s.FilePath, s.TunName+".i2pkeys"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Decrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.SamKeys, err = sam3.LoadKeysIncompat(s.file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Encrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
if err := i2pkeys.Save(s.FilePath, s.TunName, s.passfile, &s.SamKeys); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,15 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
import "github.com/eyedeekay/sam-forwarder"
|
||||
import "github.com/eyedeekay/sam-forwarder/udp"
|
||||
import ".."
|
||||
import "../udp"
|
||||
|
||||
var (
|
||||
port = "8100"
|
||||
cport = "8101"
|
||||
uport = "8102"
|
||||
ucport = "8103"
|
||||
ssuport = "8104"
|
||||
udpserveraddr *net.UDPAddr
|
||||
udplocaladdr *net.UDPAddr
|
||||
udpserverconn *net.UDPConn
|
||||
@ -115,10 +116,7 @@ func serveudp() {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
go ssuforwarder.Serve()
|
||||
|
||||
log.Printf("Serving %s on UDP port: %s %s\n", uport, "and on",
|
||||
ssuforwarder.Base32())
|
||||
log.Fatal(http.ListenAndServe("127.0.0.1:"+uport, nil))
|
||||
log.Printf("Serving on UDP port: %s and on %s\n", uport, ssuforwarder.Base32())
|
||||
}
|
||||
|
||||
func clientudp() {
|
||||
@ -126,7 +124,7 @@ func clientudp() {
|
||||
|
||||
ssuforwarderclient, err = samforwarderudp.NewSAMSSUClientForwarderFromOptions(
|
||||
samforwarderudp.SetClientHost("127.0.0.1"),
|
||||
samforwarderudp.SetClientPort(ucport),
|
||||
samforwarderudp.SetClientPort(ssuport),
|
||||
samforwarderudp.SetClientSAMHost("127.0.0.1"),
|
||||
samforwarderudp.SetClientSAMPort("7656"),
|
||||
samforwarderudp.SetClientName("testudpclient"),
|
||||
@ -135,7 +133,6 @@ func clientudp() {
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
log.Printf("Connecting %s UDP port: %s %s\n", ucport, "to",
|
||||
forwarder.Base32())
|
||||
go ssuforwarderclient.Serve()
|
||||
go ssuforwarderclient.Serve()
|
||||
log.Printf("Connecting UDP port: %s to %s\n", ucport, ssuforwarder.Base32())
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
|
||||
func TestTCP(t *testing.T) {
|
||||
go serve()
|
||||
time.Sleep(time.Duration(60 * time.Second))
|
||||
time.Sleep(time.Duration(30 * time.Second))
|
||||
go client()
|
||||
time.Sleep(time.Duration(60 * time.Second))
|
||||
time.Sleep(time.Duration(30 * time.Second))
|
||||
resp, err := http.Get("http://127.0.0.1:" + cport + "/test.html")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -22,14 +22,15 @@ func TestTCP(t *testing.T) {
|
||||
|
||||
func TestUDP(t *testing.T) {
|
||||
go echo()
|
||||
time.Sleep(time.Duration(60 * time.Second))
|
||||
time.Sleep(time.Duration(30 * time.Second))
|
||||
defer udpserverconn.Close()
|
||||
go serveudp()
|
||||
time.Sleep(time.Duration(60 * time.Second))
|
||||
time.Sleep(time.Duration(30 * time.Second))
|
||||
go clientudp()
|
||||
time.Sleep(time.Duration(60 * time.Second))
|
||||
conn, err := net.DialUDP("udp", udpserveraddr, udplocaladdr)
|
||||
defer conn.Close()
|
||||
time.Sleep(time.Duration(30 * time.Second))
|
||||
// conn, err := net.DialUDP("udp", udpserveraddr, udplocaladdr)
|
||||
conn, err := net.DialUDP("udp", udplocaladdr, udpserveraddr)
|
||||
//defer conn.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -38,3 +39,18 @@ func TestUDP(t *testing.T) {
|
||||
t.Fatal("SSU error", err)
|
||||
}
|
||||
}
|
||||
/*
|
||||
func TestUDPeasy(t *testing.T) {
|
||||
go echo()
|
||||
time.Sleep(time.Duration(1 * time.Second))
|
||||
conn, err := net.DialUDP("udp", udplocaladdr, udpserveraddr)
|
||||
//defer conn.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = conn.Write([]byte("Hello SSU"))
|
||||
if err != nil {
|
||||
t.Fatal("SSU error", err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
//"os"
|
||||
//"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -69,13 +69,13 @@ type SAMSSUClientForwarder struct {
|
||||
accessList []string
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) Cleanup() {
|
||||
func (f SAMSSUClientForwarder) Cleanup() {
|
||||
f.publishConnection.Close()
|
||||
f.connectStream.Close()
|
||||
f.samConn.Close()
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) print() []string {
|
||||
func (f SAMSSUClientForwarder) print() []string {
|
||||
lsk, lspk, lspsk := f.leasesetsettings()
|
||||
return []string{
|
||||
//f.targetForPort443(),
|
||||
@ -104,7 +104,7 @@ func (f *SAMSSUClientForwarder) print() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) Print() string {
|
||||
func (f SAMSSUClientForwarder) Print() string {
|
||||
var r string
|
||||
r += "name=" + f.TunName + "\n"
|
||||
r += "type=" + f.Type + "\n"
|
||||
@ -118,7 +118,7 @@ func (f *SAMSSUClientForwarder) Print() string {
|
||||
return strings.Replace(r, "\n\n", "\n", -1)
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) Search(search string) string {
|
||||
func (f SAMSSUClientForwarder) Search(search string) string {
|
||||
terms := strings.Split(search, ",")
|
||||
if search == "" {
|
||||
return f.Print()
|
||||
@ -131,7 +131,7 @@ func (f *SAMSSUClientForwarder) Search(search string) string {
|
||||
return f.Print()
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) accesslisttype() string {
|
||||
func (f SAMSSUClientForwarder) accesslisttype() string {
|
||||
if f.accessListType == "whitelist" {
|
||||
return "i2cp.enableAccessList=true"
|
||||
} else if f.accessListType == "blacklist" {
|
||||
@ -142,7 +142,7 @@ func (f *SAMSSUClientForwarder) accesslisttype() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) accesslist() string {
|
||||
func (f SAMSSUClientForwarder) accesslist() string {
|
||||
if f.accessListType != "" && len(f.accessList) > 0 {
|
||||
r := ""
|
||||
for _, s := range f.accessList {
|
||||
@ -153,7 +153,7 @@ func (f *SAMSSUClientForwarder) accesslist() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) leasesetsettings() (string, string, string) {
|
||||
func (f SAMSSUClientForwarder) leasesetsettings() (string, string, string) {
|
||||
var r, s, t string
|
||||
if f.leaseSetKey != "" {
|
||||
r = "i2cp.leaseSetKey=" + f.leaseSetKey
|
||||
@ -168,30 +168,30 @@ func (f *SAMSSUClientForwarder) leasesetsettings() (string, string, string) {
|
||||
}
|
||||
|
||||
// Destination returns the destination of the i2p service you want to forward locally
|
||||
func (f *SAMSSUClientForwarder) Destination() string {
|
||||
func (f SAMSSUClientForwarder) Destination() string {
|
||||
return f.addr.Base32()
|
||||
}
|
||||
|
||||
// Target returns the host:port of the local service you want to forward to i2p
|
||||
func (f *SAMSSUClientForwarder) Target() string {
|
||||
func (f SAMSSUClientForwarder) Target() string {
|
||||
return f.TargetHost + ":" + f.TargetPort
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) sam() string {
|
||||
func (f SAMSSUClientForwarder) sam() string {
|
||||
return f.SamHost + ":" + f.SamPort
|
||||
}
|
||||
|
||||
//Base32 returns the base32 address of the local destination
|
||||
func (f *SAMSSUClientForwarder) Base32() string {
|
||||
func (f SAMSSUClientForwarder) Base32() string {
|
||||
return f.SamKeys.Addr().Base32()
|
||||
}
|
||||
|
||||
//Base64 returns the base64 address of the local destination
|
||||
func (f *SAMSSUClientForwarder) Base64() string {
|
||||
func (f SAMSSUClientForwarder) Base64() string {
|
||||
return f.SamKeys.Addr().Base64()
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) forward(conn net.PacketConn) {
|
||||
func (f SAMSSUClientForwarder) forward(conn net.PacketConn) {
|
||||
var err error
|
||||
//p, _ := strconv.Atoi(f.TargetPort)
|
||||
sp, _ := strconv.Atoi(f.SamPort)
|
||||
@ -226,7 +226,7 @@ func (f *SAMSSUClientForwarder) forward(conn net.PacketConn) {
|
||||
}
|
||||
|
||||
//Serve starts the SAM connection and and forwards the local host:port to i2p
|
||||
func (f *SAMSSUClientForwarder) Serve() error {
|
||||
func (f SAMSSUClientForwarder) Serve() error {
|
||||
if f.addr, err = f.samConn.Lookup(f.dest); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -298,34 +298,7 @@ func NewSAMSSUClientForwarderFromOptions(opts ...func(*SAMSSUClientForwarder) er
|
||||
}
|
||||
log.Println("Destination keys generated, tunnel name:", s.TunName)
|
||||
if s.save {
|
||||
if _, err := os.Stat(filepath.Join(s.FilePath, s.TunName+".i2pkeys")); os.IsNotExist(err) {
|
||||
s.file, err = os.Create(filepath.Join(s.FilePath, s.TunName+".i2pkeys"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = sam3.StoreKeysIncompat(s.SamKeys, s.file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Encrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
s.file, err = os.Open(filepath.Join(s.FilePath, s.TunName+".i2pkeys"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Decrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.SamKeys, err = sam3.LoadKeysIncompat(s.file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Encrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
if err := i2pkeys.Save(s.FilePath, s.TunName, s.passfile, &s.SamKeys); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
//"os"
|
||||
//"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -69,13 +69,13 @@ type SAMSSUForwarder struct {
|
||||
|
||||
var err error
|
||||
|
||||
func (f *SAMSSUForwarder) Cleanup() {
|
||||
func (f SAMSSUForwarder) Cleanup() {
|
||||
f.publishConnection.Close()
|
||||
f.clientConnection.Close()
|
||||
f.samConn.Close()
|
||||
}
|
||||
|
||||
func (f *SAMSSUForwarder) print() []string {
|
||||
func (f SAMSSUForwarder) print() []string {
|
||||
lsk, lspk, lspsk := f.leasesetsettings()
|
||||
return []string{
|
||||
//f.targetForPort443(),
|
||||
@ -104,7 +104,7 @@ func (f *SAMSSUForwarder) print() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SAMSSUForwarder) Print() string {
|
||||
func (f SAMSSUForwarder) Print() string {
|
||||
var r string
|
||||
r += "name=" + f.TunName + "\n"
|
||||
r += "type=" + f.Type + "\n"
|
||||
@ -117,7 +117,7 @@ func (f *SAMSSUForwarder) Print() string {
|
||||
return strings.Replace(r, "\n\n", "\n", -1)
|
||||
}
|
||||
|
||||
func (f *SAMSSUForwarder) Search(search string) string {
|
||||
func (f SAMSSUForwarder) Search(search string) string {
|
||||
terms := strings.Split(search, ",")
|
||||
if search == "" {
|
||||
return f.Print()
|
||||
@ -130,7 +130,7 @@ func (f *SAMSSUForwarder) Search(search string) string {
|
||||
return f.Print()
|
||||
}
|
||||
|
||||
func (f *SAMSSUForwarder) accesslisttype() string {
|
||||
func (f SAMSSUForwarder) accesslisttype() string {
|
||||
if f.accessListType == "whitelist" {
|
||||
return "i2cp.enableAccessList=true"
|
||||
} else if f.accessListType == "blacklist" {
|
||||
@ -141,7 +141,7 @@ func (f *SAMSSUForwarder) accesslisttype() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *SAMSSUForwarder) accesslist() string {
|
||||
func (f SAMSSUForwarder) accesslist() string {
|
||||
if f.accessListType != "" && len(f.accessList) > 0 {
|
||||
r := ""
|
||||
for _, s := range f.accessList {
|
||||
@ -152,7 +152,7 @@ func (f *SAMSSUForwarder) accesslist() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *SAMSSUForwarder) leasesetsettings() (string, string, string) {
|
||||
func (f SAMSSUForwarder) leasesetsettings() (string, string, string) {
|
||||
var r, s, t string
|
||||
if f.leaseSetKey != "" {
|
||||
r = "i2cp.leaseSetKey=" + f.leaseSetKey
|
||||
@ -167,16 +167,16 @@ func (f *SAMSSUForwarder) leasesetsettings() (string, string, string) {
|
||||
}
|
||||
|
||||
// Target returns the host:port of the local service you want to forward to i2p
|
||||
func (f *SAMSSUForwarder) Target() string {
|
||||
func (f SAMSSUForwarder) Target() string {
|
||||
return f.TargetHost + ":" + f.TargetPort
|
||||
}
|
||||
|
||||
func (f *SAMSSUForwarder) sam() string {
|
||||
func (f SAMSSUForwarder) sam() string {
|
||||
return f.SamHost + ":" + f.SamPort
|
||||
}
|
||||
|
||||
//func (f *SAMSSUForwarder) forward(conn net.Conn) {
|
||||
func (f *SAMSSUForwarder) forward() {
|
||||
//func (f SAMSSUForwarder) forward(conn net.Conn) {
|
||||
func (f SAMSSUForwarder) forward() {
|
||||
go func() {
|
||||
defer f.clientConnection.Close()
|
||||
defer f.publishConnection.Close()
|
||||
@ -202,17 +202,17 @@ func (f *SAMSSUForwarder) forward() {
|
||||
}
|
||||
|
||||
//Base32 returns the base32 address where the local service is being forwarded
|
||||
func (f *SAMSSUForwarder) Base32() string {
|
||||
func (f SAMSSUForwarder) Base32() string {
|
||||
return f.SamKeys.Addr().Base32()
|
||||
}
|
||||
|
||||
//Base64 returns the base64 address where the local service is being forwarded
|
||||
func (f *SAMSSUForwarder) Base64() string {
|
||||
func (f SAMSSUForwarder) Base64() string {
|
||||
return f.SamKeys.Addr().Base64()
|
||||
}
|
||||
|
||||
//Serve starts the SAM connection and and forwards the local host:port to i2p
|
||||
func (f *SAMSSUForwarder) Serve() error {
|
||||
func (f SAMSSUForwarder) Serve() error {
|
||||
var err error
|
||||
|
||||
sp, _ := strconv.Atoi(f.SamPort)
|
||||
@ -237,7 +237,6 @@ func (f *SAMSSUForwarder) Serve() error {
|
||||
log.Printf("Connected to localhost %v\n", f.publishConnection)
|
||||
|
||||
for {
|
||||
log.Println("Accepting connections on:", b)
|
||||
f.forward()
|
||||
}
|
||||
}
|
||||
@ -295,34 +294,7 @@ func NewSAMSSUForwarderFromOptions(opts ...func(*SAMSSUForwarder) error) (*SAMSS
|
||||
}
|
||||
log.Println("Destination keys generated, tunnel name:", s.TunName)
|
||||
if s.save {
|
||||
if _, err := os.Stat(filepath.Join(s.FilePath, s.TunName+".i2pkeys")); os.IsNotExist(err) {
|
||||
s.file, err = os.Create(filepath.Join(s.FilePath, s.TunName+".i2pkeys"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = sam3.StoreKeysIncompat(s.SamKeys, s.file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Encrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
s.file, err = os.Open(filepath.Join(s.FilePath, s.TunName+".i2pkeys"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Decrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.SamKeys, err = sam3.LoadKeysIncompat(s.file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = i2pkeys.Encrypt(filepath.Join(s.FilePath, s.TunName+".i2pkeys"), s.passfile)
|
||||
if err != nil {
|
||||
if err := i2pkeys.Save(s.FilePath, s.TunName, s.passfile, &s.SamKeys); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user