cmd/clef: fix incorrect file permissions for secrets.dat

Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
This commit is contained in:
YaoZengzeng 2018-09-12 15:11:35 +08:00
parent 2d98099c25
commit b040b75075

View File

@ -225,7 +225,7 @@ func initializeSecrets(c *cli.Context) error {
if _, err := os.Stat(location); err == nil { if _, err := os.Stat(location); err == nil {
return fmt.Errorf("file %v already exists, will not overwrite", location) return fmt.Errorf("file %v already exists, will not overwrite", location)
} }
err = ioutil.WriteFile(location, masterSeed, 0700) err = ioutil.WriteFile(location, masterSeed, 0400)
if err != nil { if err != nil {
return err return err
} }
@ -540,14 +540,14 @@ func readMasterKey(ctx *cli.Context) ([]byte, error) {
// checkFile is a convenience function to check if a file // checkFile is a convenience function to check if a file
// * exists // * exists
// * is mode 0600 // * is mode 0400
func checkFile(filename string) error { func checkFile(filename string) error {
info, err := os.Stat(filename) info, err := os.Stat(filename)
if err != nil { if err != nil {
return fmt.Errorf("failed stat on %s: %v", filename, err) return fmt.Errorf("failed stat on %s: %v", filename, err)
} }
// Check the unix permission bits // Check the unix permission bits
if info.Mode().Perm()&077 != 0 { if info.Mode().Perm()&0377 != 0 {
return fmt.Errorf("file (%v) has insecure file permissions (%v)", filename, info.Mode().String()) return fmt.Errorf("file (%v) has insecure file permissions (%v)", filename, info.Mode().String())
} }
return nil return nil