From 2279018df1009e34117ea56721c38811bf692921 Mon Sep 17 00:00:00 2001 From: Murali Date: Mon, 16 Sep 2024 14:23:32 +0530 Subject: [PATCH 1/5] feat: update verb builder isencrypted --- .../at_commons/lib/src/keystore/at_key.dart | 6 ++-- .../test/update_verb_builder_test.dart | 36 +++++++++---------- packages/at_lookup/pubspec.yaml | 4 +++ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/at_commons/lib/src/keystore/at_key.dart b/packages/at_commons/lib/src/keystore/at_key.dart index d9e016af..ca25f1ba 100644 --- a/packages/at_commons/lib/src/keystore/at_key.dart +++ b/packages/at_commons/lib/src/keystore/at_key.dart @@ -559,9 +559,9 @@ class Metadata { if (isBinary) { sb.write(':isBinary:$isBinary'); } - if (isEncrypted) { - sb.write(':isEncrypted:$isEncrypted'); - } + + sb.write(':isEncrypted:$isEncrypted'); + if (sharedKeyEnc.isNotNullOrEmpty) { sb.write(':${AtConstants.sharedKeyEncrypted}:$sharedKeyEnc'); } diff --git a/packages/at_commons/test/update_verb_builder_test.dart b/packages/at_commons/test/update_verb_builder_test.dart index 174ab937..c817d10a 100644 --- a/packages/at_commons/test/update_verb_builder_test.dart +++ b/packages/at_commons/test/update_verb_builder_test.dart @@ -13,7 +13,7 @@ void main() { ..atKey.key = 'email' ..atKey.sharedBy = '@alice'; expect(updateBuilder.buildCommand(), - 'update:public:email@alice alice@gmail.com\n'); + 'update:isEncrypted:false:public:email@alice alice@gmail.com\n'); }); test('verify private at key command', () { @@ -22,7 +22,7 @@ void main() { ..atKey.key = 'email' ..atKey.sharedBy = '@alice'; expect(updateBuilder.buildCommand(), - 'update:email@alice alice@atsign.com\n'); + 'update:isEncrypted:false:email@alice alice@atsign.com\n'); }); test( @@ -47,7 +47,7 @@ void main() { var updateCommand = updateBuilder.buildCommand(); expect( updateCommand, - 'update' + 'update:isEncrypted:false' ':sharedKeyEnc:$ske' ':pubKeyCS:$pubKeyCS' ':skeEncKeyName:$skeEncKeyName' @@ -75,7 +75,7 @@ void main() { ..atKey.sharedBy = '@alice' ..atKey.isLocal = true; expect(updateBuilder.buildCommand(), - 'update:local:email@alice alice@atsign.com\n'); + 'update:isEncrypted:false:local:email@alice alice@atsign.com\n'); }); }); @@ -87,7 +87,7 @@ void main() { ..atKey.key = 'phone' ..atKey.sharedBy = '@alice'; expect(updateBuilder.buildCommandForMeta(), - 'update:meta:phone@alice:isBinary:true\n'); + 'update:meta:phone@alice:isBinary:true:isEncrypted:false\n'); }); test('verify ttl metadata', () { @@ -96,7 +96,7 @@ void main() { ..atKey.key = 'phone' ..atKey.sharedBy = '@alice'; expect(updateBuilder.buildCommandForMeta(), - 'update:meta:phone@alice:ttl:60000\n'); + 'update:meta:phone@alice:ttl:60000:isEncrypted:false\n'); }); test('verify ttr metadata', () { @@ -105,7 +105,7 @@ void main() { ..atKey.key = 'phone' ..atKey.sharedBy = '@alice'; expect(updateBuilder.buildCommandForMeta(), - 'update:meta:phone@alice:ttr:50000\n'); + 'update:meta:phone@alice:ttr:50000:isEncrypted:false\n'); }); test('verify ttb metadata', () { @@ -114,7 +114,7 @@ void main() { ..atKey.key = 'phone' ..atKey.sharedBy = '@alice'; expect(updateBuilder.buildCommandForMeta(), - 'update:meta:phone@alice:ttb:80000\n'); + 'update:meta:phone@alice:ttb:80000:isEncrypted:false\n'); }); test( @@ -351,7 +351,8 @@ void main() { ..atKey.sharedBy = '@bob' ..value = '+445 334 3423'; var command = updateVerbBuilder.buildCommand(); - expect(command, 'update:local:phone@bob +445 334 3423\n'); + expect( + command, 'update:isEncrypted:false:local:phone@bob +445 334 3423\n'); expect(() => updateVerbBuilder.atKey.sharedWith = '@alice', throwsA(predicate((dynamic e) => e is InvalidAtKeyException))); }); @@ -534,12 +535,11 @@ void main() { ..atKey.sharedBy = '@alice'; var updateCommand = updateBuilder.buildCommand(); expect(updateCommand, - 'update:ttl:5000:public:email@alice alice@gmail.com\n'); + 'update:ttl:5000:isEncrypted:false:public:email@alice alice@gmail.com\n'); var updateVerbParams = getVerbParams(VerbSyntax.update, updateCommand.trim()); print(updateVerbParams); - // existing behaviour. TODO change to false after changes for update verb isEncrypted flag - expect(updateVerbParams['isEncrypted'], null); + expect(updateVerbParams['isEncrypted'], 'false'); }); test('for shared key - isEncrypted is true if set in metadata', () { var updateBuilder = UpdateVerbBuilder() @@ -567,14 +567,12 @@ void main() { ..atKey.sharedWith = '@bob'; var updateCommand = updateBuilder.buildCommand(); print(updateCommand); - // existing behaviour. TODO Should contain isEncrypted:false after changes for update verb isEncrypted flag expect(updateCommand, - 'update:ttl:5000:@bob:email@alice sampleEncryptedValue\n'); + 'update:ttl:5000:isEncrypted:false:@bob:email@alice sampleEncryptedValue\n'); var updateVerbParams = getVerbParams(VerbSyntax.update, updateCommand.trim()); print(updateVerbParams); - // existing behaviour. TODO Should be false after changes for update verb isEncrypted flag - expect(updateVerbParams['isEncrypted'], null); + expect(updateVerbParams['isEncrypted'], 'false'); }); test('for shared key - isEncrypted is false if set to false in metadata', @@ -588,14 +586,12 @@ void main() { ..atKey.sharedWith = '@bob'; var updateCommand = updateBuilder.buildCommand(); print(updateCommand); - // existing behaviour. TODO Should contain isEncrypted:false after changes for update verb isEncrypted flag expect(updateCommand, - 'update:ttl:5000:@bob:email@alice sampleEncryptedValue\n'); + 'update:ttl:5000:isEncrypted:false:@bob:email@alice sampleEncryptedValue\n'); var updateVerbParams = getVerbParams(VerbSyntax.update, updateCommand.trim()); print(updateVerbParams); - // existing behaviour. TODO Should be false after changes for update verb isEncrypted flag - expect(updateVerbParams['isEncrypted'], null); + expect(updateVerbParams['isEncrypted'], 'false'); }); }); } diff --git a/packages/at_lookup/pubspec.yaml b/packages/at_lookup/pubspec.yaml index caf17e64..b4cba406 100644 --- a/packages/at_lookup/pubspec.yaml +++ b/packages/at_lookup/pubspec.yaml @@ -18,6 +18,10 @@ dependencies: meta: ^1.8.0 at_chops: ^2.0.0 +dependency_overrides: + at_commons: + path: ../at_commons + dev_dependencies: mocktail: ^1.0.1 lints: ^1.0.1 From fd4e93be8f9ee90a9db19016c17303d5ce8d5d3f Mon Sep 17 00:00:00 2001 From: Murali Date: Tue, 24 Sep 2024 17:42:25 +0530 Subject: [PATCH 2/5] fix: added changelog for at_commons --- packages/at_commons/CHANGELOG.md | 2 + .../lib/src/verb/notify_verb_builder.dart | 71 +------------------ packages/at_commons/pubspec.yaml | 2 +- packages/at_lookup/pubspec.yaml | 4 -- 4 files changed, 4 insertions(+), 75 deletions(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index 20b42069..8c70f70e 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,3 +1,5 @@ +## 4.1.3 +- feat: Add isEncrypted flag to update verb metadata for both true and false ## 4.1.2 - feat: Add "expiry" enroll params to support apkam keys to auto expiry after specified time duration ## 4.1.1 diff --git a/packages/at_commons/lib/src/verb/notify_verb_builder.dart b/packages/at_commons/lib/src/verb/notify_verb_builder.dart index f02f766e..6b0622d9 100644 --- a/packages/at_commons/lib/src/verb/notify_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/notify_verb_builder.dart @@ -61,7 +61,7 @@ class NotifyVerbBuilder extends AbstractVerbBuilder { } // Add in all of the metadata parameters in atProtocol command format - sb.write(_toAtProtocolFragment(atKey.metadata)); + sb.write(atKey.metadata.toAtProtocolFragment()); if (atKey.sharedWith != null) { sb.write(':${VerbUtil.formatAtSign(atKey.sharedWith)}'); @@ -84,75 +84,6 @@ class NotifyVerbBuilder extends AbstractVerbBuilder { return sb.toString(); } - // temporary method till isEncrypted flag changes are done for update verb. - // TODO Remove this and use at_key.metadata.toProtocolFragment - String _toAtProtocolFragment(Metadata metadata) { - StringBuffer sb = StringBuffer(); - - // NB The order of the verb parameters is important - it MUST match the order - // in the regular expressions [VerbSyntax.update] and [VerbSyntax.update_meta] - if (metadata.ttl != null) { - sb.write(':ttl:${metadata.ttl}'); - } - if (metadata.ttb != null) { - sb.write(':ttb:${metadata.ttb}'); - } - if (metadata.ttr != null) { - sb.write(':ttr:${metadata.ttr}'); - } - if (metadata.ccd != null) { - sb.write(':ccd:${metadata.ccd}'); - } - if (metadata.dataSignature.isNotNullOrEmpty) { - sb.write(':${AtConstants.publicDataSignature}:${metadata.dataSignature}'); - } - if (metadata.sharedKeyStatus.isNotNullOrEmpty) { - sb.write(':${AtConstants.sharedKeyStatus}:${metadata.sharedKeyStatus}'); - } - if (metadata.isBinary) { - sb.write(':isBinary:${metadata.isBinary}'); - } - - sb.write(':isEncrypted:${metadata.isEncrypted}'); - - if (metadata.sharedKeyEnc.isNotNullOrEmpty) { - sb.write(':${AtConstants.sharedKeyEncrypted}:${metadata.sharedKeyEnc}'); - } - // ignore: deprecated_member_use_from_same_package - if (metadata.pubKeyCS.isNotNullOrEmpty) { - // ignore: deprecated_member_use_from_same_package - sb.write( - ':${AtConstants.sharedWithPublicKeyCheckSum}:${metadata.pubKeyCS}'); - } - if (metadata.pubKeyHash != null) { - sb.write( - ':${AtConstants.sharedWithPublicKeyHashValue}:${metadata.pubKeyHash!.hash}'); - sb.write( - ':${AtConstants.sharedWithPublicKeyHashAlgo}:${metadata.pubKeyHash!.publicKeyHashingAlgo.name}'); - } - if (metadata.encoding.isNotNullOrEmpty) { - sb.write(':${AtConstants.encoding}:${metadata.encoding}'); - } - if (metadata.encKeyName.isNotNullOrEmpty) { - sb.write(':${AtConstants.encryptingKeyName}:${metadata.encKeyName}'); - } - if (metadata.encAlgo.isNotNullOrEmpty) { - sb.write(':${AtConstants.encryptingAlgo}:${metadata.encAlgo}'); - } - if (metadata.ivNonce.isNotNullOrEmpty) { - sb.write(':${AtConstants.ivOrNonce}:${metadata.ivNonce}'); - } - if (metadata.skeEncKeyName.isNotNullOrEmpty) { - sb.write( - ':${AtConstants.sharedKeyEncryptedEncryptingKeyName}:${metadata.skeEncKeyName}'); - } - if (metadata.skeEncAlgo.isNotNullOrEmpty) { - sb.write( - ':${AtConstants.sharedKeyEncryptedEncryptingAlgo}:${metadata.skeEncAlgo}'); - } - return sb.toString(); - } - @override bool checkParams() { var isValid = true; diff --git a/packages/at_commons/pubspec.yaml b/packages/at_commons/pubspec.yaml index 37ebb016..77549a8e 100644 --- a/packages/at_commons/pubspec.yaml +++ b/packages/at_commons/pubspec.yaml @@ -1,6 +1,6 @@ name: at_commons description: A library of Dart and Flutter utility classes that are used across other components of the atPlatform. -version: 4.1.2 +version: 4.1.3 repository: https://github.com/atsign-foundation/at_libraries homepage: https://atsign.dev diff --git a/packages/at_lookup/pubspec.yaml b/packages/at_lookup/pubspec.yaml index b4cba406..caf17e64 100644 --- a/packages/at_lookup/pubspec.yaml +++ b/packages/at_lookup/pubspec.yaml @@ -18,10 +18,6 @@ dependencies: meta: ^1.8.0 at_chops: ^2.0.0 -dependency_overrides: - at_commons: - path: ../at_commons - dev_dependencies: mocktail: ^1.0.1 lints: ^1.0.1 From df8068e3f1aa13a4942c74bfbbe3fac6b93344dd Mon Sep 17 00:00:00 2001 From: Murali Date: Tue, 24 Sep 2024 17:55:34 +0530 Subject: [PATCH 3/5] fix: analyzer issue --- packages/at_commons/lib/src/verb/notify_verb_builder.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/at_commons/lib/src/verb/notify_verb_builder.dart b/packages/at_commons/lib/src/verb/notify_verb_builder.dart index 6b0622d9..384ee99c 100644 --- a/packages/at_commons/lib/src/verb/notify_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/notify_verb_builder.dart @@ -1,5 +1,3 @@ -import 'package:at_commons/src/keystore/at_key.dart'; -import 'package:at_commons/src/utils/string_utils.dart'; import 'package:at_commons/src/verb/abstract_verb_builder.dart'; import 'package:uuid/uuid.dart'; From cfd4dd9660a3ecd2261e2b5055df4d37bb1c0179 Mon Sep 17 00:00:00 2001 From: Murali Date: Thu, 26 Sep 2024 16:14:10 +0530 Subject: [PATCH 4/5] fix: change pubspec to major version --- packages/at_commons/CHANGELOG.md | 4 ++-- packages/at_commons/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index 9079ef1b..0b3009c0 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,5 +1,5 @@ -## 4.1.3 -- feat: Add isEncrypted flag to update verb metadata for both true and false +## 5.0.0 +- [Breaking Change]feat: Add isEncrypted flag to update verb metadata for both true and false - fix: update pkam regex to accept sha512 as hashing algo ## 4.1.2 - feat: Add "expiry" enroll params to support apkam keys to auto expiry after specified time duration diff --git a/packages/at_commons/pubspec.yaml b/packages/at_commons/pubspec.yaml index 77549a8e..19435cae 100644 --- a/packages/at_commons/pubspec.yaml +++ b/packages/at_commons/pubspec.yaml @@ -1,6 +1,6 @@ name: at_commons description: A library of Dart and Flutter utility classes that are used across other components of the atPlatform. -version: 4.1.3 +version: 5.0.0 repository: https://github.com/atsign-foundation/at_libraries homepage: https://atsign.dev From 1396f803bc21320fae5ea3d5dbed524874b20581 Mon Sep 17 00:00:00 2001 From: Murali Date: Fri, 27 Sep 2024 14:03:57 +0530 Subject: [PATCH 5/5] fix: review comments in changelog --- packages/at_commons/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index 0b3009c0..38acb509 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,5 +1,5 @@ ## 5.0.0 -- [Breaking Change]feat: Add isEncrypted flag to update verb metadata for both true and false +- [Breaking Change]feat: Emit the isEncrypted value in the metadata if it is false - fix: update pkam regex to accept sha512 as hashing algo ## 4.1.2 - feat: Add "expiry" enroll params to support apkam keys to auto expiry after specified time duration