Skip to content

Commit

Permalink
Revert "audit: TOB-ACCB-009"
Browse files Browse the repository at this point in the history
This reverts commit fcb700d.
Because Windows system may have no right file mode.
  • Loading branch information
jowenshaw committed Jul 7, 2021
1 parent fa18192 commit 7203c41
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 32 deletions.
6 changes: 3 additions & 3 deletions cmd/swaptools/sendbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package main
import (
"encoding/hex"
"fmt"
"io/ioutil"
"strings"

"github.com/anyswap/CrossChain-Bridge/cmd/utils"
"github.com/anyswap/CrossChain-Bridge/common"
"github.com/anyswap/CrossChain-Bridge/log"
"github.com/anyswap/CrossChain-Bridge/tokens"
"github.com/anyswap/CrossChain-Bridge/tokens/btc"
"github.com/anyswap/CrossChain-Bridge/tools"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/base58"
Expand Down Expand Up @@ -143,13 +143,13 @@ func (bts *btcTxSender) initBridge() {
func (bts *btcTxSender) loadWIFForAddress() string {
var wifStr string
if bts.wifFile != "" {
wifdata, err := tools.SafeReadFile(bts.wifFile)
wifdata, err := ioutil.ReadFile(bts.wifFile)
if err != nil {
log.Fatal("Read WIF file failed", "err", err)
}
wifStr = strings.TrimSpace(string(wifdata))
} else {
pridata, err := tools.SafeReadFile(bts.priFile)
pridata, err := ioutil.ReadFile(bts.priFile)
if err != nil {
log.Fatal("Read private key file failed", "err", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/swaptools/sendltc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package main
import (
"encoding/hex"
"fmt"
"io/ioutil"
"strings"

"github.com/anyswap/CrossChain-Bridge/cmd/utils"
"github.com/anyswap/CrossChain-Bridge/common"
"github.com/anyswap/CrossChain-Bridge/log"
"github.com/anyswap/CrossChain-Bridge/tokens"
"github.com/anyswap/CrossChain-Bridge/tokens/ltc"
"github.com/anyswap/CrossChain-Bridge/tools"
"github.com/ltcsuite/ltcd/btcec"
"github.com/ltcsuite/ltcutil"
"github.com/ltcsuite/ltcutil/base58"
Expand Down Expand Up @@ -143,13 +143,13 @@ func (bts *ltcTxSender) initBridge() {
func (bts *ltcTxSender) loadWIFForAddress() string {
var wifStr string
if bts.wifFile != "" {
wifdata, err := tools.SafeReadFile(bts.wifFile)
wifdata, err := ioutil.ReadFile(bts.wifFile)
if err != nil {
log.Fatal("Read WIF file failed", "err", err)
}
wifStr = strings.TrimSpace(string(wifdata))
} else {
pridata, err := tools.SafeReadFile(bts.priFile)
pridata, err := ioutil.ReadFile(bts.priFile)
if err != nil {
log.Fatal("Read private key file failed", "err", err)
}
Expand Down
7 changes: 0 additions & 7 deletions tools/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error) {
// LoadECDSA loads a secp256k1 private key from the given file.
func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
buf := make([]byte, 64)
fi, err := os.Stat(file)
if err != nil {
return nil, err
}
if fi.Mode() != 0400 {
return nil, errors.New("unsafe file permissions, want 0400")
}
fd, err := os.Open(file)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion tools/crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestLoadECDSAFile(t *testing.T) {
}
}

_ = ioutil.WriteFile(fileName0, []byte(testPrivHex), 0400)
_ = ioutil.WriteFile(fileName0, []byte(testPrivHex), 0600)
defer os.Remove(fileName0)

key0, err := LoadECDSA(fileName0)
Expand Down
20 changes: 2 additions & 18 deletions tools/loadkeystore.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,20 @@
package tools

import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/anyswap/CrossChain-Bridge/tools/keystore"
)

var errUnsafeFilePermissions = errors.New("unsafe file permissions, want 0400")

// SafeReadFile check permissions is '0400' and read file
func SafeReadFile(file string) ([]byte, error) {
fi, err := os.Stat(file)
if err != nil {
return nil, err
}
if fi.Mode() != 0400 {
return nil, errUnsafeFilePermissions
}
return ioutil.ReadFile(file)
}

// LoadKeyStore load keystore from keyfile and passfile
func LoadKeyStore(keyfile, passfile string) (*keystore.Key, error) {
keyjson, err := SafeReadFile(keyfile)
keyjson, err := ioutil.ReadFile(keyfile)
if err != nil {
return nil, fmt.Errorf("read keystore fail %w", err)
}
passdata, err := SafeReadFile(passfile)
passdata, err := ioutil.ReadFile(passfile)
if err != nil {
return nil, fmt.Errorf("read password fail %w", err)
}
Expand Down

0 comments on commit 7203c41

Please sign in to comment.