Documentation ¶
Index ¶
- Constants
- Variables
- func AuthToken(header http.Header) string
- func ClientError(uid uuid.UUID, r *http.Request, w http.ResponseWriter, errMsg string, code int)
- func ContentEncoding(header http.Header) string
- func ContentType(header http.Header) string
- func FetchCSR(auth string, get GetCSR) http.HandlerFunc
- func GetSortedCompactJSON(data []byte) ([]byte, error)
- func GetUUID(r *http.Request) (uuid.UUID, error)
- func HandleOptions(http.ResponseWriter, *http.Request)
- func Health(server string) http.HandlerFunc
- func HttpFailed(StatusCode int) bool
- func HttpSuccess(StatusCode int) bool
- func NewRouter() *chi.Mux
- func ReadBody(r *http.Request) ([]byte, error)
- func Ready(server string, readinessChecks []func() error) http.HandlerFunc
- func Register(auth string, initialize InitializeIdentity) http.HandlerFunc
- func SendResponse(w http.ResponseWriter, resp HTTPResponse)
- func ServerError(uid uuid.UUID, r *http.Request, w http.ResponseWriter, errMsg string, code int)
- func UpdateActive(auth string, deactivate UpdateActivateStatus, reactivate UpdateActivateStatus) http.HandlerFunc
- type ActiveUpdatePayload
- type CheckAuth
- type GetCSR
- type HTTPRequest
- type HTTPResponse
- type HTTPServer
- type InitializeIdentity
- type Operation
- type RegistrationPayload
- type Sha256Sum
- type Sign
- type SigningService
- type UpdateActivateStatus
- type VerificationService
- type Verify
- type VerifyOffline
Constants ¶
const ( UUIDKey = "uuid" VerifyPath = "/verify" OfflinePath = "/offline" HashEndpoint = "/hash" RegisterEndpoint = "/register" CSREndpoint = "/csr" ActiveUpdateEndpoint = "/device/updateActive" MetricsEndpoint = "/metrics" LivenessCheckEndpoint = "/healthz" ReadinessCheckEndpoint = "/readyz" BinType = "application/octet-stream" TextType = "text/plain" JSONType = "application/json" XUPPHeader = "X-Ubirch-UPP" XAuthHeader = "X-Auth-Token" XErrorHeader = "X-Err" HexEncoding = "hex" HashLen = 32 )
const ( GatewayTimeout = 20 * time.Second // time after which a 504 response will be sent if no timely response could be produced ShutdownTimeout = 10 * time.Second // time after which the server will be shut down forcefully if graceful shutdown did not happen before ReadTimeout = 1 * time.Second // maximum duration for reading the entire request -> low since we only expect requests with small content WriteTimeout = 60 * time.Second // time after which the connection will be closed if response was not written -> this should never happen IdleTimeout = 60 * time.Second // time to wait for the next request when keep-alives are enabled )
Variables ¶
Functions ¶
func ClientError ¶
ClientError is a wrapper for http.Error that additionally logs uuid, request URL path, error message and status with logging level "warning"
func ContentEncoding ¶
helper function to get "Content-Transfer-Encoding" from request header
func ContentType ¶
helper function to get "Content-Type" from request header
func GetSortedCompactJSON ¶
func HandleOptions ¶
func HandleOptions(http.ResponseWriter, *http.Request)
func HttpFailed ¶
func HttpSuccess ¶
func Ready ¶
func Ready(server string, readinessChecks []func() error) http.HandlerFunc
Ready is a readiness probe.
func Register ¶
func Register(auth string, initialize InitializeIdentity) http.HandlerFunc
func SendResponse ¶
func SendResponse(w http.ResponseWriter, resp HTTPResponse)
SendResponse forwards a response to the client
func ServerError ¶
ServerError is a wrapper for http.Error that additionally logs uuid, request URL path, error message and status with logging level "error". The error message is not sent to the client.
func UpdateActive ¶
func UpdateActive(auth string, deactivate UpdateActivateStatus, reactivate UpdateActivateStatus) http.HandlerFunc
Types ¶
type ActiveUpdatePayload ¶
func GetActiveUpdatePayload ¶
func GetActiveUpdatePayload(r *http.Request) (*ActiveUpdatePayload, error)
type HTTPRequest ¶
type HTTPResponse ¶
type HTTPServer ¶
func InitHTTPServer ¶
func InitHTTPServer(conf *config.Config, initialize InitializeIdentity, getCSR GetCSR, checkAuth CheckAuth, sign Sign, verify Verify, verifyOffline VerifyOffline, deactivate UpdateActivateStatus, reactivate UpdateActivateStatus, serverID string, readinessChecks []func() error) *HTTPServer
func (*HTTPServer) AddServiceEndpoint ¶
func (srv *HTTPServer) AddServiceEndpoint(endpointPath string, handle func(offline, isHash bool) http.HandlerFunc, supportOffline bool)
func (*HTTPServer) Serve ¶
func (srv *HTTPServer) Serve() error
func (*HTTPServer) SetUpCORS ¶
func (srv *HTTPServer) SetUpCORS(allowedOrigins []string, debug bool)
type InitializeIdentity ¶
type RegistrationPayload ¶
type Sign ¶
type Sign func(msg HTTPRequest) (resp HTTPResponse)
type SigningService ¶
func (*SigningService) HandleSigningRequest ¶
func (s *SigningService) HandleSigningRequest(op Operation) func(bool, bool) http.HandlerFunc
HandleSigningRequest unpacks an incoming HTTP request and calls the Sign function with the according parameters. The function expects an Operation as parameter. Supported operations are anchoring, chaining, deleting etc.
There are online and offline signing endpoints for several operations, as well as endpoints for direct hash injection and JSON data packages for all operations. For that reason, the function is nested in a way that it can be passed to the AddServiceEndpoint function with the following signature: func (srv *HTTPServer) AddServiceEndpoint(endpointPath string, handle func(offline bool, isHash bool) http.HandlerFunc, supportOffline bool) That way we can call AddServiceEndpoint once for each operation in order to initialize the above endpoints.
type UpdateActivateStatus ¶
type VerificationService ¶
type VerificationService struct { Verify VerifyOffline }
func (*VerificationService) HandleVerificationRequest ¶
func (s *VerificationService) HandleVerificationRequest(offline, isHashRequest bool) http.HandlerFunc
HandleVerificationRequest unpacks an incoming HTTP request and calls either Verify or VerifyOffline depending on the endpoint the request was received at.
There are online and offline verification endpoints, as well as endpoints for direct hash injection and JSON data packages. For that reason, the function is nested in a way that it can be passed to the AddServiceEndpoint function with the following signature: func (srv *HTTPServer) AddServiceEndpoint(endpointPath string, handle func(offline bool, isHash bool) http.HandlerFunc, supportOffline bool)
type VerifyOffline ¶
type VerifyOffline func(upp []byte, hash []byte) HTTPResponse