Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce cramAuthenticate and close into atLookup interface #433

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/at_lookup/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +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
Expand Down
13 changes: 12 additions & 1 deletion packages/at_lookup/lib/src/at_lookup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ abstract class AtLookUp {

Future<String?> 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<bool> pkamAuthenticate({String? enrollmentId});

/// Generates digest using from verb response and [secret] and performs a
/// CRAM authentication to secondary server
Future<bool> cramAuthenticate(var secret);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename param from var secret to String secret

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change has been made as part of 6deb45f


/// Terminates the underlying connection to the atServer
/// used by this instance of AtLookup
Future<void> close();

/// set an instance of [AtChops] for signing and verification operations.
set atChops(AtChops? atChops);

Expand Down
16 changes: 10 additions & 6 deletions packages/at_lookup/lib/src/at_lookup_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class AtLookupImpl implements AtLookUp {

Future<String> _update(UpdateVerbBuilder builder) async {
String atCommand;
if (builder.operation == UPDATE_META) {
if (builder.operation == AtConstants.updateMeta) {
atCommand = builder.buildCommandForMeta();
} else {
atCommand = builder.buildCommand();
Expand Down Expand Up @@ -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<bool> authenticate_cram(var secret) async {
@override
Future<bool> cramAuthenticate(var secret) async {
secret ??= cramSecret;
if (secret == null) {
throw UnAuthenticatedException('Cram secret not passed');
Expand Down Expand Up @@ -534,6 +532,11 @@ class AtLookupImpl implements AtLookUp {
}
}

@Deprecated('use AtLookup().cramAuthenticate()')
// ignore: non_constant_identifier_names
Future<bool> authenticate_cram(var secret) async =>
await cramAuthenticate(secret);

Future<String> _plookup(PLookupVerbBuilder builder) async {
var atCommand = builder.buildCommand();
return await _process(atCommand, auth: true);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -622,6 +625,7 @@ class AtLookupImpl implements AtLookUp {
return _connection!.isInValid();
}

@override
Future<void> close() async {
await _connection!.close();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/at_lookup/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -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
Expand Down