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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
caveat := macaroon.NewCaveat()
|
caveat, err := macaroon.NewCaveat()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
caveat.DisallowDeletes = shareCfg.DisallowDeletes || shareCfg.Readonly
|
caveat.DisallowDeletes = shareCfg.DisallowDeletes || shareCfg.Readonly
|
||||||
caveat.DisallowLists = shareCfg.DisallowLists || shareCfg.Writeonly
|
caveat.DisallowLists = shareCfg.DisallowLists || shareCfg.Writeonly
|
||||||
caveat.DisallowReads = shareCfg.DisallowReads || shareCfg.Writeonly
|
caveat.DisallowReads = shareCfg.DisallowReads || shareCfg.Writeonly
|
||||||
|
@ -4,14 +4,13 @@
|
|||||||
package macaroon
|
package macaroon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"crypto/rand"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCaveat returns a Caveat with a nonce initialized to the current timestamp
|
// NewCaveat returns a Caveat with a nonce initialized to the current timestamp
|
||||||
// in nanoseconds.
|
// in nanoseconds.
|
||||||
func NewCaveat() Caveat {
|
func NewCaveat() (Caveat, error) {
|
||||||
var buf [8]byte
|
var buf [8]byte
|
||||||
binary.BigEndian.PutUint64(buf[:], uint64(time.Now().UnixNano()))
|
_, err := rand.Read(buf[:])
|
||||||
return Caveat{Nonce: buf[:]}
|
return Caveat{Nonce: buf[:]}, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user