diff --git a/Projs/PD2/internal/gateway/gateway.go b/Projs/PD2/internal/gateway/gateway.go index 65093c8..14464d4 100644 --- a/Projs/PD2/internal/gateway/gateway.go +++ b/Projs/PD2/internal/gateway/gateway.go @@ -1,5 +1,77 @@ package gateway -func Run(){ +import ( + "PD1/internal/protocol" + "fmt" + "net/http" + + "github.com/gin-gonic/gin" +) + +func HandleGetMessage(c *gin.Context){ + fmt.Println("Get Message Handler") } +func HandleGetUnreadMsgsInfo(c *gin.Context){ + fmt.Println("Get Unread Messages Info Handler") + +} +func HandleGetUserCert(c *gin.Context){ + fmt.Println("Get User Cert Handler") + +} +func HandleSendMessage(c *gin.Context){ + fmt.Println("Send Message Handler") + +} + +func HandleRegister(c *gin.Context){ + var postRegister protocol.PostRegister + c.Bind(postRegister) + //Hash the password (using salt) and store it on the db + //Get the username from the certificate +} + +func AuthMiddleware(c *gin.Context){ + fmt.Println("Authentication Middleware") +} + +func Run(){ + router := gin.Default() + + auth := router.Group("/", func(c *gin.Context) { + AuthMiddleware(c) + }) + + auth.GET("/message/:num", func(c *gin.Context) { + HandleGetMessage(c) + }) + + auth.GET("/queue", func(c *gin.Context) { + HandleGetUnreadMsgsInfo(c) + }) + + auth.GET("/cert/:user", func(c *gin.Context) { + HandleGetUserCert(c) + }) + + auth.POST("/message", func(c *gin.Context) { + HandleSendMessage(c) + }) + + router.POST("/register",func(c *gin.Context) { + HandleRegister(c) + }) + + server := http.Server{ + Addr: "0.0.0.0:8080", + Handler: router, + //TODO: Verify if it's the gateway + TLSConfig: serverKeyStore.GetServerTLSConfig(), + } + + err = server.ListenAndServeTLS("", "") + if err!=nil { + log.Fatal(err.Error()) + } +} diff --git a/Projs/PD2/internal/protocol/protocol.go b/Projs/PD2/internal/protocol/protocol.go index 5987c11..fdaf7c2 100644 --- a/Projs/PD2/internal/protocol/protocol.go +++ b/Projs/PD2/internal/protocol/protocol.go @@ -52,6 +52,11 @@ type ( Timestamp time.Time `json:"timestamp"` } + PostRegister struct { + Password string `json:"password"` + Certificate []byte `json:"certificate"` + } + ReportError struct { ErrorMessage string `json:"error"` } diff --git a/Projs/PD2/internal/server/server.go b/Projs/PD2/internal/server/server.go index e4118cb..9066fc9 100644 --- a/Projs/PD2/internal/server/server.go +++ b/Projs/PD2/internal/server/server.go @@ -141,7 +141,8 @@ func Run() { server := http.Server{ Addr: "0.0.0.0:8080", Handler: r, - TLSConfig: serverKeyStore.GetTLSConfig(), + //TODO: Verify if it's the gateway + TLSConfig: serverKeyStore.GetServerTLSConfig(), } err = server.ListenAndServeTLS("", "")