diff --git a/backup/backup.go b/backup/backup.go index 992968668b08cce3a8d9819bbc6991f738b1ce18..c6debb0888faf7f4499a060d16f2f1fae09a2082 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -90,7 +90,7 @@ type UpdateBackupFn func(encryptedBackup []byte) // new backups. // Call this to turn on backups for the first time or to replace the user's // password. -func InitializeBackup(password string, updateBackupCb UpdateBackupFn, +func InitializeBackup(backupPassphrase string, updateBackupCb UpdateBackupFn, container *xxdk.Container, e2e E2e, session Session, ud UserDiscovery, kv *versioned.KV, rng *fastRNG.StreamGenerator) (*Backup, error) { b := &Backup{ @@ -115,7 +115,7 @@ func InitializeBackup(password string, updateBackupCb UpdateBackupFn, params.Memory = 64 * 1024 // 64 MiB params.Threads = 1 params.Time = 5 - key := backup.DeriveKey(password, salt, params) + key := backup.DeriveKey(backupPassphrase, salt, params) // Save key, salt, and parameters to storage err = saveBackup(key, salt, params, b.kv) diff --git a/backup/backupRestore.go b/backup/backupRestore.go index be59b29f7cca22ce5d968afa2b41a28896129dd3..c0a4e3ecc37c5b2ba99816d0b05c297b70884e19 100644 --- a/backup/backupRestore.go +++ b/backup/backupRestore.go @@ -25,12 +25,12 @@ import ( // a successful client creation, the function will return a // JSON encoded list of the E2E partners contained in the backup and a // json-encoded string containing parameters stored in the backup -func NewCmixFromBackup(ndfJSON, storageDir string, sessionPassword, - backupPassphrase []byte, backupFileContents []byte) ([]*id.ID, +func NewCmixFromBackup(ndfJSON, storageDir, backupPassphrase string, + sessionPassword []byte, backupFileContents []byte) ([]*id.ID, string, error) { backUp := &cryptoBackup.Backup{} - err := backUp.Decrypt(string(backupPassphrase), backupFileContents) + err := backUp.Decrypt(backupPassphrase, backupFileContents) if err != nil { return nil, "", errors.WithMessage(err, "Failed to unmarshal decrypted client contents.") diff --git a/bindings/backup.go b/bindings/backup.go index dc45af9d4caa42e6f3da3796f3ccf2d84728c819..a6a083e23e84a72243c83f3f6949ad5f29b1c55a 100644 --- a/bindings/backup.go +++ b/bindings/backup.go @@ -32,7 +32,7 @@ type BackupReport struct { BackupIdListJson []byte // The backup parameters found within the backup file - BackupParams []byte + BackupParams string } // UpdateBackupFunc contains a function callback that returns new backups. @@ -57,13 +57,13 @@ type UpdateBackupFunc interface { // // Returns: // - []byte - the JSON marshalled bytes of the BackupReport object. -func NewCmixFromBackup(ndfJSON, storageDir string, sessionPassword, - backupPassphrase []byte, backupFileContents []byte) ([]byte, error) { +func NewCmixFromBackup(ndfJSON, storageDir, backupPassphrase string, + sessionPassword, backupFileContents []byte) ([]byte, error) { // Restore from backup - backupIdList, backupParamsStr, err := backup.NewCmixFromBackup( - ndfJSON, storageDir, sessionPassword, - backupPassphrase, backupFileContents) + backupIdList, backupParams, err := backup.NewCmixFromBackup( + ndfJSON, storageDir, backupPassphrase, sessionPassword, + backupFileContents) if err != nil { return nil, err } @@ -77,7 +77,7 @@ func NewCmixFromBackup(ndfJSON, storageDir string, sessionPassword, // Construct report report := BackupReport{ BackupIdListJson: backupIdListJson, - BackupParams: []byte(backupParamsStr), + BackupParams: backupParams, } // Marshal report @@ -94,9 +94,9 @@ func NewCmixFromBackup(ndfJSON, storageDir string, sessionPassword, // Params // - e2eID - ID of the E2e object in the e2e tracker. // - udID - ID of the UserDiscovery object in the ud tracker. -// - password - password used in LoadCmix. +// - backupPassPhrase - backup passphrase provided by the user. Used to decrypt backup. // - cb - the callback to be called when a backup is triggered. -func InitializeBackup(e2eID, udID int, password string, +func InitializeBackup(e2eID, udID int, backupPassPhrase string, cb UpdateBackupFunc) (*Backup, error) { // Retrieve the user from the tracker user, err := e2eTrackerSingleton.get(e2eID) @@ -111,7 +111,7 @@ func InitializeBackup(e2eID, udID int, password string, } // Initialize backup - b, err := backup.InitializeBackup(password, cb.UpdateBackup, + b, err := backup.InitializeBackup(backupPassPhrase, cb.UpdateBackup, user.api.GetBackupContainer(), user.api.GetE2E(), user.api.GetStorage(), ud.api, user.api.GetStorage().GetKV(), user.api.GetRng()) diff --git a/cmd/backup.go b/cmd/backup.go index 2499dacbff4e6a73b779da6ffd139baa4f1d5011..a102a56570c4cce0256de12d2c29f4d2d8814a14 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -51,7 +51,7 @@ func loadOrInitBackup(backupPath string, backupPass string, password []byte, sto // Construct cMix from backup data backupIdList, _, err := backup.NewCmixFromBackup(string(ndfJson), storeDir, - password, []byte(backupPass), backupFile) + backupPass, password, backupFile) if err != nil { jww.FATAL.Panicf("%+v", err) }