From 1b976129dd92bee124df052cfdbc895e7b3c5c5c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 20 Jun 2010 18:26:54 -0700 Subject: [PATCH 1/2] require basic auth for getting too --- camlistored/camlistored.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/camlistored/camlistored.go b/camlistored/camlistored.go index d77890fd3..abbf8240d 100644 --- a/camlistored/camlistored.go +++ b/camlistored/camlistored.go @@ -18,7 +18,7 @@ import "regexp" var listen *string = flag.String("listen", "0.0.0.0:3179", "host:port to listen on") var storageRoot *string = flag.String("root", "/tmp/camliroot", "Root directory to store files") -var sharedSecret string +var putPassword string var kGetPutPattern *regexp.Regexp = regexp.MustCompile(`^/camli/(sha1)-([a-f0-9]+)$`) var kBasicAuthPattern *regexp.Regexp = regexp.MustCompile(`^Basic ([a-zA-Z0-9\+/=]+)`) @@ -88,9 +88,18 @@ func putAllowed(req *http.Request) bool { } var outBuf []byte = make([]byte, base64.StdEncoding.DecodedLen(len(matches[1]))) bytes, err := base64.StdEncoding.Decode(outBuf, []uint8(matches[1])) + if err != nil { + return false + } + password := string(outBuf) fmt.Println("Decoded bytes:", bytes, " error: ", err) - fmt.Println("Got userPass:", string(outBuf)) - return false + fmt.Println("Got userPass:", password) + return password != "" && password == putPassword; +} + +func getAllowed(req *http.Request) bool { + // For now... + return putAllowed(req) } func handleCamli(conn *http.Conn, req *http.Request) { @@ -108,6 +117,13 @@ func handleCamli(conn *http.Conn, req *http.Request) { } func handleGet(conn *http.Conn, req *http.Request) { + if !getAllowed(req) { + conn.SetHeader("WWW-Authenticate", "Basic realm=\"camlistored\"") + conn.WriteHeader(http.StatusUnauthorized) + fmt.Fprintf(conn, "Authentication required.") + return + } + objRef := ParsePath(req.URL.Path) if objRef == nil { badRequestError(conn, "Malformed GET URL.") @@ -239,8 +255,8 @@ This is camlistored, a Camlistore storage daemon. func main() { flag.Parse() - sharedSecret = os.Getenv("CAMLI_PASSWORD") - if len(sharedSecret) == 0 { + putPassword = os.Getenv("CAMLI_PASSWORD") + if len(putPassword) == 0 { fmt.Fprintf(os.Stderr, "No CAMLI_PASSWORD environment variable set.\n") os.Exit(1) From 3e2e4439862cb7590a1a52cc0c7a52241d6ae432 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 20 Jun 2010 18:28:29 -0700 Subject: [PATCH 2/2] move camlistored (go blob server) under blobstore directory --- {camlistored => blobserver/go}/.gitignore | 0 {camlistored => blobserver/go}/Makefile | 0 {camlistored => blobserver/go}/README | 0 {camlistored => blobserver/go}/camlistored.go | 0 {camlistored => blobserver/go}/test-put.pl | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {camlistored => blobserver/go}/.gitignore (100%) rename {camlistored => blobserver/go}/Makefile (100%) rename {camlistored => blobserver/go}/README (100%) rename {camlistored => blobserver/go}/camlistored.go (100%) rename {camlistored => blobserver/go}/test-put.pl (100%) diff --git a/camlistored/.gitignore b/blobserver/go/.gitignore similarity index 100% rename from camlistored/.gitignore rename to blobserver/go/.gitignore diff --git a/camlistored/Makefile b/blobserver/go/Makefile similarity index 100% rename from camlistored/Makefile rename to blobserver/go/Makefile diff --git a/camlistored/README b/blobserver/go/README similarity index 100% rename from camlistored/README rename to blobserver/go/README diff --git a/camlistored/camlistored.go b/blobserver/go/camlistored.go similarity index 100% rename from camlistored/camlistored.go rename to blobserver/go/camlistored.go diff --git a/camlistored/test-put.pl b/blobserver/go/test-put.pl similarity index 100% rename from camlistored/test-put.pl rename to blobserver/go/test-put.pl