CSI-ES-2324/Projs/PD1/internal/server/server.go
2024-04-19 02:19:22 +01:00

55 lines
1.3 KiB
Go

package server
import (
"PD1/internal/protocol"
"PD1/internal/utils/cryptoUtils"
"PD1/internal/utils/networking"
"fmt"
)
func clientHandler(connection networking.Connection[protocol.Packet], dataStore DataStore) {
defer connection.Conn.Close()
_ = dataStore
clientCert := connection.GetPeerCertificate()
oidValueMap := cryptoUtils.ExtractAllOIDValues(clientCert)
fmt.Println(oidValueMap)
for {
pac := connection.Receive()
switch pac.Flag {
case protocol.ReqUserCertPkt:
//userCertPacket := dataStore.GetUserCertificate(uid)
//connection.Send(userCertPacket)
case protocol.ReqAllMsgPkt:
fmt.Println("ReqAllMsg")
case protocol.ReqMsgPkt:
fmt.Println("ReqMsg")
case protocol.SubmitMsgPkt:
fmt.Println("SubmitMsg")
}
}
}
func Run(port int) {
//Open connection to DB
dataStore := OpenDB()
defer dataStore.db.Close()
//FIX: Get the server's keystore path instead of hardcoding it
//Read server keystore
password := AskServerPassword()
serverKeyStore := cryptoUtils.LoadKeyStore("certs/server/server.p12", password)
//Create server listener
server := networking.NewServer[protocol.Packet](&serverKeyStore, port)
go server.ListenLoop()
for {
//Receive Connection via channel
conn := <-server.C
//Launch client handler via clientHandler
go clientHandler(conn, dataStore)
}
}