From 178159b0c5ed73f6b296547a2e36d88b56668742 Mon Sep 17 00:00:00 2001 From: Dmitry Bilienko Date: Tue, 28 Mar 2023 16:25:36 +0800 Subject: [PATCH 1/7] Cache | Reduce RAM --- commonspace/object/tree/objecttree/treebuilder.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commonspace/object/tree/objecttree/treebuilder.go b/commonspace/object/tree/objecttree/treebuilder.go index edaa3ede..dd5d8622 100644 --- a/commonspace/object/tree/objecttree/treebuilder.go +++ b/commonspace/object/tree/objecttree/treebuilder.go @@ -50,6 +50,10 @@ func (tb *treeBuilder) Build(theirHeads []string, newChanges []*Change) (*Tree, } func (tb *treeBuilder) build(heads []string, theirHeads []string, newChanges []*Change) (*Tree, error) { + defer func() { + tb.cache = make(map[string]*Change) + }() + var proposedHeads []string tb.cache = make(map[string]*Change) From 20a4d85836d2d9e694fbd27b912422a594481566 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Sun, 2 Apr 2023 18:13:10 +0200 Subject: [PATCH 2/7] Update cryptography and add master key --- commonspace/object/accountdata/accountdata.go | 27 +- .../object/acl/aclrecordproto/aclrecord.pb.go | 266 +++++++++++------- .../acl/aclrecordproto/protos/aclrecord.proto | 7 +- .../object/acl/list/aclrecordbuilder.go | 35 +-- commonspace/object/acl/list/aclstate.go | 15 +- commonspace/object/acl/list/listutils.go | 6 +- commonspace/payloads.go | 7 +- commonspace/space.go | 3 + util/crypto/cryptoproto/crypto.pb.go | 249 +--------------- util/crypto/cryptoproto/protos/crypto.proto | 9 - util/crypto/derived.go | 5 +- util/crypto/derived_test.go | 2 +- util/crypto/mnemonic.go | 76 ++++- util/crypto/mnemonic_test.go | 26 +- 14 files changed, 308 insertions(+), 425 deletions(-) diff --git a/commonspace/object/accountdata/accountdata.go b/commonspace/object/accountdata/accountdata.go index 279a6cbd..5cbd8ab3 100644 --- a/commonspace/object/accountdata/accountdata.go +++ b/commonspace/object/accountdata/accountdata.go @@ -6,16 +6,18 @@ import ( ) type AccountKeys struct { - PeerKey crypto.PrivKey - SignKey crypto.PrivKey - PeerId string + PeerKey crypto.PrivKey + SignKey crypto.PrivKey + MasterKey crypto.PrivKey + PeerId string } -func New(peerKey crypto.PrivKey, signKey crypto.PrivKey) *AccountKeys { +func New(peerKey, signKey, masterKey crypto.PrivKey) *AccountKeys { return &AccountKeys{ - PeerKey: peerKey, - SignKey: signKey, - PeerId: peerKey.GetPublic().PeerId(), + PeerKey: peerKey, + SignKey: signKey, + MasterKey: masterKey, + PeerId: peerKey.GetPublic().PeerId(), } } @@ -28,9 +30,14 @@ func NewRandom() (*AccountKeys, error) { if err != nil { return nil, err } + masterKey, _, err := crypto.GenerateEd25519Key(rand.Reader) + if err != nil { + return nil, err + } return &AccountKeys{ - PeerKey: peerKey, - SignKey: signKey, - PeerId: peerKey.GetPublic().PeerId(), + PeerKey: peerKey, + SignKey: signKey, + MasterKey: masterKey, + PeerId: peerKey.GetPublic().PeerId(), }, nil } diff --git a/commonspace/object/acl/aclrecordproto/aclrecord.pb.go b/commonspace/object/acl/aclrecordproto/aclrecord.pb.go index c00b712f..6842e829 100644 --- a/commonspace/object/acl/aclrecordproto/aclrecord.pb.go +++ b/commonspace/object/acl/aclrecordproto/aclrecord.pb.go @@ -247,11 +247,12 @@ func (m *AclRecord) GetTimestamp() int64 { } type AclRoot struct { - Identity []byte `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` - SpaceId string `protobuf:"bytes,2,opt,name=spaceId,proto3" json:"spaceId,omitempty"` - EncryptedReadKey []byte `protobuf:"bytes,3,opt,name=encryptedReadKey,proto3" json:"encryptedReadKey,omitempty"` - DerivationParams []byte `protobuf:"bytes,4,opt,name=derivationParams,proto3" json:"derivationParams,omitempty"` - Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Identity []byte `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` + MasterKey []byte `protobuf:"bytes,2,opt,name=masterKey,proto3" json:"masterKey,omitempty"` + SpaceId string `protobuf:"bytes,3,opt,name=spaceId,proto3" json:"spaceId,omitempty"` + EncryptedReadKey []byte `protobuf:"bytes,4,opt,name=encryptedReadKey,proto3" json:"encryptedReadKey,omitempty"` + Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + IdentitySignature []byte `protobuf:"bytes,6,opt,name=identitySignature,proto3" json:"identitySignature,omitempty"` } func (m *AclRoot) Reset() { *m = AclRoot{} } @@ -294,6 +295,13 @@ func (m *AclRoot) GetIdentity() []byte { return nil } +func (m *AclRoot) GetMasterKey() []byte { + if m != nil { + return m.MasterKey + } + return nil +} + func (m *AclRoot) GetSpaceId() string { if m != nil { return m.SpaceId @@ -308,13 +316,6 @@ func (m *AclRoot) GetEncryptedReadKey() []byte { return nil } -func (m *AclRoot) GetDerivationParams() []byte { - if m != nil { - return m.DerivationParams - } - return nil -} - func (m *AclRoot) GetTimestamp() int64 { if m != nil { return m.Timestamp @@ -322,6 +323,13 @@ func (m *AclRoot) GetTimestamp() int64 { return 0 } +func (m *AclRoot) GetIdentitySignature() []byte { + if m != nil { + return m.IdentitySignature + } + return nil +} + type AclContentValue struct { // Types that are valid to be assigned to Value: // @@ -1136,64 +1144,65 @@ func init() { } var fileDescriptor_c8e9f754f34e929b = []byte{ - // 907 bytes of a gzipped FileDescriptorProto + // 914 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xf7, 0xd8, 0x49, 0x1c, 0x3f, 0x9b, 0xc4, 0x19, 0xa0, 0x5d, 0x45, 0xc5, 0x8a, 0x56, 0x42, - 0x8a, 0xaa, 0x2a, 0x11, 0x06, 0x29, 0x55, 0x84, 0xa8, 0xdc, 0x52, 0x64, 0xb7, 0x42, 0x8a, 0x26, - 0x40, 0x51, 0x39, 0x4d, 0x66, 0x47, 0xe9,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, + 0x0c, 0x90, 0xab, 0x33, 0x2b, 0xf3, 0x63, 0x9c, 0xf9, 0xf5, 0x00, 0xcf, 0xd1, 0xf9, 0x28, 0x9e, + 0x98, 0x8c, 0xe7, 0x38, 0x7c, 0x0a, 0x5d, 0x91, 0x1d, 0xa9, 0xb3, 0x59, 0x8c, 0xba, 0xfe, 0xdd, + 0x42, 0x52, 0xf4, 0x83, 0x53, 0xc0, 0x75, 0x51, 0xb0, 0x03, 0x9b, 0x63, 0x7f, 0x16, 0x44, 0x83, + 0x16, 0x06, 0xd8, 0x7a, 0x29, 0x02, 0xc5, 0xc5, 0x00, 0xe9, 0x67, 0x9d, 0x21, 0x2e, 0x06, 0xed, + 0x27, 0x8f, 0x7f, 0xbf, 0x19, 0xa2, 0xb7, 0x37, 0x43, 0xf4, 0xe7, 0xcd, 0x10, 0xfd, 0x74, 0x3b, + 0x6c, 0xbd, 0xbd, 0x1d, 0xb6, 0xfe, 0xb8, 0x1d, 0xb6, 0x5e, 0x7d, 0xf8, 0x8f, 0xbe, 0x0a, 0x2f, + 0xb7, 0xcc, 0xcf, 0xc7, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0x2e, 0x3b, 0x3f, 0x0a, 0x45, 0x0a, + 0x00, 0x00, } func (m *RawAclRecord) Marshal() (dAtA []byte, err error) { @@ -1360,30 +1369,37 @@ func (m *AclRoot) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.IdentitySignature) > 0 { + i -= len(m.IdentitySignature) + copy(dAtA[i:], m.IdentitySignature) + i = encodeVarintAclrecord(dAtA, i, uint64(len(m.IdentitySignature))) + i-- + dAtA[i] = 0x32 + } if m.Timestamp != 0 { i = encodeVarintAclrecord(dAtA, i, uint64(m.Timestamp)) i-- dAtA[i] = 0x28 } - if len(m.DerivationParams) > 0 { - i -= len(m.DerivationParams) - copy(dAtA[i:], m.DerivationParams) - i = encodeVarintAclrecord(dAtA, i, uint64(len(m.DerivationParams))) - i-- - dAtA[i] = 0x22 - } if len(m.EncryptedReadKey) > 0 { i -= len(m.EncryptedReadKey) copy(dAtA[i:], m.EncryptedReadKey) i = encodeVarintAclrecord(dAtA, i, uint64(len(m.EncryptedReadKey))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } if len(m.SpaceId) > 0 { i -= len(m.SpaceId) copy(dAtA[i:], m.SpaceId) i = encodeVarintAclrecord(dAtA, i, uint64(len(m.SpaceId))) i-- + dAtA[i] = 0x1a + } + if len(m.MasterKey) > 0 { + i -= len(m.MasterKey) + copy(dAtA[i:], m.MasterKey) + i = encodeVarintAclrecord(dAtA, i, uint64(len(m.MasterKey))) + i-- dAtA[i] = 0x12 } if len(m.Identity) > 0 { @@ -2150,6 +2166,10 @@ func (m *AclRoot) Size() (n int) { if l > 0 { n += 1 + l + sovAclrecord(uint64(l)) } + l = len(m.MasterKey) + if l > 0 { + n += 1 + l + sovAclrecord(uint64(l)) + } l = len(m.SpaceId) if l > 0 { n += 1 + l + sovAclrecord(uint64(l)) @@ -2158,13 +2178,13 @@ func (m *AclRoot) Size() (n int) { if l > 0 { n += 1 + l + sovAclrecord(uint64(l)) } - l = len(m.DerivationParams) - if l > 0 { - n += 1 + l + sovAclrecord(uint64(l)) - } if m.Timestamp != 0 { n += 1 + sovAclrecord(uint64(m.Timestamp)) } + l = len(m.IdentitySignature) + if l > 0 { + n += 1 + l + sovAclrecord(uint64(l)) + } return n } @@ -3053,6 +3073,40 @@ func (m *AclRoot) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MasterKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAclrecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAclrecord + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAclrecord + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MasterKey = append(m.MasterKey[:0], dAtA[iNdEx:postIndex]...) + if m.MasterKey == nil { + m.MasterKey = []byte{} + } + iNdEx = postIndex + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field SpaceId", wireType) } @@ -3084,7 +3138,7 @@ func (m *AclRoot) Unmarshal(dAtA []byte) error { } m.SpaceId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EncryptedReadKey", wireType) } @@ -3118,9 +3172,28 @@ func (m *AclRoot) Unmarshal(dAtA []byte) error { m.EncryptedReadKey = []byte{} } iNdEx = postIndex - case 4: + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + m.Timestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAclrecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Timestamp |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DerivationParams", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field IdentitySignature", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -3147,30 +3220,11 @@ func (m *AclRoot) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.DerivationParams = append(m.DerivationParams[:0], dAtA[iNdEx:postIndex]...) - if m.DerivationParams == nil { - m.DerivationParams = []byte{} + m.IdentitySignature = append(m.IdentitySignature[:0], dAtA[iNdEx:postIndex]...) + if m.IdentitySignature == nil { + m.IdentitySignature = []byte{} } iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) - } - m.Timestamp = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAclrecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Timestamp |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipAclrecord(dAtA[iNdEx:]) diff --git a/commonspace/object/acl/aclrecordproto/protos/aclrecord.proto b/commonspace/object/acl/aclrecordproto/protos/aclrecord.proto index f64b9697..c90cf116 100644 --- a/commonspace/object/acl/aclrecordproto/protos/aclrecord.proto +++ b/commonspace/object/acl/aclrecordproto/protos/aclrecord.proto @@ -24,10 +24,11 @@ message AclRecord { message AclRoot { bytes identity = 1; - string spaceId = 2; - bytes encryptedReadKey = 3; - bytes derivationParams = 4; + bytes masterKey = 2; + string spaceId = 3; + bytes encryptedReadKey = 4; int64 timestamp = 5; + bytes identitySignature = 6; } message AclContentValue { diff --git a/commonspace/object/acl/list/aclrecordbuilder.go b/commonspace/object/acl/list/aclrecordbuilder.go index 8ea77746..2e02bef0 100644 --- a/commonspace/object/acl/list/aclrecordbuilder.go +++ b/commonspace/object/acl/list/aclrecordbuilder.go @@ -4,14 +4,14 @@ import ( "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/util/cidutil" "github.com/anytypeio/any-sync/util/crypto" - "github.com/anytypeio/any-sync/util/crypto/cryptoproto" "github.com/gogo/protobuf/proto" + "time" ) type RootContent struct { PrivKey crypto.PrivKey + MasterKey crypto.PrivKey SpaceId string - DerivationPath string EncryptedReadKey []byte } @@ -89,22 +89,25 @@ func (a *aclRecordBuilder) BuildRoot(content RootContent) (rec *aclrecordproto.R if err != nil { return } - var derivationParams []byte - if content.DerivationPath != "" { - keyDerivation := &cryptoproto.KeyDerivation{ - Method: cryptoproto.DerivationMethod_Slip21, - DerivationPath: content.DerivationPath, - } - derivationParams, err = keyDerivation.Marshal() - if err != nil { - return - } + masterKey, err := content.MasterKey.GetPublic().Marshall() + if err != nil { + return + } + identitySignature, err := content.MasterKey.Sign(identity) + if err != nil { + return + } + var timestamp int64 + if content.EncryptedReadKey != nil { + timestamp = time.Now().Unix() } aclRoot := &aclrecordproto.AclRoot{ - Identity: identity, - SpaceId: content.SpaceId, - EncryptedReadKey: content.EncryptedReadKey, - DerivationParams: derivationParams, + Identity: identity, + SpaceId: content.SpaceId, + EncryptedReadKey: content.EncryptedReadKey, + MasterKey: masterKey, + IdentitySignature: identitySignature, + Timestamp: timestamp, } return marshalAclRoot(aclRoot, content.PrivKey) } diff --git a/commonspace/object/acl/list/aclstate.go b/commonspace/object/acl/list/aclstate.go index c1ab749e..6bdd30aa 100644 --- a/commonspace/object/acl/list/aclstate.go +++ b/commonspace/object/acl/list/aclstate.go @@ -3,8 +3,6 @@ package list import ( "errors" "fmt" - "github.com/anytypeio/any-sync/util/crypto/cryptoproto" - "github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/util/crypto" @@ -172,8 +170,8 @@ func (st *AclState) saveReadKeyFromRoot(record *AclRecord) (err error) { if !ok { return ErrIncorrectRoot } - if root.DerivationParams != nil { - readKey, err = st.deriveKey(root.DerivationParams) + if root.EncryptedReadKey == nil { + readKey, err = st.deriveKey() if err != nil { return } @@ -315,17 +313,12 @@ func (st *AclState) LastRecordId() string { return st.lastRecordId } -func (st *AclState) deriveKey(params []byte) (crypto.SymKey, error) { - keyDerivation := &cryptoproto.KeyDerivation{} - err := proto.Unmarshal(params, keyDerivation) - if err != nil { - return nil, err - } +func (st *AclState) deriveKey() (crypto.SymKey, error) { keyBytes, err := st.key.Raw() if err != nil { return nil, err } - return crypto.DeriveSymmetricKey(keyBytes, keyDerivation.DerivationPath) + return crypto.DeriveSymmetricKey(keyBytes, crypto.AnysyncSpacePath) } func mapKeyFromPubKey(pubKey crypto.PubKey) string { diff --git a/commonspace/object/acl/list/listutils.go b/commonspace/object/acl/list/listutils.go index e9a92553..f2597ca2 100644 --- a/commonspace/object/acl/list/listutils.go +++ b/commonspace/object/acl/list/listutils.go @@ -10,9 +10,9 @@ import ( func NewTestDerivedAcl(spaceId string, keys *accountdata.AccountKeys) (AclList, error) { builder := NewAclRecordBuilder("", crypto.NewKeyStorage()) root, err := builder.BuildRoot(RootContent{ - PrivKey: keys.SignKey, - SpaceId: spaceId, - DerivationPath: crypto.AnytypeAccountPath, + PrivKey: keys.SignKey, + SpaceId: spaceId, + MasterKey: keys.MasterKey, }) if err != nil { return nil, err diff --git a/commonspace/payloads.go b/commonspace/payloads.go index 00075379..46d2515d 100644 --- a/commonspace/payloads.go +++ b/commonspace/payloads.go @@ -66,6 +66,7 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload sp aclBuilder := list.NewAclRecordBuilder("", keyStorage) aclRoot, err := aclBuilder.BuildRoot(list.RootContent{ PrivKey: payload.SigningKey, + MasterKey: payload.MasterKey, SpaceId: spaceId, EncryptedReadKey: readKey, }) @@ -151,9 +152,9 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload sp keyStorage := crypto.NewKeyStorage() aclBuilder := list.NewAclRecordBuilder("", keyStorage) aclRoot, err := aclBuilder.BuildRoot(list.RootContent{ - PrivKey: payload.SigningKey, - SpaceId: spaceId, - DerivationPath: crypto.AnytypeAccountPath, + PrivKey: payload.SigningKey, + MasterKey: payload.MasterKey, + SpaceId: spaceId, }) if err != nil { return diff --git a/commonspace/space.go b/commonspace/space.go index ece13042..8b4375fb 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -50,6 +50,8 @@ type SpaceCreatePayload struct { ReplicationKey uint64 // SpacePayload is an arbitrary payload related to space type SpacePayload []byte + // MasterKey is the master key of the owner + MasterKey crypto.PrivKey } type HandleMessage struct { @@ -61,6 +63,7 @@ type HandleMessage struct { type SpaceDerivePayload struct { SigningKey crypto.PrivKey + MasterKey crypto.PrivKey SpaceType string SpacePayload []byte } diff --git a/util/crypto/cryptoproto/crypto.pb.go b/util/crypto/cryptoproto/crypto.pb.go index 0f1120cc..338c1dd9 100644 --- a/util/crypto/cryptoproto/crypto.pb.go +++ b/util/crypto/cryptoproto/crypto.pb.go @@ -50,28 +50,6 @@ func (KeyType) EnumDescriptor() ([]byte, []int) { return fileDescriptor_ddfeb19e486561de, []int{0} } -type DerivationMethod int32 - -const ( - DerivationMethod_Slip21 DerivationMethod = 0 -) - -var DerivationMethod_name = map[int32]string{ - 0: "Slip21", -} - -var DerivationMethod_value = map[string]int32{ - "Slip21": 0, -} - -func (x DerivationMethod) String() string { - return proto.EnumName(DerivationMethod_name, int32(x)) -} - -func (DerivationMethod) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_ddfeb19e486561de, []int{1} -} - type Key struct { Type KeyType `protobuf:"varint,1,opt,name=Type,proto3,enum=crypto.KeyType" json:"Type,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"` @@ -124,63 +102,9 @@ func (m *Key) GetData() []byte { return nil } -type KeyDerivation struct { - Method DerivationMethod `protobuf:"varint,1,opt,name=method,proto3,enum=crypto.DerivationMethod" json:"method,omitempty"` - DerivationPath string `protobuf:"bytes,2,opt,name=derivationPath,proto3" json:"derivationPath,omitempty"` -} - -func (m *KeyDerivation) Reset() { *m = KeyDerivation{} } -func (m *KeyDerivation) String() string { return proto.CompactTextString(m) } -func (*KeyDerivation) ProtoMessage() {} -func (*KeyDerivation) Descriptor() ([]byte, []int) { - return fileDescriptor_ddfeb19e486561de, []int{1} -} -func (m *KeyDerivation) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *KeyDerivation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_KeyDerivation.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *KeyDerivation) XXX_Merge(src proto.Message) { - xxx_messageInfo_KeyDerivation.Merge(m, src) -} -func (m *KeyDerivation) XXX_Size() int { - return m.Size() -} -func (m *KeyDerivation) XXX_DiscardUnknown() { - xxx_messageInfo_KeyDerivation.DiscardUnknown(m) -} - -var xxx_messageInfo_KeyDerivation proto.InternalMessageInfo - -func (m *KeyDerivation) GetMethod() DerivationMethod { - if m != nil { - return m.Method - } - return DerivationMethod_Slip21 -} - -func (m *KeyDerivation) GetDerivationPath() string { - if m != nil { - return m.DerivationPath - } - return "" -} - func init() { proto.RegisterEnum("crypto.KeyType", KeyType_name, KeyType_value) - proto.RegisterEnum("crypto.DerivationMethod", DerivationMethod_name, DerivationMethod_value) proto.RegisterType((*Key)(nil), "crypto.Key") - proto.RegisterType((*KeyDerivation)(nil), "crypto.KeyDerivation") } func init() { @@ -188,24 +112,19 @@ func init() { } var fileDescriptor_ddfeb19e486561de = []byte{ - // 263 bytes of a gzipped FileDescriptorProto + // 191 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2e, 0x2d, 0xc9, 0xcc, 0xd1, 0x4f, 0x2e, 0xaa, 0x2c, 0x28, 0xc9, 0x87, 0x52, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0xfa, 0x60, 0xb2, 0x18, 0x2a, 0xa4, 0x07, 0xe6, 0x09, 0xb1, 0x41, 0x78, 0x4a, 0x76, 0x5c, 0xcc, 0xde, 0xa9, 0x95, 0x42, 0xca, 0x5c, 0x2c, 0x21, 0x95, 0x05, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x7c, 0x46, 0xfc, 0x7a, 0x50, 0xb5, 0xde, 0xa9, 0x95, 0x20, 0xe1, 0x20, 0xb0, 0xa4, 0x90, 0x10, 0x17, 0x8b, - 0x4b, 0x62, 0x49, 0xa2, 0x04, 0x93, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x98, 0xad, 0x94, 0xc9, 0xc5, - 0xeb, 0x9d, 0x5a, 0xe9, 0x92, 0x5a, 0x94, 0x59, 0x96, 0x58, 0x92, 0x99, 0x9f, 0x27, 0x64, 0xc0, - 0xc5, 0x96, 0x9b, 0x5a, 0x92, 0x91, 0x9f, 0x02, 0x35, 0x4b, 0x02, 0x66, 0x16, 0x42, 0x8d, 0x2f, - 0x58, 0x3e, 0x08, 0xaa, 0x4e, 0x48, 0x8d, 0x8b, 0x2f, 0x05, 0x2e, 0x17, 0x90, 0x58, 0x92, 0x01, - 0xb6, 0x80, 0x33, 0x08, 0x4d, 0x54, 0xcb, 0x92, 0x8b, 0x1d, 0xea, 0x1e, 0x21, 0x41, 0x2e, 0x5e, - 0xd7, 0x14, 0x23, 0x53, 0x53, 0x43, 0xcb, 0x80, 0xd2, 0xa4, 0x9c, 0xcc, 0x64, 0x01, 0x06, 0x21, - 0x21, 0x2e, 0x3e, 0x98, 0x10, 0x58, 0x57, 0xaa, 0x00, 0xa3, 0x10, 0x3b, 0x17, 0xb3, 0xa3, 0x6b, - 0xb0, 0x00, 0x93, 0x96, 0x1c, 0x97, 0x00, 0xba, 0xf5, 0x42, 0x5c, 0x5c, 0x6c, 0xc1, 0x39, 0x99, - 0x05, 0x46, 0x86, 0x02, 0x0c, 0x4e, 0x86, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, - 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, - 0x10, 0x25, 0x8e, 0x23, 0x50, 0x93, 0xd8, 0xc0, 0x94, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x65, - 0xdf, 0xa5, 0x11, 0x76, 0x01, 0x00, 0x00, + 0x4b, 0x62, 0x49, 0xa2, 0x04, 0x93, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x98, 0xad, 0x65, 0xc9, 0xc5, + 0x0e, 0x55, 0x24, 0x24, 0xc8, 0xc5, 0xeb, 0x9a, 0x62, 0x64, 0x6a, 0x6a, 0x68, 0x19, 0x50, 0x9a, + 0x94, 0x93, 0x99, 0x2c, 0xc0, 0x20, 0x24, 0xc4, 0xc5, 0x07, 0x13, 0x2a, 0xca, 0x2c, 0x4b, 0x2c, + 0x49, 0x15, 0x60, 0x14, 0x62, 0xe7, 0x62, 0x76, 0x74, 0x0d, 0x16, 0x60, 0x72, 0x32, 0x3c, 0xf1, + 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, + 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x71, 0x1c, 0x3e, 0x49, 0x62, 0x03, 0x53, + 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x27, 0xb9, 0xba, 0xd8, 0xeb, 0x00, 0x00, 0x00, } func (m *Key) Marshal() (dAtA []byte, err error) { @@ -243,41 +162,6 @@ func (m *Key) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *KeyDerivation) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *KeyDerivation) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *KeyDerivation) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.DerivationPath) > 0 { - i -= len(m.DerivationPath) - copy(dAtA[i:], m.DerivationPath) - i = encodeVarintCrypto(dAtA, i, uint64(len(m.DerivationPath))) - i-- - dAtA[i] = 0x12 - } - if m.Method != 0 { - i = encodeVarintCrypto(dAtA, i, uint64(m.Method)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - func encodeVarintCrypto(dAtA []byte, offset int, v uint64) int { offset -= sovCrypto(v) base := offset @@ -305,22 +189,6 @@ func (m *Key) Size() (n int) { return n } -func (m *KeyDerivation) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Method != 0 { - n += 1 + sovCrypto(uint64(m.Method)) - } - l = len(m.DerivationPath) - if l > 0 { - n += 1 + l + sovCrypto(uint64(l)) - } - return n -} - func sovCrypto(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -430,107 +298,6 @@ func (m *Key) Unmarshal(dAtA []byte) error { } return nil } -func (m *KeyDerivation) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCrypto - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: KeyDerivation: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: KeyDerivation: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Method", wireType) - } - m.Method = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCrypto - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Method |= DerivationMethod(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DerivationPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCrypto - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthCrypto - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthCrypto - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.DerivationPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCrypto(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthCrypto - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipCrypto(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/util/crypto/cryptoproto/protos/crypto.proto b/util/crypto/cryptoproto/protos/crypto.proto index d74f0b61..dea6164b 100644 --- a/util/crypto/cryptoproto/protos/crypto.proto +++ b/util/crypto/cryptoproto/protos/crypto.proto @@ -8,16 +8,7 @@ enum KeyType { AES = 2; } -enum DerivationMethod { - Slip21 = 0; -} - message Key { KeyType Type = 1; bytes Data = 2; } - -message KeyDerivation { - DerivationMethod method = 1; - string derivationPath = 2; -} \ No newline at end of file diff --git a/util/crypto/derived.go b/util/crypto/derived.go index 596e4560..5821ea5f 100644 --- a/util/crypto/derived.go +++ b/util/crypto/derived.go @@ -5,9 +5,8 @@ import ( ) const ( - AnytypeAccountPath = "m/SLIP-0021/anytype/account" - AnysyncTreePath = "m/SLIP-0021/anysync/tree/%s" - AnytypeAccountPrefix = "m/44'/607'" + AnysyncSpacePath = "m/SLIP-0021/anysync/space" + AnysyncTreePath = "m/SLIP-0021/anysync/tree/%s" ) // DeriveSymmetricKey derives a symmetric key from seed and path using slip-21 diff --git a/util/crypto/derived_test.go b/util/crypto/derived_test.go index 24fd75df..2418e9b4 100644 --- a/util/crypto/derived_test.go +++ b/util/crypto/derived_test.go @@ -10,7 +10,7 @@ func TestDerivedKey(t *testing.T) { seed := make([]byte, 32) _, err := rand.Read(seed) require.NoError(t, err) - key, err := DeriveSymmetricKey(seed, AnytypeAccountPath) + key, err := DeriveSymmetricKey(seed, AnysyncSpacePath) require.NoError(t, err) _, err = rand.Read(seed) require.NoError(t, err) diff --git a/util/crypto/mnemonic.go b/util/crypto/mnemonic.go index 3b388bcc..07fe0260 100644 --- a/util/crypto/mnemonic.go +++ b/util/crypto/mnemonic.go @@ -12,6 +12,19 @@ var ( ErrInvalidMnemonic = errors.New("error invalid mnemonic") ) +const ( + anytypeAccountOldPrefix = "m/44'/607'" + // TODO: actually approve this + anytypeAccountNewPrefix = "m/44'/123456'" +) + +type DerivationResult struct { + MasterKey PrivKey + Identity PrivKey + OldAccountKey PrivKey + MasterNode slip10.Node +} + type MnemonicGenerator struct { mnemonic string } @@ -61,7 +74,47 @@ func (g MnemonicGenerator) WithEntropy(b []byte) (Mnemonic, error) { return Mnemonic(mnemonic), nil } -func (m Mnemonic) DeriveEd25519Key(index int) (PrivKey, error) { +func (m Mnemonic) deriveForPath(onlyMaster bool, index uint32, path string) (res DerivationResult, err error) { + seed, err := m.Seed() + if err != nil { + return + } + prefixNode, err := slip10.DeriveForPath(path, seed) + if err != nil { + return + } + // m/44'/code'/index' + res.MasterNode, err = prefixNode.Derive(slip10.FirstHardenedIndex + index) + if err != nil { + return + } + res.MasterKey, err = genKey(res.MasterNode) + if err != nil || onlyMaster { + return + } + // m/44'/code'/index'/0' + identityNode, err := res.MasterNode.Derive(slip10.FirstHardenedIndex) + if err != nil { + return + } + res.Identity, err = genKey(identityNode) + return +} + +func (m Mnemonic) DeriveKeys(index uint32) (res DerivationResult, err error) { + oldRes, err := m.deriveForPath(true, index, anytypeAccountOldPrefix) + if err != nil { + return + } + res, err = m.deriveForPath(false, index, anytypeAccountNewPrefix) + if err != nil { + return + } + res.OldAccountKey = oldRes.MasterKey + return +} + +func (m Mnemonic) Seed() ([]byte, error) { seed, err := bip39.NewSeedWithErrorChecking(string(m), "") if err != nil { if err == bip39.ErrInvalidMnemonic { @@ -69,22 +122,15 @@ func (m Mnemonic) DeriveEd25519Key(index int) (PrivKey, error) { } return nil, err } - masterKey, err := slip10.DeriveForPath(AnytypeAccountPrefix, seed) - if err != nil { - return nil, err - } - - key, err := masterKey.Derive(slip10.FirstHardenedIndex + uint32(index)) - if err != nil { - return nil, err - } - - reader := bytes.NewReader(key.RawSeed()) - privKey, _, err := GenerateEd25519Key(reader) - - return privKey, err + return seed, nil } func (m Mnemonic) Bytes() ([]byte, error) { return bip39.MnemonicToByteArray(string(m), true) } + +func genKey(node slip10.Node) (key PrivKey, err error) { + reader := bytes.NewReader(node.RawSeed()) + key, _, err = GenerateEd25519Key(reader) + return +} diff --git a/util/crypto/mnemonic_test.go b/util/crypto/mnemonic_test.go index 176dabbf..ae4e86bb 100644 --- a/util/crypto/mnemonic_test.go +++ b/util/crypto/mnemonic_test.go @@ -2,6 +2,7 @@ package crypto import ( "crypto/rand" + "github.com/anytypeio/go-slip10" "github.com/stretchr/testify/require" "strings" "testing" @@ -12,14 +13,31 @@ func TestMnemonic(t *testing.T) { require.NoError(t, err) parts := strings.Split(string(phrase), " ") require.Equal(t, 12, len(parts)) - key, err := phrase.DeriveEd25519Key(0) + res, err := phrase.DeriveKeys(0) require.NoError(t, err) bytes := make([]byte, 64) _, err = rand.Read(bytes) require.NoError(t, err) - sign, err := key.Sign(bytes) + + // testing signing with keys + for _, k := range []PrivKey{res.MasterKey, res.Identity, res.OldAccountKey} { + sign, err := k.Sign(bytes) + require.NoError(t, err) + res, err := k.GetPublic().Verify(bytes, sign) + require.NoError(t, err) + require.True(t, res) + } + + // testing derivation + masterKey, err := genKey(res.MasterNode) require.NoError(t, err) - res, err := key.GetPublic().Verify(bytes, sign) + require.True(t, res.MasterKey.Equals(masterKey)) + identityNode, err := res.MasterNode.Derive(slip10.FirstHardenedIndex) require.NoError(t, err) - require.True(t, res) + identityKey, err := genKey(identityNode) + require.NoError(t, err) + require.True(t, res.Identity.Equals(identityKey)) + oldAccountRes, err := phrase.deriveForPath(true, 0, anytypeAccountOldPrefix) + require.NoError(t, err) + require.True(t, res.OldAccountKey.Equals(oldAccountRes.MasterKey)) } From 13df75d0e0770a051c60e7d0a64e0a33ed4079b2 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Sun, 2 Apr 2023 18:53:02 +0200 Subject: [PATCH 3/7] Add old account to coordinator proto --- .../credentialprovider/credentialprovider.go | 28 --- .../object/acl/list/aclrecordbuilder.go | 6 +- .../coordinatorclient/coordinatorclient.go | 30 ++- .../coordinatorproto/coordinator.pb.go | 204 ++++++++++++++---- .../coordinatorproto/protos/coordinator.proto | 6 + 5 files changed, 195 insertions(+), 79 deletions(-) diff --git a/commonspace/credentialprovider/credentialprovider.go b/commonspace/credentialprovider/credentialprovider.go index 14f7f653..0b188278 100644 --- a/commonspace/credentialprovider/credentialprovider.go +++ b/commonspace/credentialprovider/credentialprovider.go @@ -3,18 +3,11 @@ package credentialprovider import ( "context" - "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" - "github.com/anytypeio/any-sync/coordinator/coordinatorclient" - "github.com/gogo/protobuf/proto" ) const CName = "common.commonspace.credentialprovider" -func New() app.Component { - return &credentialProvider{} -} - func NewNoOp() CredentialProvider { return &noOpProvider{} } @@ -29,24 +22,3 @@ type noOpProvider struct { func (n noOpProvider) GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { return nil, nil } - -type credentialProvider struct { - client coordinatorclient.CoordinatorClient -} - -func (c *credentialProvider) Init(a *app.App) (err error) { - c.client = a.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient) - return -} - -func (c *credentialProvider) Name() (name string) { - return CName -} - -func (c *credentialProvider) GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { - receipt, err := c.client.SpaceSign(ctx, spaceHeader.Id, spaceHeader.RawHeader) - if err != nil { - return nil, err - } - return proto.Marshal(receipt) -} diff --git a/commonspace/object/acl/list/aclrecordbuilder.go b/commonspace/object/acl/list/aclrecordbuilder.go index 2e02bef0..741cac66 100644 --- a/commonspace/object/acl/list/aclrecordbuilder.go +++ b/commonspace/object/acl/list/aclrecordbuilder.go @@ -85,6 +85,10 @@ func (a *aclRecordBuilder) Unmarshall(rawIdRecord *aclrecordproto.RawAclRecordWi } func (a *aclRecordBuilder) BuildRoot(content RootContent) (rec *aclrecordproto.RawAclRecordWithId, err error) { + rawIdentity, err := content.PrivKey.GetPublic().Raw() + if err != nil { + return + } identity, err := content.PrivKey.GetPublic().Marshall() if err != nil { return @@ -93,7 +97,7 @@ func (a *aclRecordBuilder) BuildRoot(content RootContent) (rec *aclrecordproto.R if err != nil { return } - identitySignature, err := content.MasterKey.Sign(identity) + identitySignature, err := content.MasterKey.Sign(rawIdentity) if err != nil { return } diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index 7e490268..fc3c2dc2 100644 --- a/coordinator/coordinatorclient/coordinatorclient.go +++ b/coordinator/coordinatorclient/coordinatorclient.go @@ -9,6 +9,7 @@ import ( "github.com/anytypeio/any-sync/net/pool" "github.com/anytypeio/any-sync/net/rpc/rpcerr" "github.com/anytypeio/any-sync/nodeconf" + "github.com/anytypeio/any-sync/util/crypto" ) const CName = "common.coordinator.coordinatorclient" @@ -20,11 +21,18 @@ func New() CoordinatorClient { type CoordinatorClient interface { ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (status *coordinatorproto.SpaceStatusPayload, err error) StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error) - SpaceSign(ctx context.Context, spaceId string, spaceHeader []byte) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) + SpaceSign(ctx context.Context, payload SpaceSignPayload) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) FileLimitCheck(ctx context.Context, spaceId string, identity []byte) (limit uint64, err error) app.Component } +type SpaceSignPayload struct { + SpaceId string + SpaceHeader []byte + OldAccount crypto.PrivKey + Identity crypto.PrivKey +} + type coordinatorClient struct { pool pool.Pool nodeConf nodeconf.Service @@ -74,14 +82,28 @@ func (c *coordinatorClient) Name() (name string) { return CName } -func (c *coordinatorClient) SpaceSign(ctx context.Context, spaceId string, spaceHeader []byte) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) { +func (c *coordinatorClient) SpaceSign(ctx context.Context, payload SpaceSignPayload) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) { cl, err := c.client(ctx) if err != nil { return } + newRaw, err := payload.Identity.GetPublic().Raw() + if err != nil { + return + } + newSignature, err := payload.OldAccount.Sign(newRaw) + if err != nil { + return + } + oldIdentity, err := payload.OldAccount.GetPublic().Marshall() + if err != nil { + return + } resp, err := cl.SpaceSign(ctx, &coordinatorproto.SpaceSignRequest{ - SpaceId: spaceId, - Header: spaceHeader, + SpaceId: payload.SpaceId, + Header: payload.SpaceHeader, + OldIdentity: oldIdentity, + NewIdentitySignature: newSignature, }) if err != nil { err = rpcerr.Unwrap(err) diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index d35c7b8a..ef911967 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -91,8 +91,14 @@ func (SpaceStatus) EnumDescriptor() ([]byte, []int) { } type SpaceSignRequest struct { + // SpaceId is the id of the signed space SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` - Header []byte `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"` + // Header is the header of the signed space + Header []byte `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"` + // OldIdentity is the old identity of the space owner + OldIdentity []byte `protobuf:"bytes,3,opt,name=oldIdentity,proto3" json:"oldIdentity,omitempty"` + // NewIdentitySignature is the new identity signed by the old one + NewIdentitySignature []byte `protobuf:"bytes,4,opt,name=newIdentitySignature,proto3" json:"newIdentitySignature,omitempty"` } func (m *SpaceSignRequest) Reset() { *m = SpaceSignRequest{} } @@ -142,6 +148,20 @@ func (m *SpaceSignRequest) GetHeader() []byte { return nil } +func (m *SpaceSignRequest) GetOldIdentity() []byte { + if m != nil { + return m.OldIdentity + } + return nil +} + +func (m *SpaceSignRequest) GetNewIdentitySignature() []byte { + if m != nil { + return m.NewIdentitySignature + } + return nil +} + type SpaceStatusPayload struct { Status SpaceStatus `protobuf:"varint,1,opt,name=status,proto3,enum=coordinator.SpaceStatus" json:"status,omitempty"` DeletionTimestamp int64 `protobuf:"varint,2,opt,name=deletionTimestamp,proto3" json:"deletionTimestamp,omitempty"` @@ -689,51 +709,53 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 704 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4d, 0x4f, 0x13, 0x4f, - 0x18, 0xef, 0xb6, 0x05, 0xd2, 0xa7, 0xa4, 0xff, 0x65, 0xfe, 0x80, 0x6b, 0x83, 0x2b, 0x59, 0x95, - 0x34, 0xc4, 0x00, 0x29, 0x6a, 0xe2, 0xcd, 0x58, 0x30, 0xc1, 0x18, 0x24, 0x8b, 0xd5, 0xa8, 0x07, - 0xb3, 0xec, 0x3e, 0xc0, 0x84, 0x65, 0x67, 0xdd, 0x99, 0x1a, 0x38, 0x98, 0xf8, 0x11, 0x3c, 0xf9, - 0x29, 0xfc, 0x08, 0x7e, 0x00, 0x8f, 0x1c, 0x3d, 0x1a, 0xf8, 0x14, 0xde, 0xcc, 0xbe, 0x4c, 0x3b, - 0xdb, 0x6e, 0xcb, 0xc1, 0x0b, 0x74, 0x7e, 0xcf, 0xcb, 0xef, 0xf7, 0xbc, 0xcc, 0x2c, 0x3c, 0x74, - 0x19, 0x8b, 0x3c, 0x1a, 0x38, 0x82, 0x45, 0xeb, 0xca, 0xef, 0x30, 0x62, 0x82, 0xad, 0x27, 0x7f, - 0xb9, 0x8a, 0xaf, 0x25, 0x10, 0xa9, 0x2b, 0x90, 0xb5, 0x05, 0xfa, 0x7e, 0xe8, 0xb8, 0xb8, 0x4f, - 0x8f, 0x02, 0x1b, 0x3f, 0xf6, 0x90, 0x0b, 0x62, 0xc0, 0x0c, 0x8f, 0xb1, 0x1d, 0xcf, 0xd0, 0x96, - 0xb5, 0x56, 0xcd, 0x96, 0x47, 0xb2, 0x08, 0xd3, 0xc7, 0xe8, 0x78, 0x18, 0x19, 0xe5, 0x65, 0xad, - 0x35, 0x6b, 0x67, 0x27, 0x4b, 0x00, 0x49, 0xb3, 0x08, 0x47, 0xf4, 0xf8, 0x9e, 0x73, 0xee, 0x33, - 0xc7, 0x23, 0x1b, 0x30, 0xcd, 0x13, 0x20, 0x49, 0xd3, 0x68, 0x1b, 0x6b, 0xaa, 0x18, 0x25, 0xc0, - 0xce, 0xfc, 0xc8, 0x7d, 0x98, 0xf3, 0xd0, 0x47, 0x41, 0x59, 0xf0, 0x8a, 0x9e, 0x22, 0x17, 0xce, - 0x69, 0x98, 0x50, 0x55, 0xec, 0x51, 0x83, 0xd5, 0x85, 0x39, 0x45, 0x3b, 0x0f, 0x59, 0xc0, 0x91, - 0x3c, 0x81, 0x99, 0x08, 0x5d, 0xa4, 0xa1, 0x48, 0x58, 0xeb, 0xed, 0x95, 0x51, 0x56, 0x3b, 0x75, - 0x78, 0x43, 0xc5, 0x71, 0x1c, 0xeb, 0x88, 0x5e, 0x84, 0xb6, 0x0c, 0xb3, 0x4e, 0xe0, 0xe6, 0x58, - 0x2f, 0xb2, 0x01, 0xff, 0x73, 0xc5, 0x98, 0x95, 0x9a, 0x50, 0xcd, 0xda, 0x45, 0x26, 0xb2, 0x04, - 0x35, 0x2e, 0xc3, 0xb3, 0xb6, 0x0d, 0x00, 0xeb, 0x87, 0x06, 0xb3, 0x2a, 0xdb, 0xe4, 0xe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34, 0x57, 0xae, 0x73, 0x4b, 0x39, - 0x9e, 0x3e, 0xfa, 0x79, 0x69, 0x6a, 0x17, 0x97, 0xa6, 0xf6, 0xfb, 0xd2, 0xd4, 0xbe, 0x5e, 0x99, - 0xa5, 0x8b, 0x2b, 0xb3, 0xf4, 0xeb, 0xca, 0x2c, 0xbd, 0x5b, 0x9a, 0xf4, 0x91, 0x3c, 0x98, 0x4e, - 0xfe, 0x6d, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x76, 0x96, 0x0f, 0x4b, 0x07, 0x00, 0x00, + // 728 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcf, 0x4e, 0x13, 0x41, + 0x18, 0xef, 0xb6, 0x05, 0xd2, 0xaf, 0xa4, 0x2e, 0x23, 0xe0, 0xda, 0xe0, 0xda, 0xac, 0x4a, 0x1a, + 0x62, 0x80, 0x14, 0x35, 0xf1, 0x66, 0xac, 0x98, 0x60, 0x0c, 0x92, 0xc5, 0x6a, 0xd4, 0x83, 0x59, + 0x76, 0x3f, 0x60, 0xc2, 0xb2, 0xb3, 0xee, 0x4c, 0x15, 0x0e, 0x26, 0x3e, 0x82, 0x27, 0x0f, 0x3e, + 0x83, 0x8f, 0xe0, 0x03, 0x78, 0xe4, 0xe8, 0xd1, 0xc0, 0x53, 0x78, 0x33, 0x9d, 0xdd, 0x6d, 0x67, + 0xdb, 0x6d, 0x39, 0x78, 0x81, 0xce, 0xef, 0xfb, 0x7d, 0x7f, 0x7f, 0xdf, 0xcc, 0xc2, 0x7d, 0x97, + 0xb1, 0xc8, 0xa3, 0x81, 0x23, 0x58, 0xb4, 0xa6, 0xfc, 0x0e, 0x23, 0x26, 0xd8, 0x9a, 0xfc, 0xcb, + 0x55, 0x7c, 0x55, 0x42, 0xa4, 0xaa, 0x40, 0xd6, 0x77, 0x0d, 0xf4, 0xdd, 0xd0,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0x9b, 0x52, 0x5f, 0xbe, 0x8c, 0x16, 0xe7, 0x78, 0xfc, 0xe0, 0xd7, 0xb9, 0xa9, 0x9d, 0x9d, + 0x9b, 0xda, 0x9f, 0x73, 0x53, 0xfb, 0x7a, 0x61, 0x16, 0xce, 0x2e, 0xcc, 0xc2, 0xef, 0x0b, 0xb3, + 0xf0, 0x76, 0x69, 0xd2, 0xb7, 0x77, 0x6f, 0x5a, 0xfe, 0xdb, 0xf8, 0x17, 0x00, 0x00, 0xff, 0xff, + 0x86, 0x2f, 0x30, 0xee, 0xa2, 0x07, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { @@ -756,6 +778,20 @@ func (m *SpaceSignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.NewIdentitySignature) > 0 { + i -= len(m.NewIdentitySignature) + copy(dAtA[i:], m.NewIdentitySignature) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.NewIdentitySignature))) + i-- + dAtA[i] = 0x22 + } + if len(m.OldIdentity) > 0 { + i -= len(m.OldIdentity) + copy(dAtA[i:], m.OldIdentity) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.OldIdentity))) + i-- + dAtA[i] = 0x1a + } if len(m.Header) > 0 { i -= len(m.Header) copy(dAtA[i:], m.Header) @@ -1168,6 +1204,14 @@ func (m *SpaceSignRequest) Size() (n int) { if l > 0 { n += 1 + l + sovCoordinator(uint64(l)) } + l = len(m.OldIdentity) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + l = len(m.NewIdentitySignature) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } return n } @@ -1434,6 +1478,74 @@ func (m *SpaceSignRequest) Unmarshal(dAtA []byte) error { m.Header = []byte{} } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OldIdentity", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OldIdentity = append(m.OldIdentity[:0], dAtA[iNdEx:postIndex]...) + if m.OldIdentity == nil { + m.OldIdentity = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewIdentitySignature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NewIdentitySignature = append(m.NewIdentitySignature[:0], dAtA[iNdEx:postIndex]...) + if m.NewIdentitySignature == nil { + m.NewIdentitySignature = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipCoordinator(dAtA[iNdEx:]) diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index b828740c..1075a1d6 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -21,8 +21,14 @@ service Coordinator { } message SpaceSignRequest { + // SpaceId is the id of the signed space string spaceId = 1; + // Header is the header of the signed space bytes header = 2; + // OldIdentity is the old identity of the space owner + bytes oldIdentity = 3; + // NewIdentitySignature is the new identity signed by the old one + bytes newIdentitySignature = 4; } enum ErrorCodes { From 7258df1c2d6f4bc600b68f9dc8de4587ef96f88e Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 3 Apr 2023 10:21:28 +0200 Subject: [PATCH 4/7] Update key path --- util/crypto/mnemonic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/crypto/mnemonic.go b/util/crypto/mnemonic.go index 07fe0260..bbdc5628 100644 --- a/util/crypto/mnemonic.go +++ b/util/crypto/mnemonic.go @@ -14,8 +14,8 @@ var ( const ( anytypeAccountOldPrefix = "m/44'/607'" - // TODO: actually approve this - anytypeAccountNewPrefix = "m/44'/123456'" + // TODO: https://github.com/satoshilabs/slips/pull/1528 + anytypeAccountNewPrefix = "m/44'/2046'" ) type DerivationResult struct { From 357f1c935ddd336e089a4b97c9e3c76094315e7a Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 3 Apr 2023 13:01:58 +0200 Subject: [PATCH 5/7] Update derivation path comment --- util/crypto/mnemonic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/crypto/mnemonic.go b/util/crypto/mnemonic.go index bbdc5628..f70b911b 100644 --- a/util/crypto/mnemonic.go +++ b/util/crypto/mnemonic.go @@ -14,7 +14,7 @@ var ( const ( anytypeAccountOldPrefix = "m/44'/607'" - // TODO: https://github.com/satoshilabs/slips/pull/1528 + // https://github.com/satoshilabs/slips/blob/master/slip-0044.md anytypeAccountNewPrefix = "m/44'/2046'" ) From e9d1de77819e8c24f58ffeef1b380b20e580f758 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 3 Apr 2023 13:19:12 +0200 Subject: [PATCH 6/7] Remove master key from account --- commonspace/object/accountdata/accountdata.go | 27 +++++++------------ commonspace/object/acl/list/listutils.go | 6 ++++- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/commonspace/object/accountdata/accountdata.go b/commonspace/object/accountdata/accountdata.go index 5cbd8ab3..b6816a2d 100644 --- a/commonspace/object/accountdata/accountdata.go +++ b/commonspace/object/accountdata/accountdata.go @@ -6,18 +6,16 @@ import ( ) type AccountKeys struct { - PeerKey crypto.PrivKey - SignKey crypto.PrivKey - MasterKey crypto.PrivKey - PeerId string + PeerKey crypto.PrivKey + SignKey crypto.PrivKey + PeerId string } -func New(peerKey, signKey, masterKey crypto.PrivKey) *AccountKeys { +func New(peerKey, signKey crypto.PrivKey) *AccountKeys { return &AccountKeys{ - PeerKey: peerKey, - SignKey: signKey, - MasterKey: masterKey, - PeerId: peerKey.GetPublic().PeerId(), + PeerKey: peerKey, + SignKey: signKey, + PeerId: peerKey.GetPublic().PeerId(), } } @@ -30,14 +28,9 @@ func NewRandom() (*AccountKeys, error) { if err != nil { return nil, err } - masterKey, _, err := crypto.GenerateEd25519Key(rand.Reader) - if err != nil { - return nil, err - } return &AccountKeys{ - PeerKey: peerKey, - SignKey: signKey, - MasterKey: masterKey, - PeerId: peerKey.GetPublic().PeerId(), + PeerKey: peerKey, + SignKey: signKey, + PeerId: peerKey.GetPublic().PeerId(), }, nil } diff --git a/commonspace/object/acl/list/listutils.go b/commonspace/object/acl/list/listutils.go index f2597ca2..342bddb1 100644 --- a/commonspace/object/acl/list/listutils.go +++ b/commonspace/object/acl/list/listutils.go @@ -9,10 +9,14 @@ import ( func NewTestDerivedAcl(spaceId string, keys *accountdata.AccountKeys) (AclList, error) { builder := NewAclRecordBuilder("", crypto.NewKeyStorage()) + masterKey, _, err := crypto.GenerateRandomEd25519KeyPair() + if err != nil { + return nil, err + } root, err := builder.BuildRoot(RootContent{ PrivKey: keys.SignKey, SpaceId: spaceId, - MasterKey: keys.MasterKey, + MasterKey: masterKey, }) if err != nil { return nil, err From 73a919ff9623a4ef1c4445917172e894ba369527 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Tue, 4 Apr 2023 11:22:48 +0200 Subject: [PATCH 7/7] Fix mocks --- .../mock_coordinatorclient/mock_coordinatorclient.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go index 7216e1eb..ab31996b 100644 --- a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go +++ b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go @@ -10,6 +10,7 @@ import ( app "github.com/anytypeio/any-sync/app" treechangeproto "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" + coordinatorclient "github.com/anytypeio/any-sync/coordinator/coordinatorclient" coordinatorproto "github.com/anytypeio/any-sync/coordinator/coordinatorproto" gomock "github.com/golang/mock/gomock" ) @@ -96,18 +97,18 @@ func (mr *MockCoordinatorClientMockRecorder) Name() *gomock.Call { } // SpaceSign mocks base method. -func (m *MockCoordinatorClient) SpaceSign(arg0 context.Context, arg1 string, arg2 []byte) (*coordinatorproto.SpaceReceiptWithSignature, error) { +func (m *MockCoordinatorClient) SpaceSign(arg0 context.Context, arg1 coordinatorclient.SpaceSignPayload) (*coordinatorproto.SpaceReceiptWithSignature, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SpaceSign", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "SpaceSign", arg0, arg1) ret0, _ := ret[0].(*coordinatorproto.SpaceReceiptWithSignature) ret1, _ := ret[1].(error) return ret0, ret1 } // SpaceSign indicates an expected call of SpaceSign. -func (mr *MockCoordinatorClientMockRecorder) SpaceSign(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockCoordinatorClientMockRecorder) SpaceSign(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpaceSign", reflect.TypeOf((*MockCoordinatorClient)(nil).SpaceSign), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpaceSign", reflect.TypeOf((*MockCoordinatorClient)(nil).SpaceSign), arg0, arg1) } // StatusCheck mocks base method.