Skip to content
Draft
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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

13 changes: 8 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (

"github.com/keyvchan/NetAssist/pkg/flags"
"github.com/keyvchan/NetAssist/pkg/utils"
"github.com/keyvchan/NetAssist/protocol"
"github.com/keyvchan/NetAssist/protocol/tcp"
"github.com/keyvchan/NetAssist/protocol/udp"
"github.com/keyvchan/NetAssist/protocol/unixgram"
"github.com/keyvchan/NetAssist/protocol/unixsocket"
)

// Req is the entry point for the client
Expand All @@ -14,13 +17,13 @@ func Req() {
log.Println("Req:", types)
switch types {
case "tcp":
protocol.TCPClient()
tcp.Client()
case "udp":
protocol.UDPClient()
udp.Client()
case "unix":
protocol.UnixClient()
unixsocket.Client()
case "unixgram":
protocol.UnixgramClient()
unixgram.Client()
case "unixpacket":
utils.Unimplemented("unixpacket")
case "ip":
Expand Down
20 changes: 20 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
module github.com/keyvchan/NetAssist

go 1.18

require github.com/lucas-clemente/quic-go v0.27.1

require (
github.com/cheekybits/genny v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.1 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.1 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/tools v0.1.1 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)
281 changes: 281 additions & 0 deletions go.sum

Large diffs are not rendered by default.

Empty file added protocol/quic/client.go
Empty file.
9 changes: 9 additions & 0 deletions protocol/quic/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package quic

import (
"github.com/lucas-clemente/quic-go"
)

func Server() {
quic.ListenAddr()
}
34 changes: 34 additions & 0 deletions protocol/quic/tls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package quic

import (
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"encoding/pem"
"math/big"
)

// Setup a bare-bones TLS config for the server
func generateTLSConfig() *tls.Config {
key, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
panic(err)
}
template := x509.Certificate{SerialNumber: big.NewInt(1)}
certDER, err := x509.CreateCertificate(rand.Reader, &template, &template, &key.PublicKey, key)
if err != nil {
panic(err)
}
keyPEM := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)})
certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certDER})

tlsCert, err := tls.X509KeyPair(certPEM, keyPEM)
if err != nil {
panic(err)
}
return &tls.Config{
Certificates: []tls.Certificate{tlsCert},
NextProtos: []string{"quic-echo-example"},
}
}
44 changes: 44 additions & 0 deletions protocol/tcp/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package tcp

import (
"log"
"net"

"github.com/keyvchan/NetAssist/pkg/connection"
"github.com/keyvchan/NetAssist/pkg/flags"
"github.com/keyvchan/NetAssist/pkg/message"
)

// TCPClient is a TCP client, read from stdin and write to the server and read from the server when it to stdout
func Client() {
address := flags.GetArg(3)
conn, err := net.Dial("tcp", address)
if err != nil {
log.Fatal(err)
}
defer conn.Close()

tcp_client := connection.Stream{
Type: "tcp",
Conn: conn,
}

// create a chennel to communicate between the read and write goroutines
stdin_read := make(chan message.Message)
go message.Read(stdin_read, connection.Stdin)
go message.Write(stdin_read, tcp_client)

quit := make(chan bool)
conn_read := make(chan message.Message)

go message.Read(conn_read, tcp_client)
go message.Write(conn_read, connection.Stdout)
go func() {
conn := <-*connection.ClosedConn
conn.Close()
quit <- true
}()

// quit on signal
<-quit
}
38 changes: 2 additions & 36 deletions protocol/tcp.go → protocol/tcp/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package protocol
package tcp

import (
"log"
Expand All @@ -11,7 +11,7 @@ import (
)

// TCPServer is a TCP server, read from stdin and write to the client and read from the client write it to stdout
func TCPServer() {
func Server() {
address := flags.GetArg(3)
listener, err := net.Listen("tcp", address)
if err != nil {
Expand Down Expand Up @@ -61,40 +61,6 @@ func accept_conn(read_chan chan message.Message, listener net.Listener, connecti

}

// TCPClient is a TCP client, read from stdin and write to the server and read from the server when it to stdout
func TCPClient() {
address := flags.GetArg(3)
conn, err := net.Dial("tcp", address)
if err != nil {
log.Fatal(err)
}
defer conn.Close()

tcp_client := connection.Stream{
Type: "tcp",
Conn: conn,
}

// create a chennel to communicate between the read and write goroutines
stdin_read := make(chan message.Message)
go message.Read(stdin_read, connection.Stdin)
go message.Write(stdin_read, tcp_client)

quit := make(chan bool)
conn_read := make(chan message.Message)

go message.Read(conn_read, tcp_client)
go message.Write(conn_read, connection.Stdout)
go func() {
conn := <-*connection.ClosedConn
conn.Close()
quit <- true
}()

// quit on signal
<-quit
}

// conn_cleanup removes closed connections from the connections map
func conn_cleanup(closed_conn chan net.Conn, conns map[net.Conn]bool) {
for {
Expand Down
26 changes: 2 additions & 24 deletions protocol/udp.go → protocol/udp/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package protocol
package udp

import (
"log"
Expand All @@ -9,30 +9,8 @@ import (
"github.com/keyvchan/NetAssist/pkg/message"
)

// UDPServer is a UDP server, it reads from stdin and writes to stdout and read from the client and write to the stdout
func UDPServer() {
address := flags.GetArg(3)
conn, err := net.ListenPacket("udp", address)
if err != nil {
log.Fatal(err)
}
stdin_read_chan := make(chan message.Message)
conn_read_chan := make(chan message.Message)

udp_server_conn := connection.Packet{
Type: "udp",
PacketConn: conn,
}

go message.Read(stdin_read_chan, connection.Stdin)
go message.Read(conn_read_chan, udp_server_conn)
go message.Write(conn_read_chan, connection.Stdout)
go message.Write(stdin_read_chan, udp_server_conn)
select {}
}

// UDPClient is a UDP client, it reads from stdin and writes to stdout and read from the server and write to the stdout
func UDPClient() {
func Client() {
address := flags.GetArg(3)
conn, err := net.Dial("udp", address)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions protocol/udp/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package udp

import (
"log"
"net"

"github.com/keyvchan/NetAssist/pkg/connection"
"github.com/keyvchan/NetAssist/pkg/flags"
"github.com/keyvchan/NetAssist/pkg/message"
)

// UDPServer is a UDP server, it reads from stdin and writes to stdout and read from the client and write to the stdout
func Server() {
address := flags.GetArg(3)
conn, err := net.ListenPacket("udp", address)
if err != nil {
log.Fatal(err)
}
stdin_read_chan := make(chan message.Message)
conn_read_chan := make(chan message.Message)

udp_server_conn := connection.Packet{
Type: "udp",
PacketConn: conn,
}

go message.Read(stdin_read_chan, connection.Stdin)
go message.Read(conn_read_chan, udp_server_conn)
go message.Write(conn_read_chan, connection.Stdout)
go message.Write(stdin_read_chan, udp_server_conn)
select {}
}
47 changes: 0 additions & 47 deletions protocol/unixgram.go

This file was deleted.

32 changes: 32 additions & 0 deletions protocol/unixgram/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package unixgram

import (
"bufio"
"errors"
"log"
"net"
"os"

"github.com/keyvchan/NetAssist/pkg/flags"
)

// Client is a client for the unixgram protocol, its create a bridge between server and client
func Client() {
address := flags.GetArg(3)
conn, err := net.Dial("unixgram", address)
if err != nil {
log.Fatal(err)
}
defer conn.Close()

for {
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
conn.Write([]byte(scanner.Text()))
} else {
log.Fatal(errors.New("failed to read from stdin"))
}

}

}
23 changes: 23 additions & 0 deletions protocol/unixgram/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package unixgram

import (
"fmt"
"log"
"net"

"github.com/keyvchan/NetAssist/pkg/flags"
)

// Server is a server for the unixgram protocol, its create a bridge between server and client
func Server() {
address := flags.GetArg(3)
conn, err := net.ListenPacket("unixgram", address)
if err != nil {
log.Fatal(err)
}
for {
buf := make([]byte, 1024)
conn.ReadFrom(buf)
fmt.Println(string(buf))
}
}
Loading