Skip to content
Open
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
Binary file added __debug_bin1705683591
Binary file not shown.
Binary file added __debug_bin2873655182
Binary file not shown.
16 changes: 16 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ type ChatMessage struct {

var lastTimestamp int

func runClient() {//takes message and password, encrypts, decrypts, checks hash
var pass string//please note servers will use main at main.go
var message string


fmt.Println("Input password")
fmt.Scan(&pass)
fmt.Println("Input message")
fmt.Scan(&message)

encrypted := encryptUsingPass(message, pass)
fmt.Println(encrypted)
fmt.Println(decryptUsingPass(encrypted, pass))
fmt.Println(extractHash(encrypted))
}

func runClientSender() {
for {
fmt.Printf("> ")
Expand Down
2 changes: 1 addition & 1 deletion encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ func decryptUsingHash(ct []byte, pass []byte) []byte {
nonce, data := ct[:ns], ct[ns:]
bytes, _ := aead.Open(nil, nonce, data, nil)
return bytes
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module pingchat

go 1.25.0

//lists dependencies
require golang.org/x/crypto v0.49.0

require golang.org/x/sys v0.42.0 // indirect
13 changes: 5 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ var (
ip = flag.String("ip", "127.0.0.1", "server ip to connect to")
)

func main() {
func main() { //takes input and redirects to run either client or server
mode := flag.String("mode", "client", "inputs server or client")
flag.Parse()
if *reauthKernel {
enableKernelReplies(true)
} else if *server {
enableKernelReplies(false)

if *mode == "server"{
runServer()
} else if *send {
runClientSender()
} else {
runClientListener()
runClient()
}
}
6 changes: 3 additions & 3 deletions networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func makeChecksum(b []byte) uint16 {
func enableKernelReplies(val bool) {
option := "0"
if !val {
option = "1"
option = "1" //1 makes system ignore incoming pings
}
err := os.WriteFile("/proc/sys/net/ipv4/icmp_echo_ignore_all", []byte(option), 0644)
processErr(err)
Expand All @@ -42,10 +42,10 @@ func sendBytes(data []byte, dest string) []byte {
defer c.Close()

dst, _ := net.ResolveIPAddr("ip4", dest)
c.WriteTo(buf, dst)
c.WriteTo(buf, dst)//Send packets

recv := make([]byte, 1500)
c.SetReadDeadline(time.Now().Add(3 * time.Second))
c.SetReadDeadline(time.Now().Add(3 * time.Second)) //times out packets after 3 sec
n, _, err := c.ReadFrom(recv)
if err != nil {
fmt.Println("Error: ", err.Error())
Expand Down
19 changes: 14 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"encoding/hex"
"encoding/json"
"fmt"
"os"
"encoding/json"
"time"
)

Expand Down Expand Up @@ -49,6 +50,18 @@ func sendReply(ip string, incomingPayload []byte) string {
return string(encryptUsingHash(recordJson, key))
}

func runServer() {
//flag.Parse()
if *reauthKernel {
enableKernelReplies(true)
} else if *server {
enableKernelReplies(false)
listenForPackets()
} else {
fmt.Println(sendString(os.Args[1], "91.98.131.91"))
}
}

func updateChat(ip string, encrypted []byte) {
key := hex.EncodeToString(encrypted[:32])
store[key] = MsgRecord{
Expand All @@ -57,7 +70,3 @@ func updateChat(ip string, encrypted []byte) {
LastMsgTimestamp: int(time.Now().Unix()),
}
}

func runServer() {
listenForPackets()
}