71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package client
|
|
|
|
import (
|
|
"PD1/internal/protocol"
|
|
"PD1/internal/utils/cryptoUtils"
|
|
"PD1/internal/utils/networking"
|
|
"flag"
|
|
"fmt"
|
|
)
|
|
|
|
func Run() {
|
|
var userFile string
|
|
flag.StringVar(&userFile, "user", "userdata.p12", "Specify user data file")
|
|
flag.Parse()
|
|
|
|
if flag.NArg() == 0 {
|
|
panic("No command provided. Use 'help' for instructions.")
|
|
}
|
|
//Get user KeyStore
|
|
password := AskUserPassword()
|
|
clientKeyStore := cryptoUtils.LoadKeyStore(userFile, password)
|
|
|
|
command := flag.Arg(0)
|
|
switch command {
|
|
case "send":
|
|
if flag.NArg() < 3 {
|
|
panic("Insufficient arguments for 'send' command. Usage: send <UID> <SUBJECT>")
|
|
}
|
|
uid := flag.Arg(1)
|
|
//subject := flag.Arg(2)
|
|
//messageContent := readMessageContent()
|
|
|
|
cl := networking.NewClient[protocol.Packet](&clientKeyStore)
|
|
defer cl.Connection.Conn.Close()
|
|
|
|
certRequestPacket := protocol.NewRequestUserCertPacket(uid)
|
|
cl.Connection.Send(certRequestPacket)
|
|
|
|
var certPacket protocol.Packet
|
|
cl.Connection.Receive(&certPacket)
|
|
uidCert := (certPacket.Body).(protocol.SendUserCertPacket)
|
|
fmt.Println(uidCert)
|
|
|
|
// TODO: Encrypt message
|
|
//submitMessage(cl, uid, cipherContent)
|
|
|
|
case "askqueue":
|
|
cl := networking.NewClient[protocol.Packet](&clientKeyStore)
|
|
defer cl.Connection.Conn.Close()
|
|
|
|
case "getmsg":
|
|
if flag.NArg() < 2 {
|
|
panic("Insufficient arguments for 'getmsg' command. Usage: getmsg <NUM>")
|
|
}
|
|
//num := flag.Arg(1)
|
|
cl := networking.NewClient[protocol.Packet](&clientKeyStore)
|
|
defer cl.Connection.Conn.Close()
|
|
|
|
case "help":
|
|
showHelp()
|
|
|
|
default:
|
|
commandError()
|
|
}
|
|
|
|
}
|
|
|
|
func submitMessage(cl networking.Client[protocol.Packet], uid string, content []byte) {
|
|
pack := protocol.NewSubmitMessagePacket(uid, content)
|
|
cl.Connection.Send(pack)
|
|
}
|