perkeep/server/go/sigserver/sign.go

39 lines
841 B
Go
Raw Normal View History

2010-11-15 03:31:47 +00:00
package main
import (
2010-12-06 06:34:46 +00:00
"camli/httputil"
"camli/jsonsign"
"fmt"
2010-11-15 03:31:47 +00:00
"http"
)
const kMaxJsonLength = 1024 * 1024
2010-11-15 03:31:47 +00:00
func handleSign(conn http.ResponseWriter, req *http.Request) {
if !(req.Method == "POST" && req.URL.Path == "/camli/sig/sign") {
2010-12-06 06:34:46 +00:00
httputil.BadRequestError(conn, "Inconfigured handler.")
2010-11-15 03:31:47 +00:00
return
}
req.ParseForm()
jsonStr := req.FormValue("json")
if jsonStr == "" {
httputil.BadRequestError(conn, "Missing json parameter")
2010-11-15 03:31:47 +00:00
return
}
if len(jsonStr) > kMaxJsonLength {
httputil.BadRequestError(conn, "json parameter too large")
2010-11-15 03:31:47 +00:00
return
}
sreq := &jsonsign.SignRequest{UnsignedJson: jsonStr, Fetcher: blobFetcher}
signedJson, err := sreq.Sign()
if err != nil {
// TODO: some aren't really a "bad request"
httputil.BadRequestError(conn, fmt.Sprintf("%v", err))
return
}
conn.Write([]byte(signedJson))
2010-11-15 03:31:47 +00:00
}