[ARVADOS] created: f39807a3c5dd32520bebd4fcd5254f214351eb4f

git at public.curoverse.com git at public.curoverse.com
Wed Oct 15 18:29:04 EDT 2014


        at  f39807a3c5dd32520bebd4fcd5254f214351eb4f (commit)


commit f39807a3c5dd32520bebd4fcd5254f214351eb4f
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed Oct 15 18:27:35 2014 -0400

    4219: Accept signatures even if other hints are present in URL.

diff --git a/services/keepstore/perms.go b/services/keepstore/perms.go
index 1438155..9fd65dd 100644
--- a/services/keepstore/perms.go
+++ b/services/keepstore/perms.go
@@ -83,20 +83,24 @@ func SignLocator(blob_locator string, api_token string, expiry time.Time) string
 // VerifySignature returns true if the signature on the signed_locator
 // can be verified using the given api_token.
 func VerifySignature(signed_locator string, api_token string) bool {
-	if re, err := regexp.Compile(`^([a-f0-9]{32}(\+[0-9]+)?).*\+A[[:xdigit:]]+@([[:xdigit:]]{8})`); err == nil {
-		if matches := re.FindStringSubmatch(signed_locator); matches != nil {
-			blob_locator := matches[1]
-			timestamp_hex := matches[3]
-			if expire_ts, err := ParseHexTimestamp(timestamp_hex); err == nil {
-				// Fail signatures with expired timestamps.
-				if expire_ts.Before(time.Now()) {
-					return false
-				}
-				return signed_locator == SignLocator(blob_locator, api_token, expire_ts)
-			}
-		}
+	re, err := regexp.Compile(`^([[:xdigit:]]{32}).*\+A([[:xdigit:]]{40})@([[:xdigit:]]{8})`)
+	if err != nil {
+		// Could not compile regexp(!)
+		return false
 	}
-	return false
+	matches := re.FindStringSubmatch(signed_locator)
+	if matches == nil {
+		// Could not find a permission signature at all
+		return false
+	}
+	blob_hash := matches[1]
+	sig_hex := matches[2]
+	exp_hex := matches[3]
+	if exp_time, err := ParseHexTimestamp(exp_hex); err != nil || exp_time.Before(time.Now()) {
+		// Signature is expired, or timestamp is unparseable
+		return false
+	}
+	return sig_hex == MakePermSignature(blob_hash, api_token, exp_hex)
 }
 
 func ParseHexTimestamp(timestamp_hex string) (ts time.Time, err error) {
diff --git a/services/keepstore/perms_test.go b/services/keepstore/perms_test.go
index d1c6b50..a2aa725 100644
--- a/services/keepstore/perms_test.go
+++ b/services/keepstore/perms_test.go
@@ -43,6 +43,25 @@ func TestVerifySignature(t *testing.T) {
 	}
 }
 
+func TestVerifySignatureExtraHints(t *testing.T) {
+	PermissionSecret = []byte(known_key)
+	defer func() { PermissionSecret = nil }()
+
+	sig_stuff := "+A" + known_signature + "@" + known_timestamp
+
+	if !VerifySignature(known_locator + "+K at xyzzy" + sig_stuff, known_token) {
+		t.Fatal("Verify cannot handle hint before permission signature")
+	}
+
+	if !VerifySignature(known_locator + sig_stuff + "+Zfoo", known_token) {
+		t.Fatal("Verify cannot handle hint after permission signature")
+	}
+
+	if !VerifySignature(known_locator + "+K at xyzzy" + sig_stuff + "+Zfoo", known_token) {
+		t.Fatal("Verify cannot handle hints around permission signature")
+	}
+}
+
 // The size hint on the locator string should not affect signature validation.
 func TestVerifySignatureWrongSize(t *testing.T) {
 	PermissionSecret = []byte(known_key)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list