@@ -42,7 +42,7 @@ const (
4242
4343// Mirror is the interface that the handler uses to interact with the mirror's state.
4444type Mirror interface {
45- AddCheckpoint (ctx context.Context , cp [] byte , oldSize uint64 , proof [][]byte ) error
45+ AddCheckpoint (ctx context.Context , oldSize uint64 , proof [][] byte , cp []byte ) error
4646 AddEntries (ctx context.Context , logOrigin string , uploadStart , uploadEnd uint64 , ticket []byte , next func () (* mirror.Package , error )) ([]byte , error )
4747}
4848
@@ -114,7 +114,7 @@ func addCheckpoint(m Mirror) http.HandlerFunc {
114114 return
115115 }
116116
117- if err := m .AddCheckpoint (r .Context (), cp , oldSize , proof ); err != nil {
117+ if err := m .AddCheckpoint (r .Context (), oldSize , proof , cp ); err != nil {
118118 slog .ErrorContext (r .Context (), "AddCheckpoint failed" , slog .Any ("error" , err ))
119119 http .Error (w , err .Error (), http .StatusInternalServerError )
120120 return
@@ -127,6 +127,11 @@ func addCheckpoint(m Mirror) http.HandlerFunc {
127127
128128func addEntries (m Mirror ) http.HandlerFunc {
129129 return func (w http.ResponseWriter , r * http.Request ) {
130+ // SPEC: The request body MUST have Content-Type of application/octet-stream ...
131+ if t := strings .ToLower (r .Header .Get ("Content-Type" )); t != "application/octet-stream" {
132+ http .Error (w , fmt .Sprintf ("invalid Content-Type %q" , t ), http .StatusBadRequest )
133+ return
134+ }
130135 req , err := parseAddEntriesPreamble (r .Body )
131136 if err != nil {
132137 http .Error (w , fmt .Sprintf ("failed to parse header: %v" , err ), http .StatusBadRequest )
@@ -227,15 +232,14 @@ func (a *addEntriesRequest) NextPackage() (*mirror.Package, error) {
227232//
228233// Returns a struct which represents the request, and provides streaming access to the entry packages.
229234func parseAddEntriesPreamble (r io.Reader ) (* addEntriesRequest , error ) {
230- //SPEC: The request body MUST have Content-Type of application/octet-stream and contain the
231- // following values, concatenated.
232- // 2 bytes, encoding a big-endian uint16: log_origin_size
233- // log_origin_size bytes, containing the log origin: log_origin
234- // 8 bytes, encoding a big-endian uint64: upload_start
235- // 8 bytes, encoding a big-endian uint64: upload_end
236- // 2 bytes, encoding a big-endian uint16: ticket_size
237- // ticket_size bytes, containing an opaque ticket value, described below
238- // A sequence of entry packages
235+ // SPEC: The request body MUST ... contain the following values, concatenated:
236+ // 2 bytes, encoding a big-endian uint16: log_origin_size
237+ // log_origin_size bytes, containing the log origin: log_origin
238+ // 8 bytes, encoding a big-endian uint64: upload_start
239+ // 8 bytes, encoding a big-endian uint64: upload_end
240+ // 2 bytes, encoding a big-endian uint16: ticket_size
241+ // ticket_size bytes, containing an opaque ticket value, described below
242+ // A sequence of entry packages
239243 var logOriginSize uint16
240244 if err := binary .Read (r , binary .BigEndian , & logOriginSize ); err != nil {
241245 return nil , err
0 commit comments