func IncomingMessageHeader(w http.ResponseWriter, req *http.Request) {
	// Check ticket
	t, err := fetchTicketHeader(req)
	if err != nil {
		httputils.ErrorOut(w, http.StatusUnauthorized, invalidTicketID)
		return
	}

	// Read header from request body
	header, err := readHeaderFromBody(req.Body)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, "invalid header posted")
		return
	}

	// Verify from/to header with the ticket info
	if header.From.Addr.String() != t.Sender.String() || header.To.Addr.String() != t.Recipient.String() {
		httputils.ErrorOut(w, http.StatusBadRequest, "header from/to address do not match the ticket")
		return
	}

	// If we are sending on behalf of another account, we need to add additional authorization information if we are originating
	if header.From.SignedBy == message.SignedByTypeAuthorized && IsOriginServer(header.From.Addr) {
		if t.AuthKey == "" {
			httputils.ErrorOut(w, http.StatusInternalServerError, "onbehalf signing, but token is not fetched with authentication")
			return
		}

		r := container.Instance.GetAuthKeyRepo()
		k, err := r.Fetch(t.AuthKey)
		if err != nil {
			httputils.ErrorOut(w, http.StatusInternalServerError, "error while fetching auth key")
			return
		}

		header.AuthorizedBy = &message.AuthorizedByType{
			PublicKey: k.PublicKey,
			Signature: k.Signature,
		}
	}

	// Add server signature if we are the originating server
	if IsOriginServer(header.From.Addr) {
		// Add a server signature to the header, so we know this server is the origin of the message
		err = message.SignServerHeader(header)
		if err != nil {
			httputils.ErrorOut(w, http.StatusInternalServerError, "error while signing incoming message")
			return
		}
	}

	// Save request
	err = message.StoreHeader(t.ID, header)
	if err != nil {
		httputils.ErrorOut(w, http.StatusInternalServerError, "error while storing message header")
		return
	}

	_ = httputils.JSONOut(w, http.StatusOK, httputils.StatusOk("saved message header"))
}
// IncomingMessageHeader deals with uploading message headers
IncomingMessageHeader deals with uploading message headers
// IncomingMessageHeader deals with uploading message headers
func IncomingMessageHeader(w http.ResponseWriter, req *http.Request) {
	t, err := fetchTicketHeader(req)
	if err != nil {
		httputils.ErrorOut(w, http.StatusUnauthorized, invalidTicketID)
		return
	}
	header, err := readHeaderFromBody(req.Body)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, "invalid header posted")
		return
	}
	if header.From.Addr.String() != t.Sender.String() || header.To.Addr.String() != t.Recipient.String() {
		httputils.ErrorOut(w, http.StatusBadRequest, "header from/to address do not match the ticket")
		return
	}
	if header.From.SignedBy == message.SignedByTypeAuthorized && IsOriginServer(header.From.Addr) {
		if t.AuthKey == "" {
			httputils.ErrorOut(w, http.StatusInternalServerError, "onbehalf signing, but token is not fetched with authentication")
			return
		}
		r := container.Instance.GetAuthKeyRepo()
		k, err := r.Fetch(t.AuthKey)
		if err != nil {
			httputils.ErrorOut(w, http.StatusInternalServerError, "error while fetching auth key")
			return
		}
		header.AuthorizedBy = &message.AuthorizedByType{
			PublicKey: k.PublicKey,
			Signature: k.Signature,
		}
	}
	if IsOriginServer(header.From.Addr) {
		err = message.SignServerHeader(header)
		if err != nil {
			httputils.ErrorOut(w, http.StatusInternalServerError, "error while signing incoming message")
			return
		}
	}
	err = message.StoreHeader(t.ID, header)
	if err != nil {
		httputils.ErrorOut(w, http.StatusInternalServerError, "error while storing message header")
		return
	}
	_ = httputils.JSONOut(w, http.StatusOK, httputils.StatusOk("saved message header"))
}
func IncomingMessageHeader ( w http . ResponseWriter , req * http . Request ) { t , err := fetchTicketHeader ( req ) if err != nil { httputils . ErrorOut ( w , http . StatusUnauthorized , invalidTicketID ) return } header , err := readHeaderFromBody ( req . Body ) if err != nil { httputils . ErrorOut ( w , http . StatusBadRequest , " " ) return } if header . From . Addr . String ( ) != t . Sender . String ( ) || header . To . Addr . String ( ) != t . Recipient . String ( ) { httputils . ErrorOut ( w , http . StatusBadRequest , " " ) return } if header . From . SignedBy == message . SignedByTypeAuthorized && IsOriginServer ( header . From . Addr ) { if t . AuthKey == " " { httputils . ErrorOut ( w , http . StatusInternalServerError , " " ) return } r := container . Instance . GetAuthKeyRepo ( ) k , err := r . Fetch ( t . AuthKey ) if err != nil { httputils . ErrorOut ( w , http . StatusInternalServerError , " " ) return } header . AuthorizedBy = & message . AuthorizedByType { PublicKey : k . PublicKey , Signature : k . Signature , } } if IsOriginServer ( header . From . Addr ) { err = message . SignServerHeader ( header ) if err != nil { httputils . ErrorOut ( w , http . StatusInternalServerError , " " ) return } } err = message . StoreHeader ( t . ID , header ) if err != nil { httputils . ErrorOut ( w , http . StatusInternalServerError , " " ) return } _ = httputils . JSONOut ( w , http . StatusOK , httputils . StatusOk ( " " ) ) }
IncomingMessageHeader deals with uploading message headers
IncomingMessageHeader deals with uploading message headers
// Check ticket // Read header from request body // Verify from/to header with the ticket info // If we are sending on behalf of another account, we need to add additional authorization information if we are originating // Add server signature if we are the originating server // Add a server signature to the header, so we know this server is the origin of the message // Save request