Add individual key derivation for trees

This commit is contained in:
mcrakhman 2023-03-27 13:01:35 +02:00
parent 503c4f339f
commit 3d017d1e0c
No known key found for this signature in database
GPG Key ID: DED12CFEF5B8396B
4 changed files with 24 additions and 2 deletions

View File

@ -45,7 +45,11 @@ func (h *historyTree) rebuildFromStorage(beforeId string, include bool) (err err
if len(ot.keys) != len(state.UserReadKeys()) {
for key, value := range state.UserReadKeys() {
ot.keys[key] = value
treeKey, err := deriveTreeKey(value, h.id)
if err != nil {
return err
}
ot.keys[key] = treeKey
}
}
return

View File

@ -640,7 +640,11 @@ func (ot *objectTree) validateTree(newChanges []*Change) error {
// just not to take lock many times, updating the key map from aclList
if len(ot.keys) != len(state.UserReadKeys()) {
for key, value := range state.UserReadKeys() {
ot.keys[key] = value
treeKey, err := deriveTreeKey(value, ot.id)
if err != nil {
return err
}
ot.keys[key] = treeKey
}
}
if len(newChanges) == 0 {

View File

@ -1,5 +1,10 @@
package objecttree
import (
"fmt"
"github.com/anytypeio/any-sync/util/crypto"
)
func commonSnapshotForTwoPaths(ourPath []string, theirPath []string) (string, error) {
var i int
var j int
@ -27,3 +32,11 @@ OuterLoop:
}
return ourPath[i+1], nil
}
func deriveTreeKey(key crypto.SymKey, cid string) (crypto.SymKey, error) {
raw, err := key.Raw()
if err != nil {
return nil, err
}
return crypto.DeriveSymmetricKey(raw, fmt.Sprintf(crypto.AnysyncTreePath, cid))
}

View File

@ -6,6 +6,7 @@ import (
const (
AnytypeAccountPath = "m/SLIP-0021/anytype/account"
AnysyncTreePath = "m/SLIP-0021/anysync/tree/%s"
AnytypeAccountPrefix = "m/44'/607'"
)