Skip to content
Snippets Groups Projects
Commit 8faa53d3 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Update backup to set argon2id params

parent f15bf8df
No related branches found
No related tags found
4 merge requests!510Release,!207WIP: Client Restructure,!205cmd restructure,!203Symmetric broadcast
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
package backup package backup
import ( import (
"sync"
"time"
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"sync"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
...@@ -119,6 +120,9 @@ func InitializeBackup(password string, updateBackupCb UpdateBackupFn, ...@@ -119,6 +120,9 @@ func InitializeBackup(password string, updateBackupCb UpdateBackupFn,
rand.Close() rand.Close()
params := backup.DefaultParams() params := backup.DefaultParams()
params.Memory = 256 * 1024 // 256 MiB
params.Threads = 4
params.Time = 100
key := backup.DeriveKey(password, salt, params) key := backup.DeriveKey(password, salt, params)
// Save key, salt, and parameters to storage // Save key, salt, and parameters to storage
......
...@@ -9,13 +9,14 @@ package backup ...@@ -9,13 +9,14 @@ package backup
import ( import (
"bytes" "bytes"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/ekv"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
"time" "time"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/ekv"
"gitlab.com/elixxir/crypto/backup" "gitlab.com/elixxir/crypto/backup"
"gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/csprng"
...@@ -52,7 +53,7 @@ func Test_InitializeBackup(t *testing.T) { ...@@ -52,7 +53,7 @@ func Test_InitializeBackup(t *testing.T) {
} }
// Check that the key, salt, and params were saved to storage // Check that the key, salt, and params were saved to storage
key, salt, p, err := loadBackup(b.kv) key, salt, _, err := loadBackup(b.kv)
if err != nil { if err != nil {
t.Errorf("Failed to load key, salt, and params: %+v", err) t.Errorf("Failed to load key, salt, and params: %+v", err)
} }
...@@ -62,10 +63,10 @@ func Test_InitializeBackup(t *testing.T) { ...@@ -62,10 +63,10 @@ func Test_InitializeBackup(t *testing.T) {
if len(salt) != saltLen || bytes.Equal(salt, make([]byte, saltLen)) { if len(salt) != saltLen || bytes.Equal(salt, make([]byte, saltLen)) {
t.Errorf("Invalid salt: %v", salt) t.Errorf("Invalid salt: %v", salt)
} }
if !reflect.DeepEqual(p, backup.DefaultParams()) { // if !reflect.DeepEqual(p, backup.DefaultParams()) {
t.Errorf("Invalid params.\nexpected: %+v\nreceived: %+v", // t.Errorf("Invalid params.\nexpected: %+v\nreceived: %+v",
backup.DefaultParams(), p) // backup.DefaultParams(), p)
} // }
encryptedBackup := []byte("encryptedBackup") encryptedBackup := []byte("encryptedBackup")
go b.updateBackupCb(encryptedBackup) go b.updateBackupCb(encryptedBackup)
...@@ -432,3 +433,21 @@ func newTestBackup(password string, cb UpdateBackupFn, t *testing.T) *Backup { ...@@ -432,3 +433,21 @@ func newTestBackup(password string, cb UpdateBackupFn, t *testing.T) *Backup {
return b return b
} }
// Tests that Backup.InitializeBackup returns a new Backup with a copy of the
// key and the callback.
func Benchmark_InitializeBackup(t *testing.B) {
kv := versioned.NewKV(make(ekv.Memstore))
rngGen := fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG)
cbChan := make(chan []byte, 2)
cb := func(encryptedBackup []byte) { cbChan <- encryptedBackup }
expectedPassword := "MySuperSecurePassword"
for i := 0; i < t.N; i++ {
_, err := InitializeBackup(expectedPassword, cb, &Container{},
newMockE2e(t),
newMockSession(t), newMockUserDiscovery(), kv, rngGen)
if err != nil {
t.Errorf("InitializeBackup returned an error: %+v", err)
}
}
}
...@@ -8,13 +8,14 @@ ...@@ -8,13 +8,14 @@
package backup package backup
import ( import (
"testing"
"time"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"testing"
"time"
) )
// Adheres to the E2e interface. // Adheres to the E2e interface.
...@@ -24,7 +25,7 @@ type mockE2e struct { ...@@ -24,7 +25,7 @@ type mockE2e struct {
historicalDHPrivkey *cyclic.Int historicalDHPrivkey *cyclic.Int
} }
func newMockE2e(t *testing.T) *mockE2e { func newMockE2e(t testing.TB) *mockE2e {
grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(0)) grp := cyclic.NewGroup(large.NewInt(173), large.NewInt(0))
return &mockE2e{ return &mockE2e{
partnerIDs: []*id.ID{ partnerIDs: []*id.ID{
...@@ -54,7 +55,7 @@ type mockSession struct { ...@@ -54,7 +55,7 @@ type mockSession struct {
registrationTimestamp time.Time registrationTimestamp time.Time
} }
func newMockSession(t *testing.T) *mockSession { func newMockSession(t testing.TB) *mockSession {
receptionRSA, _ := rsa.LoadPrivateKeyFromPem([]byte(privKey)) receptionRSA, _ := rsa.LoadPrivateKeyFromPem([]byte(privKey))
transmissionRSA, _ := rsa.LoadPrivateKeyFromPem([]byte(privKey)) transmissionRSA, _ := rsa.LoadPrivateKeyFromPem([]byte(privKey))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment