[PD1] Fixed stuff. Unmarshal still returns map[string]interface{}, need to fix
This commit is contained in:
parent
c131aa2aea
commit
39a0e5c01f
6 changed files with 127 additions and 96 deletions
|
@ -154,3 +154,22 @@ func (ds DataStore) GetUserCertificate(uid string) protocol.Packet {
|
|||
}
|
||||
return protocol.NewSendUserCertPacket(uid, userCert)
|
||||
}
|
||||
|
||||
func userExists(db *sql.DB, uid string) bool {
|
||||
// Prepare the SQL statement for checking if a user exists
|
||||
query := `
|
||||
SELECT COUNT(*)
|
||||
FROM users
|
||||
WHERE UID = ?
|
||||
`
|
||||
|
||||
var count int
|
||||
// Execute the SQL query
|
||||
err := db.QueryRow(query, uid).Scan(&count)
|
||||
if err != nil {
|
||||
log.Panicln("Error checking if user exists")
|
||||
}
|
||||
|
||||
// If count is greater than 0, the user exists
|
||||
return count > 0
|
||||
}
|
||||
|
|
|
@ -9,17 +9,29 @@ import (
|
|||
|
||||
func clientHandler(connection networking.Connection[protocol.Packet], dataStore DataStore) {
|
||||
defer connection.Conn.Close()
|
||||
_ = dataStore
|
||||
|
||||
//Get certificate sent by user
|
||||
clientCert := connection.GetPeerCertificate()
|
||||
oidValueMap := cryptoUtils.ExtractAllOIDValues(clientCert)
|
||||
fmt.Println(oidValueMap)
|
||||
//Get the OID values
|
||||
oidMap := cryptoUtils.ExtractAllOIDValues(clientCert)
|
||||
//Get the UID of this user
|
||||
UID := oidMap["2.5.4.65"]
|
||||
if UID=="" {
|
||||
panic("User certificate does not specify it's PSEUDONYM")
|
||||
}
|
||||
|
||||
for {
|
||||
pac := connection.Receive()
|
||||
var pac protocol.Packet
|
||||
connection.Receive(&pac)
|
||||
switch pac.Flag {
|
||||
case protocol.ReqUserCertPkt:
|
||||
//userCertPacket := dataStore.GetUserCertificate(uid)
|
||||
//connection.Send(userCertPacket)
|
||||
fmt.Printf("Type of pac.Body: %T\n", pac.Body)
|
||||
UserCertPacket, ok := (pac.Body).(protocol.RequestUserCertPacket)
|
||||
if !ok {
|
||||
panic("Could not cast packet to it's type")
|
||||
}
|
||||
userCertPacket := dataStore.GetUserCertificate(UserCertPacket.UID)
|
||||
connection.Send(userCertPacket)
|
||||
case protocol.ReqAllMsgPkt:
|
||||
fmt.Println("ReqAllMsg")
|
||||
case protocol.ReqMsgPkt:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue