perkeep/server/go/sigserver/camsigd.go

59 lines
1.3 KiB
Go
Raw Normal View History

2010-11-15 02:32:25 +00:00
package main
import (
2010-11-30 03:51:25 +00:00
"camli/auth"
"camli/http_util"
"camli/webserver"
2010-11-15 03:08:33 +00:00
"flag"
"fmt"
"http"
2010-11-15 03:08:33 +00:00
"os"
2010-11-15 02:32:25 +00:00
)
var gpgPath *string = flag.String("gpg-path", "/usr/bin/gpg", "Path to the gpg binary.")
2010-11-15 03:08:33 +00:00
var flagRing *string = flag.String("keyring", "./test/test-keyring.gpg",
"GnuPG public keyring file to use.")
var flagSecretRing *string = flag.String("secret-keyring", "./test/test-secring.gpg",
"GnuPG secret keyring file to use.")
var accessPassword string
2010-11-29 15:35:16 +00:00
func handleRoot(conn http.ResponseWriter, req *http.Request) {
fmt.Fprintf(conn, "camsigd")
}
2010-11-15 03:31:47 +00:00
func handleCamliSig(conn http.ResponseWriter, req *http.Request) {
handler := func (conn http.ResponseWriter, req *http.Request) {
http_util.BadRequestError(conn, "Unsupported path or method.")
}
switch req.Method {
case "POST":
switch req.URL.Path {
case "/camli/sig/sign":
handler = auth.RequireAuth(handleSign)
2010-11-30 07:22:11 +00:00
case "/camli/sig/verify":
handler = handleVerify
2010-11-15 03:31:47 +00:00
}
}
handler(conn, req)
}
2010-11-15 02:32:25 +00:00
func main() {
2010-11-15 03:08:33 +00:00
flag.Parse()
2010-11-15 03:31:47 +00:00
auth.AccessPassword = os.Getenv("CAMLI_PASSWORD")
if len(auth.AccessPassword) == 0 {
2010-11-15 03:08:33 +00:00
fmt.Fprintf(os.Stderr,
"No CAMLI_PASSWORD environment variable set.\n")
os.Exit(1)
}
ws := webserver.New()
ws.HandleFunc("/", handleRoot)
ws.HandleFunc("/camli/sig/", handleCamliSig)
ws.Serve()
2010-11-15 02:32:25 +00:00
}