Merge branch 'master' into 7454-azure-custom-data
[arvados.git] / services / keepstore / perms.go
1 package main
2
3 import (
4         "git.curoverse.com/arvados.git/sdk/go/keepclient"
5         "time"
6 )
7
8 // The PermissionSecret is the secret key used to generate SHA1
9 // digests for permission hints. apiserver and Keep must use the same
10 // key.
11 var PermissionSecret []byte
12
13 // SignLocator takes a blobLocator, an apiToken and an expiry time, and
14 // returns a signed locator string.
15 func SignLocator(blobLocator, apiToken string, expiry time.Time) string {
16         return keepclient.SignLocator(blobLocator, apiToken, expiry, PermissionSecret)
17 }
18
19 // VerifySignature returns nil if the signature on the signedLocator
20 // can be verified using the given apiToken. Otherwise it returns
21 // either ExpiredError (if the timestamp has expired, which is
22 // something the client could have figured out independently) or
23 // PermissionError.
24 func VerifySignature(signedLocator, apiToken string) error {
25         err := keepclient.VerifySignature(signedLocator, apiToken, PermissionSecret)
26         if err == keepclient.ErrSignatureExpired {
27                 return ExpiredError
28         } else if err != nil {
29                 return PermissionError
30         }
31         return nil
32 }