1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 14:07:02 +09:00

Update validation

This commit is contained in:
mcrakhman 2023-08-21 10:48:21 +02:00
parent 6caa9214b7
commit 4592760ece
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
2 changed files with 8 additions and 9 deletions

View file

@ -33,31 +33,31 @@ func PrepareDeleteConfirmation(privKey crypto.PrivKey, spaceId, peerId, networkI
return return
} }
func ValidateDeleteConfirmation(pubKey crypto.PubKey, networkId string, deleteConfirm *DeletionConfirmPayloadWithSignature) (spaceId string, err error) { func ValidateDeleteConfirmation(pubKey crypto.PubKey, spaceId, networkId string, deleteConfirm *DeletionConfirmPayloadWithSignature) (err error) {
res, err := pubKey.Verify(deleteConfirm.GetDeletionPayload(), deleteConfirm.GetSignature()) res, err := pubKey.Verify(deleteConfirm.GetDeletionPayload(), deleteConfirm.GetSignature())
if err != nil { if err != nil {
return return
} }
if !res { if !res {
err = errSignatureIncorrect return errSignatureIncorrect
return
} }
payload := &DeletionConfirmPayload{} payload := &DeletionConfirmPayload{}
err = payload.Unmarshal(deleteConfirm.GetDeletionPayload()) err = payload.Unmarshal(deleteConfirm.GetDeletionPayload())
if err != nil { if err != nil {
return return
} }
spaceId = payload.SpaceId if payload.SpaceId != spaceId {
return errSpaceIdIncorrect
}
if payload.NetworkId != networkId { if payload.NetworkId != networkId {
err = errNetworkIsIncorrect return errNetworkIsIncorrect
return
} }
accountRaw, err := crypto.UnmarshalEd25519PublicKeyProto(payload.AccountIdentity) accountRaw, err := crypto.UnmarshalEd25519PublicKeyProto(payload.AccountIdentity)
if err != nil { if err != nil {
return return
} }
if !bytes.Equal(pubKey.Storage(), accountRaw.Storage()) { if !bytes.Equal(pubKey.Storage(), accountRaw.Storage()) {
err = errAccountIncorrect return errAccountIncorrect
} }
return return
} }

View file

@ -9,7 +9,6 @@ func TestValidateDeleteConfirmation(t *testing.T) {
fx := newFixture(t) fx := newFixture(t)
delConfirm, err := PrepareDeleteConfirmation(fx.accountPrivKey, fx.spaceId, fx.peerId, fx.networkKey.GetPublic().Network()) delConfirm, err := PrepareDeleteConfirmation(fx.accountPrivKey, fx.spaceId, fx.peerId, fx.networkKey.GetPublic().Network())
require.NoError(t, err) require.NoError(t, err)
spaceId, err := ValidateDeleteConfirmation(fx.accountKey, fx.networkKey.GetPublic().Network(), delConfirm) err = ValidateDeleteConfirmation(fx.accountKey, fx.spaceId, fx.networkKey.GetPublic().Network(), delConfirm)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, fx.spaceId, spaceId)
} }