[PD2] Relatorio inicio

Co-authored-by: tsousa111 <tiagao2001@hotmail.com>
This commit is contained in:
Afonso Franco 2024-05-31 23:14:06 +01:00
parent 6f8219d991
commit b86992a10a
Signed by: afonso
SSH key fingerprint: SHA256:PQTRDHPH3yALEGtHXnXBp3Orfcn21pK20t0tS1kHg54
10 changed files with 192 additions and 289 deletions

View file

@ -104,27 +104,37 @@ func HandleRegister(c *gin.Context, dataStore DataStore, keyStore cryptoUtils.Ke
c.JSON(http.StatusBadRequest, gin.H{"error": "User certificate is invalid"})
return
}
err = keyStore.CheckCert(userCert, postRegister.UID, "MSG SERVICE")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "User certificate is invalid, not trusted, belongs to another user or has incorrect usage field"})
if err := keyStore.CheckCertCA(userCert); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if err := keyStore.CheckCertTime(userCert); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if err := keyStore.CheckCertUsage(userCert, "MSG SERVICE"); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
hashedPassword, err := HashPassword(postRegister.Password)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not hash password"})
c.JSON(http.StatusBadRequest, gin.H{"error": "Could not hash password"})
return
}
err = dataStore.InsertUser(postRegister.UID, hashedPassword)
uid,err := keyStore.GetCertPseudonym(userCert)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = dataStore.InsertUser(uid, hashedPassword)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not insert user into DB"})
c.JSON(http.StatusBadRequest, gin.H{"error": "Could not insert user into DB"})
return
}
storeUserCertificate := protocol.NewStoreUserCert(userCert.Raw)
statusCode, body, err := forwardStoreUserCert(keyStore.GetGatewayOutgoingTLSConfig(), postRegister.UID, storeUserCertificate)
statusCode, body, err := forwardStoreUserCert(keyStore.GetGatewayOutgoingTLSConfig(),uid, storeUserCertificate)
if err != nil {
log.Println(err.Error())
} else {