[PD1] crypto changes and TLS almost done

This commit is contained in:
Afonso Franco 2024-04-18 17:15:47 +01:00
parent 2c4f1fd2fc
commit 5ae7358a0d
Signed by: afonso
SSH key fingerprint: SHA256:aiLbdlPwXKJS5wMnghdtod0SPy8imZjlVvCyUX9DJNk
13 changed files with 138 additions and 87 deletions

View file

@ -115,7 +115,7 @@ func (ds DataStore) GetAllMessages(toUID string) []protocol.Packet {
if err := rows.Scan(&fromUID, &toUID, &content, &timestamp); err != nil {
log.Panicln("Failed to scan row:", err)
}
message := protocol.NewMessagePacket(fromUID, toUID, content, timestamp)
message := protocol.NewServerMessagePacket(fromUID, toUID, content, timestamp)
messagePackets = append(messagePackets, message)
}
if err := rows.Err(); err != nil {

View file

@ -0,0 +1,15 @@
package server
import (
"bufio"
"fmt"
"os"
)
func AskServerPassword() string {
fmt.Println("Enter key store password")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
// FIX: make sure this doesnt die
return scanner.Text()
}

View file

@ -10,15 +10,17 @@ import (
func clientHandler(connection networking.Connection[protocol.Packet], dataStore DataStore) {
defer connection.Conn.Close()
// FIX: GET THE UID FROM THE USER CERTIFICATE FROM THE TLS SESSION
uid := "0"
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)
//userCertPacket := dataStore.GetUserCertificate(uid)
//connection.Send(userCertPacket)
case protocol.ReqAllMsgPkt:
fmt.Println("ReqAllMsg")
case protocol.ReqMsgPkt:
@ -35,13 +37,14 @@ func Run(port int) {
dataStore := OpenDB()
defer dataStore.db.Close()
//TODO: Get the server's keystore path instead of hardcoding it
//FIX: Get the server's keystore path instead of hardcoding it
//Read server keystore
serverKeyStore := cryptoUtils.LoadKeyStore("serverdata.p12")
password := AskServerPassword()
serverKeyStore := cryptoUtils.LoadKeyStore("certs/serverdata.p12",password)
//Create server listener
server := networking.NewServer[protocol.Packet](serverKeyStore,port)
server := networking.NewServer[protocol.Packet](&serverKeyStore,port)
go server.ListenLoop()
for {