Change ioutil -> os APIs
This commit is contained in:
parent
5765cfd6c4
commit
79bf060c2f
|
@ -11,7 +11,6 @@ import (
|
|||
"cwtch.im/cwtch/storage"
|
||||
"git.openprivacy.ca/openprivacy/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
path "path/filepath"
|
||||
"strconv"
|
||||
|
@ -140,7 +139,7 @@ func (app *application) LoadProfiles(password string) {
|
|||
count := 0
|
||||
migrating := false
|
||||
|
||||
files, err := ioutil.ReadDir(path.Join(app.directory, "profiles"))
|
||||
files, err := os.ReadDir(path.Join(app.directory, "profiles"))
|
||||
if err != nil {
|
||||
log.Errorf("error: cannot read profiles directory: %v", err)
|
||||
return
|
||||
|
|
|
@ -121,7 +121,6 @@ func (nc *networkCheck) selfTest() {
|
|||
go nc.checkConnection(nc.onion)
|
||||
}
|
||||
|
||||
//
|
||||
func (nc *networkCheck) checkConnection(onion string) {
|
||||
prog, _ := nc.acn.GetBootstrapStatus()
|
||||
if prog != 100 {
|
||||
|
|
|
@ -91,7 +91,7 @@ func (g *Group) Invite() (string, error) {
|
|||
return serializedInvite, err
|
||||
}
|
||||
|
||||
//EncryptMessage takes a message and encrypts the message under the group key.
|
||||
// EncryptMessage takes a message and encrypts the message under the group key.
|
||||
func (g *Group) EncryptMessage(message *groups.DecryptedGroupMessage) ([]byte, error) {
|
||||
var nonce [24]byte
|
||||
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
|
||||
|
@ -210,11 +210,12 @@ func (g *Group) AttemptDecryption(ciphertext []byte, signature []byte) (bool, *g
|
|||
|
||||
// VerifyGroupMessage confirms the authenticity of a message given an sender onion, message and signature.
|
||||
// The goal of this function is 2-fold:
|
||||
// 1. We confirm that the sender referenced in the group text is the actual sender of the message (or at least
|
||||
// 1. We confirm that the sender referenced in the group text is the actual sender of the message (or at least
|
||||
// knows the senders private key)
|
||||
// 2. Secondly, we confirm that the sender sent the message to a particular group id on a specific server (it doesn't
|
||||
// matter if we actually received this message from the server or from a hybrid protocol, all that matters is
|
||||
// that the sender and receivers agree that this message was intended for the group
|
||||
// 2. Secondly, we confirm that the sender sent the message to a particular group id on a specific server (it doesn't
|
||||
// matter if we actually received this message from the server or from a hybrid protocol, all that matters is
|
||||
// that the sender and receivers agree that this message was intended for the group
|
||||
//
|
||||
// The 2nd point is important as it prevents an attack documented in the original Cwtch paper (and later at
|
||||
// https://docs.openprivacy.ca/cwtch-security-handbook/groups.html) in which a malicious profile sets up 2 groups
|
||||
// on two different servers with the same key and then forwards messages between them to convince the parties in
|
||||
|
|
|
@ -99,7 +99,7 @@ func (t *Timeline) SetMessages(messages []Message) {
|
|||
|
||||
// GetMessagesByHash attempts to find messages that match the given
|
||||
// content hash in the timeline. If successful it returns a list of messages as well as their local index
|
||||
//, on failure it returns an error.
|
||||
// , on failure it returns an error.
|
||||
// We return a list of messages because content hashes are not guaranteed to be unique from a given Peer. This allows
|
||||
// us to do things like: ensure that reply-to and quotes reference the last seen message from the message they are quoted
|
||||
// in or detect duplicate messages from a peer.
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"io/ioutil"
|
||||
"math/bits"
|
||||
"os"
|
||||
path "path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
@ -40,7 +40,8 @@ var autoHandleableEvents = map[event.Type]bool{event.EncryptedGroupMessage: true
|
|||
event.ManifestSizeReceived: true, event.ManifestReceived: true, event.FileDownloaded: true}
|
||||
|
||||
// DefaultEventsToHandle specifies which events will be subscribed to
|
||||
// when a peer has its Init() function called
|
||||
//
|
||||
// when a peer has its Init() function called
|
||||
var DefaultEventsToHandle = []event.Type{
|
||||
event.EncryptedGroupMessage,
|
||||
event.NewMessageFromPeerEngine,
|
||||
|
@ -108,7 +109,7 @@ func (cp *cwtchPeer) ChangePassword(password string, newpassword string, newpass
|
|||
}
|
||||
cps.Close()
|
||||
|
||||
salt, err := ioutil.ReadFile(path.Join(cp.storage.ProfileDirectory, saltFile))
|
||||
salt, err := os.ReadFile(path.Join(cp.storage.ProfileDirectory, saltFile))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
"golang.org/x/crypto/pbkdf2"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -56,12 +55,12 @@ func initV2Directory(directory, password string) ([32]byte, [128]byte, error) {
|
|||
return [32]byte{}, [128]byte{}, err
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(path.Join(directory, versionFile), []byte(version), 0600); err != nil {
|
||||
if err = os.WriteFile(path.Join(directory, versionFile), []byte(version), 0600); err != nil {
|
||||
log.Errorf("Could not write version file: %v", err)
|
||||
return [32]byte{}, [128]byte{}, err
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(path.Join(directory, saltFile), salt[:], 0600); err != nil {
|
||||
if err = os.WriteFile(path.Join(directory, saltFile), salt[:], 0600); err != nil {
|
||||
log.Errorf("Could not write salt file: %v", err)
|
||||
return [32]byte{}, [128]byte{}, err
|
||||
}
|
||||
|
@ -70,7 +69,7 @@ func initV2Directory(directory, password string) ([32]byte, [128]byte, error) {
|
|||
}
|
||||
|
||||
func openEncryptedDatabase(profileDirectory string, password string, createIfNotExists bool) (*sql.DB, error) {
|
||||
salt, err := ioutil.ReadFile(path.Join(profileDirectory, saltFile))
|
||||
salt, err := os.ReadFile(path.Join(profileDirectory, saltFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
@ -122,7 +121,7 @@ func (m *Manifest) GetChunkBytes(id uint64) ([]byte, error) {
|
|||
|
||||
// LoadManifest reads in a json serialized Manifest from a file
|
||||
func LoadManifest(filename string) (*Manifest, error) {
|
||||
bytes, err := ioutil.ReadFile(filename)
|
||||
bytes, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -319,7 +318,7 @@ func (m *Manifest) Close() {
|
|||
|
||||
// Save writes a JSON encoded byte array version of the manifest to path
|
||||
func (m *Manifest) Save(path string) error {
|
||||
return ioutil.WriteFile(path, m.Serialize(), 0600)
|
||||
return os.WriteFile(path, m.Serialize(), 0600)
|
||||
}
|
||||
|
||||
// Serialize returns the manifest as a JSON encoded byte array
|
||||
|
|
|
@ -3,8 +3,8 @@ package files
|
|||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -77,7 +77,7 @@ func TestManifestLarge(t *testing.T) {
|
|||
t.Logf("%v %s", len(json), json)
|
||||
|
||||
// Pretend we downloaded the manifest
|
||||
ioutil.WriteFile("testdata/cwtch.png.manifest", json, 0600)
|
||||
os.WriteFile("testdata/cwtch.png.manifest", json, 0600)
|
||||
|
||||
// Load the manifest from a file
|
||||
cwtchPngManifest, err := LoadManifest("testdata/cwtch.png.manifest")
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"golang.org/x/crypto/pbkdf2"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
path "path/filepath"
|
||||
)
|
||||
|
||||
|
@ -35,7 +35,7 @@ func CreateKey(password string, salt []byte) [32]byte {
|
|||
return dkr
|
||||
}
|
||||
|
||||
//EncryptFileData encrypts the data with the supplied key
|
||||
// EncryptFileData encrypts the data with the supplied key
|
||||
func EncryptFileData(data []byte, key [32]byte) ([]byte, error) {
|
||||
var nonce [24]byte
|
||||
|
||||
|
@ -48,7 +48,7 @@ func EncryptFileData(data []byte, key [32]byte) ([]byte, error) {
|
|||
return encrypted, nil
|
||||
}
|
||||
|
||||
//DecryptFile decrypts the passed ciphertext with the supplied key.
|
||||
// DecryptFile decrypts the passed ciphertext with the supplied key.
|
||||
func DecryptFile(ciphertext []byte, key [32]byte) ([]byte, error) {
|
||||
var decryptNonce [24]byte
|
||||
copy(decryptNonce[:], ciphertext[:24])
|
||||
|
@ -61,7 +61,7 @@ func DecryptFile(ciphertext []byte, key [32]byte) ([]byte, error) {
|
|||
|
||||
// ReadEncryptedFile reads data from an encrypted file in directory with key
|
||||
func ReadEncryptedFile(directory, filename string, key [32]byte) ([]byte, error) {
|
||||
encryptedbytes, err := ioutil.ReadFile(path.Join(directory, filename))
|
||||
encryptedbytes, err := os.ReadFile(path.Join(directory, filename))
|
||||
if err == nil {
|
||||
return DecryptFile(encryptedbytes, key)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package v1
|
|||
|
||||
import (
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
@ -38,7 +37,7 @@ func (fps *fileStore) Write(data []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(path.Join(fps.directory, fps.filename), encryptedbytes, 0600)
|
||||
err = os.WriteFile(path.Join(fps.directory, fps.filename), encryptedbytes, 0600)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"cwtch.im/cwtch/model"
|
||||
"encoding/json"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
const profileFilename = "profile"
|
||||
const saltFile = "SALT"
|
||||
|
||||
//ProfileStoreV1 storage for profiles and message streams that uses in memory key and fs stored salt instead of in memory password
|
||||
// ProfileStoreV1 storage for profiles and message streams that uses in memory key and fs stored salt instead of in memory password
|
||||
type ProfileStoreV1 struct {
|
||||
fs FileStore
|
||||
directory string
|
||||
|
@ -24,7 +24,7 @@ type ProfileStoreV1 struct {
|
|||
// LoadProfileWriterStore loads a profile store from filestore listening for events and saving them
|
||||
// directory should be $appDir/profiles/$rand
|
||||
func LoadProfileWriterStore(directory, password string) (*ProfileStoreV1, error) {
|
||||
salt, err := ioutil.ReadFile(path.Join(directory, saltFile))
|
||||
salt, err := os.ReadFile(path.Join(directory, saltFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -93,7 +92,7 @@ func (ss *streamStore) updateFile() error {
|
|||
return err
|
||||
}
|
||||
|
||||
ioutil.WriteFile(path.Join(ss.storeDirectory, fmt.Sprintf("%s.%d", ss.filenameBase, 0)), encryptedMsgs, 0600)
|
||||
os.WriteFile(path.Join(ss.storeDirectory, fmt.Sprintf("%s.%d", ss.filenameBase, 0)), encryptedMsgs, 0600)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
_ "github.com/mutecomm/go-sqlcipher/v4"
|
||||
"io/ioutil"
|
||||
mrand "math/rand"
|
||||
"os"
|
||||
"os/user"
|
||||
|
@ -80,7 +79,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
}
|
||||
|
||||
torDataDir := ""
|
||||
if torDataDir, err = ioutil.TempDir(dataDir, "data-dir-"); err != nil {
|
||||
if torDataDir, err = os.MkdirTemp(dataDir, "data-dir-"); err != nil {
|
||||
t.Fatalf("could not create data dir")
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
_ "github.com/mutecomm/go-sqlcipher/v4"
|
||||
"io/ioutil"
|
||||
mrand "math/rand"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -42,7 +41,7 @@ func TestEncryptedStorage(t *testing.T) {
|
|||
}
|
||||
|
||||
torDataDir := ""
|
||||
if torDataDir, err = ioutil.TempDir(dataDir, "data-dir-"); err != nil {
|
||||
if torDataDir, err = os.MkdirTemp(dataDir, "data-dir-"); err != nil {
|
||||
t.Fatalf("could not create data dir")
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,6 @@ package filesharing
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
utils2 "cwtch.im/cwtch/utils"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
app2 "cwtch.im/cwtch/app"
|
||||
"cwtch.im/cwtch/event"
|
||||
"cwtch.im/cwtch/functionality/filesharing"
|
||||
|
@ -18,6 +11,11 @@ import (
|
|||
"cwtch.im/cwtch/peer"
|
||||
"cwtch.im/cwtch/protocol/connections"
|
||||
"cwtch.im/cwtch/protocol/files"
|
||||
utils2 "cwtch.im/cwtch/utils"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
|
||||
|
@ -77,7 +75,7 @@ func TestFileSharing(t *testing.T) {
|
|||
}
|
||||
|
||||
torDataDir := ""
|
||||
if torDataDir, err = ioutil.TempDir(dataDir, "data-dir-"); err != nil {
|
||||
if torDataDir, err = os.MkdirTemp(dataDir, "data-dir-"); err != nil {
|
||||
t.Fatalf("could not create data dir")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue