* Rework client/server authentication. - Remove Signature from all requests, and instead expect a signature in HTTP header "VSP-Client-Signature". - Remove CommitmentSignatures from the database. - Use a bool flag to indicate when a ticket is missing from the database rather than an error. This commit introduces a lot of duplication into each of the authenticated HTTP handlers. This should be removed in future work which moves the authentication to a dedicated middleware. * Introduce auth and rpc middleware. This removed the duplication added in the previous commit, and also removes the duplication of RPC client error handling.
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package webapi
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin/binding"
|
|
"github.com/jholdstock/dcrvsp/database"
|
|
)
|
|
|
|
// ticketStatus is the handler for "GET /ticketstatus".
|
|
func ticketStatus(c *gin.Context) {
|
|
|
|
// Get values which have been added to context by middleware.
|
|
rawRequest := c.MustGet("RawRequest").([]byte)
|
|
ticket := c.MustGet("Ticket").(database.Ticket)
|
|
knownTicket := c.MustGet("KnownTicket").(bool)
|
|
|
|
if !knownTicket {
|
|
log.Warnf("Invalid ticket from %s", c.ClientIP())
|
|
sendErrorResponse("invalid ticket", http.StatusBadRequest, c)
|
|
return
|
|
}
|
|
|
|
var ticketStatusRequest TicketStatusRequest
|
|
if err := binding.JSON.BindBody(rawRequest, &ticketStatusRequest); err != nil {
|
|
log.Warnf("Bad ticketstatus request from %s: %v", c.ClientIP(), err)
|
|
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
|
return
|
|
}
|
|
|
|
sendJSONResponse(ticketStatusResponse{
|
|
Timestamp: time.Now().Unix(),
|
|
Request: ticketStatusRequest,
|
|
Status: "active",
|
|
VoteChoices: ticket.VoteChoices,
|
|
}, c)
|
|
}
|