From 346a9960c8c83683e203c04dc911962b98c26102 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 19 Oct 2023 02:34:18 +0530 Subject: [PATCH 1/5] refactor: update authenticate_cram -> cramAuthenticate and deprecate the former --- packages/at_lookup/lib/src/at_lookup_impl.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/at_lookup/lib/src/at_lookup_impl.dart b/packages/at_lookup/lib/src/at_lookup_impl.dart index 3542f4c9..01efbd09 100644 --- a/packages/at_lookup/lib/src/at_lookup_impl.dart +++ b/packages/at_lookup/lib/src/at_lookup_impl.dart @@ -333,7 +333,7 @@ class AtLookupImpl implements AtLookUp { Future _update(UpdateVerbBuilder builder) async { String atCommand; - if (builder.operation == UPDATE_META) { + if (builder.operation == AtConstants.updateMeta) { atCommand = builder.buildCommandForMeta(); } else { atCommand = builder.buildCommand(); @@ -492,10 +492,8 @@ class AtLookupImpl implements AtLookUp { final Mutex _cramAuthenticationMutex = Mutex(); - /// Generates digest using from verb response and [secret] and performs a CRAM authentication to - /// secondary server - // ignore: non_constant_identifier_names - Future authenticate_cram(var secret) async { + @override + Future cramAuthenticate(var secret) async { secret ??= cramSecret; if (secret == null) { throw UnAuthenticatedException('Cram secret not passed'); @@ -534,6 +532,11 @@ class AtLookupImpl implements AtLookUp { } } + @Deprecated('use AtLookup().cramAuthenticate()') + // ignore: non_constant_identifier_names + Future authenticate_cram(var secret) async => + await cramAuthenticate(secret); + Future _plookup(PLookupVerbBuilder builder) async { var atCommand = builder.buildCommand(); return await _process(atCommand, auth: true); @@ -573,7 +576,7 @@ class AtLookupImpl implements AtLookUp { logger.finer('calling pkam without atchops'); await authenticate(privateKey); } else if (cramSecret != null) { - await authenticate_cram(cramSecret); + await cramAuthenticate(cramSecret); } else { throw UnAuthenticatedException( 'Unable to perform atLookup auth. Private key/cram secret is not set'); @@ -622,6 +625,7 @@ class AtLookupImpl implements AtLookUp { return _connection!.isInValid(); } + @override Future close() async { await _connection!.close(); } From a2d4ccb7fdecbe515ba55587c3952e90c83759ba Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 19 Oct 2023 02:34:47 +0530 Subject: [PATCH 2/5] feat: introduce cramAuthenticate and close into the AtLookup interface --- packages/at_lookup/lib/src/at_lookup.dart | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/at_lookup/lib/src/at_lookup.dart b/packages/at_lookup/lib/src/at_lookup.dart index 962ae22a..404f2904 100644 --- a/packages/at_lookup/lib/src/at_lookup.dart +++ b/packages/at_lookup/lib/src/at_lookup.dart @@ -28,12 +28,23 @@ abstract class AtLookUp { Future executeCommand(String command, {bool auth = false}); - /// performs a PKAM authentication using private key on the client side and public key on secondary server + /// Performs a PKAM authentication using private key on the client side and public key on secondary server + /// /// Pkam private key should be set in [atChops.atChopsKeys] + /// /// Default signing algorithm for pkam signature is [SigningAlgoType.rsa2048] and default hashing algorithm is [HashingAlgoType.sha256] + /// /// Optionally pass enrollmentId if the client is enrolled using APKAM Future pkamAuthenticate({String? enrollmentId}); + /// Generates digest using from verb response and [secret] and performs a + /// CRAM authentication to secondary server + Future cramAuthenticate(var secret); + + /// Terminates the underlying connection to the atServer + /// used by this instance of AtLookup + Future close(); + /// set an instance of [AtChops] for signing and verification operations. set atChops(AtChops? atChops); From 29908d8ef576953937c4648b046fefd0f3422335 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 19 Oct 2023 02:37:59 +0530 Subject: [PATCH 3/5] docs: update changelog --- packages/at_lookup/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/at_lookup/CHANGELOG.md b/packages/at_lookup/CHANGELOG.md index e388a100..7f2fd00e 100644 --- a/packages/at_lookup/CHANGELOG.md +++ b/packages/at_lookup/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.0.41 +- feat: introduce methods cramAuthenticate and close into the AtLookup interface +- deprecate: authenticate_cram() from AtLookupImpl. [cramAuthenticate should be used instead] ## 3.0.40 - feat: make `SecondaryUrlFinder` (atServer address lookup) resilient to transient failures to reach an atDirectory From 32fb2bc5e797a2adcf5af23132a94e2b746bcbae Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 19 Oct 2023 02:42:46 +0530 Subject: [PATCH 4/5] docs: update package version to 3.0.41 and upgrade dependencies to latest version --- packages/at_lookup/CHANGELOG.md | 1 + packages/at_lookup/pubspec.yaml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/at_lookup/CHANGELOG.md b/packages/at_lookup/CHANGELOG.md index 7f2fd00e..58c6b83b 100644 --- a/packages/at_lookup/CHANGELOG.md +++ b/packages/at_lookup/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.0.41 - feat: introduce methods cramAuthenticate and close into the AtLookup interface - deprecate: authenticate_cram() from AtLookupImpl. [cramAuthenticate should be used instead] +- build(deps): Upgrade at_commons to v3.0.57 and at_chops to v1.0.5 ## 3.0.40 - feat: make `SecondaryUrlFinder` (atServer address lookup) resilient to transient failures to reach an atDirectory diff --git a/packages/at_lookup/pubspec.yaml b/packages/at_lookup/pubspec.yaml index 0986789f..cd7eb98a 100644 --- a/packages/at_lookup/pubspec.yaml +++ b/packages/at_lookup/pubspec.yaml @@ -1,6 +1,6 @@ name: at_lookup description: A Dart library that contains the core commands that can be used with a secondary server (scan, update, lookup, llookup, plookup, etc.) -version: 3.0.40 +version: 3.0.41 repository: https://github.com/atsign-foundation/at_libraries homepage: https://atsign.com documentation: https://docs.atsign.com/ @@ -13,11 +13,11 @@ dependencies: crypton: ^2.0.1 crypto: ^3.0.1 at_utils: ^3.0.15 - at_commons: ^3.0.53 + at_commons: ^3.0.57 mutex: ^3.0.0 mocktail: ^0.3.0 meta: ^1.8.0 - at_chops: ^1.0.4 + at_chops: ^1.0.5 dev_dependencies: lints: ^1.0.1 From 6deb45fd82f18e34b0f25c9491a8033bbc0c4fe6 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Fri, 20 Oct 2023 21:03:54 +0530 Subject: [PATCH 5/5] fix: change param type of secret to String in AtLookup.cramAuthenticate() --- packages/at_lookup/lib/src/at_lookup.dart | 2 +- packages/at_lookup/lib/src/at_lookup_impl.dart | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/at_lookup/lib/src/at_lookup.dart b/packages/at_lookup/lib/src/at_lookup.dart index 404f2904..c8bb9cdf 100644 --- a/packages/at_lookup/lib/src/at_lookup.dart +++ b/packages/at_lookup/lib/src/at_lookup.dart @@ -39,7 +39,7 @@ abstract class AtLookUp { /// Generates digest using from verb response and [secret] and performs a /// CRAM authentication to secondary server - Future cramAuthenticate(var secret); + Future cramAuthenticate(String secret); /// Terminates the underlying connection to the atServer /// used by this instance of AtLookup diff --git a/packages/at_lookup/lib/src/at_lookup_impl.dart b/packages/at_lookup/lib/src/at_lookup_impl.dart index 01efbd09..07aa54c4 100644 --- a/packages/at_lookup/lib/src/at_lookup_impl.dart +++ b/packages/at_lookup/lib/src/at_lookup_impl.dart @@ -493,11 +493,7 @@ class AtLookupImpl implements AtLookUp { final Mutex _cramAuthenticationMutex = Mutex(); @override - Future cramAuthenticate(var secret) async { - secret ??= cramSecret; - if (secret == null) { - throw UnAuthenticatedException('Cram secret not passed'); - } + Future cramAuthenticate(String secret) async { await createConnection(); try { await _cramAuthenticationMutex.acquire(); @@ -534,8 +530,13 @@ class AtLookupImpl implements AtLookUp { @Deprecated('use AtLookup().cramAuthenticate()') // ignore: non_constant_identifier_names - Future authenticate_cram(var secret) async => - await cramAuthenticate(secret); + Future authenticate_cram(var secret) async { + secret ??= cramSecret; + if (secret == null) { + throw UnAuthenticatedException('Cram secret not passed'); + } + return await cramAuthenticate(secret); + } Future _plookup(PLookupVerbBuilder builder) async { var atCommand = builder.buildCommand(); @@ -576,7 +577,7 @@ class AtLookupImpl implements AtLookUp { logger.finer('calling pkam without atchops'); await authenticate(privateKey); } else if (cramSecret != null) { - await cramAuthenticate(cramSecret); + await cramAuthenticate(cramSecret!); } else { throw UnAuthenticatedException( 'Unable to perform atLookup auth. Private key/cram secret is not set');