CSI-ES-2324/Projs/PD1/internal/server/server.go

57 lines
1.3 KiB
Go
Raw Normal View History

2024-04-16 12:23:00 +01:00
package server
import (
"PD1/internal/protocol"
2024-04-18 13:06:16 +01:00
"PD1/internal/utils/cryptoUtils"
"PD1/internal/utils/networking"
2024-04-16 12:23:00 +01:00
"fmt"
)
func clientHandler(connection networking.Connection[protocol.Packet], dataStore DataStore) {
defer connection.Conn.Close()
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")
}
}
2024-04-16 12:23:00 +01:00
}
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
2024-04-18 13:06:16 +01:00
//Read server keystore
password := AskServerPassword()
serverKeyStore := cryptoUtils.LoadKeyStore("certs/server/server.p12",password)
2024-04-18 13:06:16 +01:00
//Create server listener
server := networking.NewServer[protocol.Packet](&serverKeyStore,port)
go server.ListenLoop()
2024-04-16 12:23:00 +01:00
for {
//Receive Connection via channel
conn := <-server.C
//Launch client handler via clientHandler
go clientHandler(conn, dataStore)
2024-04-16 12:23:00 +01:00
}
}