Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
74b2ce10
Commit
74b2ce10
authored
2 years ago
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Add NewClientFromBackup to messenger
parent
b73aabf6
No related branches found
No related tags found
3 merge requests
!510
Release
,
!226
WIP: Api2.0
,
!207
WIP: Client Restructure
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/messenger/backupRestore.go
+90
-0
90 additions, 0 deletions
api/messenger/backupRestore.go
with
90 additions
and
0 deletions
api/messenger/backupRestore.go
0 → 100644
+
90
−
0
View file @
74b2ce10
// FIXME: This is placeholder, there's got to be a better place to put
// backup restoration than inside messenger.
package
messenger
import
(
"github.com/pkg/errors"
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/rekey"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/storage/user"
"gitlab.com/elixxir/client/ud"
cryptoBackup
"gitlab.com/elixxir/crypto/backup"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/primitives/id"
)
// NewClientFromBackup constructs a new Client from an encrypted
// backup. The backup is decrypted using the backupPassphrase. On
// success 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
NewClientFromBackup
(
ndfJSON
,
storageDir
string
,
sessionPassword
,
backupPassphrase
[]
byte
,
backupFileContents
[]
byte
)
([]
*
id
.
ID
,
string
,
error
)
{
backUp
:=
&
cryptoBackup
.
Backup
{}
err
:=
backUp
.
Decrypt
(
string
(
backupPassphrase
),
backupFileContents
)
if
err
!=
nil
{
return
nil
,
""
,
errors
.
WithMessage
(
err
,
"Failed to unmarshal decrypted client contents."
)
}
usr
:=
user
.
NewUserFromBackup
(
backUp
)
def
,
err
:=
api
.
ParseNDF
(
ndfJSON
)
if
err
!=
nil
{
return
nil
,
""
,
err
}
cmixGrp
,
e2eGrp
:=
api
.
DecodeGroups
(
def
)
// Note we do not need registration here
storageSess
,
err
:=
api
.
CheckVersionAndSetupStorage
(
def
,
storageDir
,
[]
byte
(
sessionPassword
),
usr
,
cmixGrp
,
e2eGrp
,
backUp
.
RegistrationCode
)
if
err
!=
nil
{
return
nil
,
""
,
err
}
storageSess
.
SetReceptionRegistrationValidationSignature
(
backUp
.
ReceptionIdentity
.
RegistrarSignature
)
storageSess
.
SetTransmissionRegistrationValidationSignature
(
backUp
.
TransmissionIdentity
.
RegistrarSignature
)
storageSess
.
SetRegistrationTimestamp
(
backUp
.
RegistrationTimestamp
)
//move the registration state to indicate registered with
// registration on proto client
err
=
storageSess
.
ForwardRegistrationStatus
(
storage
.
PermissioningComplete
)
if
err
!=
nil
{
return
nil
,
""
,
err
}
privkey
:=
usr
.
E2eDhPrivateKey
//initialize the e2e storage
err
=
e2e
.
Init
(
storageSess
.
GetKV
(),
usr
.
ReceptionID
,
privkey
,
e2eGrp
,
rekey
.
GetDefaultParams
())
if
err
!=
nil
{
return
nil
,
""
,
err
}
udInfo
:=
backUp
.
UserDiscoveryRegistration
var
username
,
email
,
phone
fact
.
Fact
for
_
,
f
:=
range
udInfo
.
FactList
{
switch
f
.
T
{
case
fact
.
Email
:
email
=
f
case
fact
.
Username
:
username
=
f
case
fact
.
Phone
:
phone
=
f
}
}
ud
.
InitStoreFromBackup
(
storageSess
.
GetKV
(),
username
,
email
,
phone
)
return
backUp
.
Contacts
.
Identities
,
backUp
.
JSONParams
,
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment