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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
4b91b6af
Commit
4b91b6af
authored
Mar 28, 2022
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Properly repopulate UD store after backup
parent
e56f1b60
No related branches found
No related tags found
3 merge requests
!233
Modify restore to call user-defined bindings callback. Add Sent requests to...
,
!231
Revert "Update store to print changes to the partners list"
,
!191
Properly repopulate UD store after backup
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/client.go
+23
-10
23 additions, 10 deletions
api/client.go
storage/ud/facts.go
+18
-1
18 additions, 1 deletion
storage/ud/facts.go
with
41 additions
and
11 deletions
api/client.go
+
23
−
10
View file @
4b91b6af
...
@@ -167,17 +167,19 @@ func NewVanityClient(ndfJSON, storageDir string, password []byte,
...
@@ -167,17 +167,19 @@ func NewVanityClient(ndfJSON, storageDir string, password []byte,
return
nil
return
nil
}
}
// NewClientFromBackup constructs a new Client from an encrypted backup. The backup
// NewClientFromBackup constructs a new Client from an encrypted backup.
// is decrypted using the backupPassphrase. On success a successful client creation,
// The backup is decrypted using the backupPassphrase. On success a
// the function will return a JSON encoded list of the E2E partners
// successful client creation, the function will return a JSON encoded
// contained in the backup and a json-encoded string containing parameters stored in the backup
// 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
,
func
NewClientFromBackup
(
ndfJSON
,
storageDir
string
,
sessionPassword
,
backupPassphrase
[]
byte
,
backupFileContents
[]
byte
)
([]
*
id
.
ID
,
string
,
error
)
{
backupPassphrase
[]
byte
,
backupFileContents
[]
byte
)
([]
*
id
.
ID
,
string
,
error
)
{
backUp
:=
&
backup
.
Backup
{}
backUp
:=
&
backup
.
Backup
{}
err
:=
backUp
.
Decrypt
(
string
(
backupPassphrase
),
backupFileContents
)
err
:=
backUp
.
Decrypt
(
string
(
backupPassphrase
),
backupFileContents
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
""
,
errors
.
WithMessage
(
err
,
"Failed to unmarshal decrypted client contents."
)
return
nil
,
""
,
errors
.
WithMessage
(
err
,
"Failed to "
+
"unmarshal decrypted client contents."
)
}
}
usr
:=
user
.
NewUserFromBackup
(
backUp
)
usr
:=
user
.
NewUserFromBackup
(
backUp
)
...
@@ -195,20 +197,31 @@ func NewClientFromBackup(ndfJSON, storageDir string, sessionPassword,
...
@@ -195,20 +197,31 @@ func NewClientFromBackup(ndfJSON, storageDir string, sessionPassword,
// Create storage object.
// Create storage object.
// Note we do not need registration
// Note we do not need registration
storageSess
,
err
:=
checkVersionAndSetupStorage
(
def
,
storageDir
,
[]
byte
(
sessionPassword
),
usr
,
storageSess
,
err
:=
checkVersionAndSetupStorage
(
def
,
storageDir
,
cmixGrp
,
e2eGrp
,
rngStreamGen
,
false
,
backUp
.
RegistrationCode
)
[]
byte
(
sessionPassword
),
usr
,
cmixGrp
,
e2eGrp
,
rngStreamGen
,
false
,
backUp
.
RegistrationCode
)
// Set registration values in storage
// Set registration values in storage
storageSess
.
User
()
.
SetReceptionRegistrationValidationSignature
(
backUp
.
ReceptionIdentity
.
RegistrarSignature
)
storageSess
.
User
()
.
SetReceptionRegistrationValidationSignature
(
backUp
.
storageSess
.
User
()
.
SetTransmissionRegistrationValidationSignature
(
backUp
.
TransmissionIdentity
.
RegistrarSignature
)
ReceptionIdentity
.
RegistrarSignature
)
storageSess
.
User
()
.
SetTransmissionRegistrationValidationSignature
(
backUp
.
TransmissionIdentity
.
RegistrarSignature
)
storageSess
.
User
()
.
SetRegistrationTimestamp
(
backUp
.
RegistrationTimestamp
)
storageSess
.
User
()
.
SetRegistrationTimestamp
(
backUp
.
RegistrationTimestamp
)
//move the registration state to indicate registered with registration on proto client
//move the registration state to indicate registered with registration
//on proto client
err
=
storageSess
.
ForwardRegistrationStatus
(
storage
.
PermissioningComplete
)
err
=
storageSess
.
ForwardRegistrationStatus
(
storage
.
PermissioningComplete
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
""
,
err
return
nil
,
""
,
err
}
}
err
=
storageSess
.
GetUd
()
.
RestoreFromBackUp
(
backUp
.
UserDiscoveryRegistration
.
FactList
)
if
err
!=
nil
{
return
nil
,
""
,
errors
.
WithMessage
(
err
,
"Could not restore user "
+
"discover storage"
)
}
return
backUp
.
Contacts
.
Identities
,
backUp
.
JSONParams
,
nil
return
backUp
.
Contacts
.
Identities
,
backUp
.
JSONParams
,
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
storage/ud/facts.go
+
18
−
1
View file @
4b91b6af
...
@@ -38,7 +38,6 @@ type Store struct {
...
@@ -38,7 +38,6 @@ type Store struct {
// NewStore creates a new, empty Store object.
// NewStore creates a new, empty Store object.
func
NewStore
(
kv
*
versioned
.
KV
)
(
*
Store
,
error
)
{
func
NewStore
(
kv
*
versioned
.
KV
)
(
*
Store
,
error
)
{
kv
=
kv
.
Prefix
(
prefix
)
kv
=
kv
.
Prefix
(
prefix
)
s
:=
&
Store
{
s
:=
&
Store
{
confirmedFacts
:
make
(
map
[
fact
.
Fact
]
struct
{},
0
),
confirmedFacts
:
make
(
map
[
fact
.
Fact
]
struct
{},
0
),
unconfirmedFacts
:
make
(
map
[
string
]
fact
.
Fact
,
0
),
unconfirmedFacts
:
make
(
map
[
string
]
fact
.
Fact
,
0
),
...
@@ -48,6 +47,24 @@ func NewStore(kv *versioned.KV) (*Store, error) {
...
@@ -48,6 +47,24 @@ func NewStore(kv *versioned.KV) (*Store, error) {
return
s
,
s
.
save
()
return
s
,
s
.
save
()
}
}
// RestoreFromBackUp initializes the confirmedFacts map
// with the backed up fact data. This will error if
// the store is already stateful.
func
(
s
*
Store
)
RestoreFromBackUp
(
backupData
fact
.
FactList
)
error
{
s
.
mux
.
Lock
()
defer
s
.
mux
.
Unlock
()
if
len
(
s
.
confirmedFacts
)
!=
0
||
len
(
s
.
unconfirmedFacts
)
!=
0
{
return
errors
.
New
(
"cannot overwrite ud store with existing data"
)
}
for
_
,
f
:=
range
backupData
{
s
.
confirmedFacts
[
f
]
=
struct
{}{}
}
return
nil
}
// StoreUnconfirmedFact stores a fact that has been added to UD but has not been
// StoreUnconfirmedFact stores a fact that has been added to UD but has not been
// confirmed by the user. It is keyed on the confirmation ID given by UD.
// confirmed by the user. It is keyed on the confirmation ID given by UD.
func
(
s
*
Store
)
StoreUnconfirmedFact
(
confirmationId
string
,
f
fact
.
Fact
)
error
{
func
(
s
*
Store
)
StoreUnconfirmedFact
(
confirmationId
string
,
f
fact
.
Fact
)
error
{
...
...
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