[PD2] Relatorio inicio
Co-authored-by: tsousa111 <tiagao2001@hotmail.com>
This commit is contained in:
parent
6f8219d991
commit
b86992a10a
10 changed files with 192 additions and 289 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue