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/cmd/backup.go b/cmd/backup.go index 2499dacbff4e6a73b779da6ffd139baa4f1d5011..f13bbc16c34ee485aad2bafd1f8a97faa6c18d2e 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -21,6 +21,14 @@ import ( "gitlab.com/xx_network/primitives/utils" ) +type BackupReport struct { + // The JSON encoded list of E2E partner IDs + BackupIdListJson []byte + + // The backup parameters found within the backup file + BackupParams []byte +} + // loadOrInitBackup will build a new xxdk.E2e from existing storage // or from a new storage that it will create if none already exists func loadOrInitBackup(backupPath string, backupPass string, password []byte, storeDir string, @@ -50,12 +58,35 @@ 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) + backupIdList, backupParams, err := backup.NewCmixFromBackup(string(ndfJson), storeDir, + backupPass, password, backupFile) if err != nil { jww.FATAL.Panicf("%+v", err) } + backupIdListJson, err := json.Marshal(backupIdList) + if err != nil { + jww.FATAL.Panicf("Failed to marshal backup ID: %v", err) + } + + buReport := BackupReport{ + BackupIdListJson: backupIdListJson, + BackupParams: []byte(backupParams), + } + + jww.INFO.Printf("") + jww.INFO.Printf("backup Report obj: %v", buReport) + + reportJson, err := json.Marshal(buReport) + if err != nil { + jww.FATAL.Panicf("Failed to marshal backup report: %v", err) + } + + jww.INFO.Printf("backupIdList: %v\n"+ + "backupParams: %s\n"+ + "backup Report obj: %v\n"+ + "backup report: \n%s", backupIdList, backupParams, buReport, string(reportJson)) + backupIdListPath := viper.GetString(backupIdListFlag) if backupIdListPath != "" { // Marshal backed up ID list to JSON