You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.0 KiB
102 lines
2.0 KiB
package main
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/gob"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"net"
|
|
"time"
|
|
"golang.org/x/term"
|
|
"syscall"
|
|
)
|
|
|
|
type Request struct {
|
|
Username string
|
|
Password string
|
|
Operation string
|
|
Site string
|
|
VaultData string
|
|
Timestamp int64
|
|
Nonce string
|
|
}
|
|
|
|
type Response struct {
|
|
Message string
|
|
}
|
|
|
|
func generateNonce() (string, error) {
|
|
b := make([]byte, 12) // 96-bit nonce
|
|
_, err := rand.Read(b)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return hex.EncodeToString(b), nil
|
|
}
|
|
|
|
func main() {
|
|
var host string
|
|
fmt.Print("Enter host or IP: ")
|
|
fmt.Scanln(&host)
|
|
|
|
conn, err := net.Dial("tcp", host+":9898")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
var username, op, site, vaultData string
|
|
fmt.Print("Username: ")
|
|
fmt.Scanln(&username)
|
|
|
|
fmt.Print("Password: ")
|
|
bytePassword, err := term.ReadPassword(int(syscall.Stdin))
|
|
fmt.Println()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
password := string(bytePassword)
|
|
|
|
fmt.Print("Operation (register/store/get): ")
|
|
fmt.Scanln(&op)
|
|
|
|
if op == "store" || op == "get" {
|
|
fmt.Print("Site: ")
|
|
fmt.Scanln(&site)
|
|
}
|
|
if op == "store" {
|
|
fmt.Print("Password to store: ")
|
|
fmt.Scanln(&vaultData)
|
|
}
|
|
|
|
nonce, err := generateNonce()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
req := Request{
|
|
Username: username,
|
|
Password: password,
|
|
Operation: op,
|
|
Site: site,
|
|
VaultData: vaultData,
|
|
Timestamp: time.Now().Unix(),
|
|
Nonce: nonce,
|
|
}
|
|
|
|
enc := gob.NewEncoder(conn)
|
|
dec := gob.NewDecoder(conn)
|
|
|
|
if err := enc.Encode(req); err != nil {
|
|
fmt.Println("Failed to send request:", err)
|
|
return
|
|
}
|
|
|
|
var res Response
|
|
if err := dec.Decode(&res); err != nil {
|
|
fmt.Println("Failed to receive response:", err)
|
|
return
|
|
}
|
|
|
|
fmt.Println("Server response:", res.Message)
|
|
}
|
|
|