make caveat nonces random (#1964)
This commit is contained in:
parent
15e74c8c3d
commit
791ec89c5e
@ -88,7 +88,11 @@ func shareMain(cmd *cobra.Command, args []string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
caveat := macaroon.NewCaveat()
|
||||
caveat, err := macaroon.NewCaveat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
caveat.DisallowDeletes = shareCfg.DisallowDeletes || shareCfg.Readonly
|
||||
caveat.DisallowLists = shareCfg.DisallowLists || shareCfg.Writeonly
|
||||
caveat.DisallowReads = shareCfg.DisallowReads || shareCfg.Writeonly
|
||||
|
@ -4,14 +4,13 @@
|
||||
package macaroon
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"time"
|
||||
"crypto/rand"
|
||||
)
|
||||
|
||||
// NewCaveat returns a Caveat with a nonce initialized to the current timestamp
|
||||
// in nanoseconds.
|
||||
func NewCaveat() Caveat {
|
||||
func NewCaveat() (Caveat, error) {
|
||||
var buf [8]byte
|
||||
binary.BigEndian.PutUint64(buf[:], uint64(time.Now().UnixNano()))
|
||||
return Caveat{Nonce: buf[:]}
|
||||
_, err := rand.Read(buf[:])
|
||||
return Caveat{Nonce: buf[:]}, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user