-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into 2121-uptake-pubkeyhash-changes
- Loading branch information
Showing
35 changed files
with
1,199 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...s/at_persistence_secondary_server/lib/src/log/commitlog/sync/fetch_all_keys_strategy.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:at_persistence_secondary_server/src/log/commitlog/commit_entry.dart'; | ||
import 'package:at_persistence_secondary_server/src/log/commitlog/sync/sync_keys_fetch_strategy.dart'; | ||
|
||
/// Returns the commit entries which have to be synced from server to client | ||
class FetchAllKeysStrategy extends SyncKeysFetchStrategy { | ||
@override | ||
bool shouldIncludeEntryInSyncResponse( | ||
CommitEntry commitEntry, int commitId, String regex, | ||
{List<String>? enrolledNamespace}) { | ||
return commitEntry.commitId! >= commitId && | ||
super.shouldIncludeKeyInSyncResponse(commitEntry.atKey!, regex, | ||
enrolledNamespace: enrolledNamespace); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ges/at_persistence_secondary_server/lib/src/log/commitlog/sync/skip_deletes_strategy.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:at_persistence_secondary_server/src/log/commitlog/commit_entry.dart'; | ||
import 'package:at_persistence_secondary_server/src/log/commitlog/sync/sync_keys_fetch_strategy.dart'; | ||
|
||
/// Returns the commit entries to be returned in sync response from server to client except delete commit entries. | ||
class SkipDeleteStrategy extends SyncKeysFetchStrategy { | ||
late int skipDeletesUntil; | ||
late int latestCommitId; | ||
SkipDeleteStrategy(this.skipDeletesUntil, this.latestCommitId); | ||
@override | ||
bool shouldIncludeEntryInSyncResponse( | ||
CommitEntry commitEntry, int commitId, String regex, | ||
{List<String>? enrolledNamespace}) { | ||
// do not include delete commit entries between commitId and skipDeletesUntil, except when delete is the last commit entry | ||
if (commitEntry.operation == CommitOp.DELETE && | ||
commitEntry.commitId! <= skipDeletesUntil && | ||
commitEntry.commitId! >= commitId && | ||
commitEntry.commitId != latestCommitId) { | ||
return false; | ||
} | ||
return commitEntry.commitId! >= commitId && | ||
super.shouldIncludeKeyInSyncResponse(commitEntry.atKey!, regex, | ||
enrolledNamespace: enrolledNamespace); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
.../at_persistence_secondary_server/lib/src/log/commitlog/sync/sync_keys_fetch_strategy.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:at_commons/at_commons.dart'; | ||
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart'; | ||
import 'package:at_utils/at_utils.dart'; | ||
|
||
abstract class SyncKeysFetchStrategy { | ||
final _logger = AtSignLogger('SyncKeysFetchStrategy'); | ||
|
||
/// Returns true if the commit entry should be included in sync response, false otherwise | ||
bool shouldIncludeEntryInSyncResponse( | ||
CommitEntry commitEntry, int commitId, String regex, | ||
{List<String>? enrolledNamespace}); | ||
|
||
/// if enrolledNamespace is passed, key namespace should be in enrolledNamespace list and | ||
/// atKey should match regex or should be a special key that is always included in sync. | ||
bool shouldIncludeKeyInSyncResponse(String atKey, String regex, | ||
{List<String>? enrolledNamespace}) { | ||
return isNamespaceAuthorised(atKey, enrolledNamespace) && | ||
(keyMatchesRegex(atKey, regex) || alwaysIncludeInSync(atKey)); | ||
} | ||
|
||
/// Returns true if atKey namespace is empty or null/ enrolledNamespace is empty or null | ||
/// if enrolledNamespace contains atKey namespace, return true. false otherwise | ||
bool isNamespaceAuthorised( | ||
String atKeyAsString, List<String>? enrolledNamespace) { | ||
// This is work-around for : https://github.com/atsign-foundation/at_server/issues/1570 | ||
if (atKeyAsString.toLowerCase() == 'configkey') { | ||
return true; | ||
} | ||
late AtKey atKey; | ||
try { | ||
atKey = AtKey.fromString(atKeyAsString); | ||
} on InvalidSyntaxException catch (_) { | ||
_logger.warning( | ||
'_isNamespaceAuthorized found an invalid key "$atKeyAsString" in the commit log. Returning false'); | ||
return false; | ||
} | ||
String? keyNamespace = atKey.namespace; | ||
// If enrolledNamespace is null or keyNamespace is null, fallback to | ||
// existing behaviour - the key is authorized for the client to receive. So return true. | ||
if (enrolledNamespace == null || | ||
enrolledNamespace.isEmpty || | ||
(keyNamespace == null || keyNamespace.isEmpty)) { | ||
return true; | ||
} | ||
if (enrolledNamespace.contains('*') || | ||
enrolledNamespace.contains(keyNamespace)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/// Returns true if atKey matches regex. false otherwise | ||
bool keyMatchesRegex(String atKey, String regex) { | ||
return RegExp(regex).hasMatch(atKey); | ||
} | ||
|
||
/// match keys which have to included in sync irrespective of whether regex matches | ||
/// e.g @bob:shared_key@alice, shared_key.bob@alice, public:publickey@alice, | ||
/// public:phone@alice (public key without namespace) | ||
bool alwaysIncludeInSync(String atKey) { | ||
return (atKey.contains(AtConstants.atEncryptionSharedKey) && | ||
RegexUtil.keyType(atKey, false) == KeyType.reservedKey) || | ||
atKey.startsWith(AtConstants.atEncryptionPublicKey) || | ||
(atKey.startsWith('public:') && !atKey.contains('.')); | ||
} | ||
} |
Oops, something went wrong.