Skip to content

Commit 8b77fe3

Browse files
committed
fix(cli): fix CLI paths and perms on windows
1 parent 02cd731 commit 8b77fe3

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

cli/internal/utils/utils.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/erikgeiser/promptkit/confirmation"
3636
"github.com/ethereum/go-ethereum/common/hexutil"
3737
"github.com/ethereum/go-ethereum/crypto"
38+
"go.uber.org/zap"
3839
)
3940

4041
// BoolToYN converts a boolean to "yes" or "no".
@@ -123,7 +124,7 @@ func GetPrivateKey(ethHexPK, orPath string) (*ecdsa.PrivateKey, error) {
123124
if err != nil {
124125
return pk, err
125126
}
126-
orPath = filepath.Join(home, "/.dps/key")
127+
orPath = filepath.Join(home, ".dps", "key")
127128
}
128129

129130
finfo, err := os.Stat(orPath)
@@ -171,13 +172,22 @@ func GetPrivateKey(ethHexPK, orPath string) (*ecdsa.PrivateKey, error) {
171172
} else if err != nil {
172173
return nil, err
173174
}
174-
if !(finfo.Mode()&0700 > 0 && (finfo.Mode()&0070 == 0) && (finfo.Mode()&0007 == 0)) {
175-
internallog.I.Sugar().Errorf(
176-
"Permission of %s is insecure! Please `chmod 600 %s`.\n",
177-
orPath,
178-
orPath,
179-
)
180-
return nil, errors.New("insecure file permission")
175+
// Check os is not windows
176+
if os.PathSeparator != '\\' {
177+
if !(finfo.Mode()&0700 > 0 && (finfo.Mode()&0070 == 0) && (finfo.Mode()&0007 == 0)) {
178+
if err := os.Chmod(orPath, 0600); err != nil {
179+
internallog.I.Error("Couldn't chmod to read-only.", zap.Error(err))
180+
internallog.I.Sugar().Errorf(
181+
"Permission of %s is insecure! Please `chmod 600 %s`.\n",
182+
orPath,
183+
orPath,
184+
)
185+
}
186+
187+
return nil, errors.New("insecure file permission")
188+
}
189+
} else {
190+
internallog.I.Sugar().Warnf("You are running on Windows. Please make sure the file permission of %s is secure.\n", orPath)
181191
}
182192
b, err := os.ReadFile(orPath)
183193
if err != nil {

0 commit comments

Comments
 (0)