[PD1] crypto changes and TLS almost done
This commit is contained in:
parent
2c4f1fd2fc
commit
5ae7358a0d
13 changed files with 138 additions and 87 deletions
|
@ -115,7 +115,7 @@ func (ds DataStore) GetAllMessages(toUID string) []protocol.Packet {
|
|||
if err := rows.Scan(&fromUID, &toUID, &content, ×tamp); 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 {
|
||||
|
|
15
Projs/PD1/internal/server/interface.go
Normal file
15
Projs/PD1/internal/server/interface.go
Normal 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()
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue