From beaccd82c8a2eaf1a79154f6ee13b498c5357d56 Mon Sep 17 00:00:00 2001 From: murali-shris Date: Mon, 9 Oct 2023 17:09:40 +0530 Subject: [PATCH] feat: replace onboard impl with at_auth.onboard --- .../at_onboarding_cli/example/onboard.dart | 9 ++-- .../onboard/at_onboarding_service_impl.dart | 47 +++++++------------ .../lib/src/onboard/at_security_keys.dart | 12 ----- packages/at_onboarding_cli/pubspec.yaml | 12 +++++ 4 files changed, 34 insertions(+), 46 deletions(-) delete mode 100644 packages/at_onboarding_cli/lib/src/onboard/at_security_keys.dart diff --git a/packages/at_onboarding_cli/example/onboard.dart b/packages/at_onboarding_cli/example/onboard.dart index 3c5fe939..dcec9787 100644 --- a/packages/at_onboarding_cli/example/onboard.dart +++ b/packages/at_onboarding_cli/example/onboard.dart @@ -2,17 +2,18 @@ import 'package:at_onboarding_cli/at_onboarding_cli.dart'; import 'package:at_utils/at_logger.dart'; Future main() async { - AtSignLogger.root_level = 'info'; - final atSign = '@alice'; + AtSignLogger.root_level = 'finest'; + final atSign = '@aliceđź› '; AtOnboardingPreference atOnboardingPreference = AtOnboardingPreference() ..namespace = 'wavi' // unique identifier that can be used to identify data from your app ..cramSecret = 'b26455a907582760ebf35bc4847de549bc41c24b25c8b1c58d5964f7b4f8a43bc55b0e9a601c9a9657d9a8b8bbc32f88b4e38ffaca03c8710ebae1b14ca9f364' - ..atKeysFilePath = '/home/murali/atsign/alice_key.atKeys' + ..atKeysFilePath = '/home/murali/.atsign/@aliceđź› _key.atKeys' ..appName = 'wavi' ..deviceName = 'pixel' - ..rootDomain = 'vip.ve.atsign.zone'; + ..rootDomain = 'vip.ve.atsign.zone' + ..enableEnrollmentDuringOnboard = true; AtOnboardingService? onboardingService = AtOnboardingServiceImpl(atSign, atOnboardingPreference); await onboardingService.onboard(); diff --git a/packages/at_onboarding_cli/lib/src/onboard/at_onboarding_service_impl.dart b/packages/at_onboarding_cli/lib/src/onboard/at_onboarding_service_impl.dart index 2c368d7d..f9ca31c6 100644 --- a/packages/at_onboarding_cli/lib/src/onboard/at_onboarding_service_impl.dart +++ b/packages/at_onboarding_cli/lib/src/onboard/at_onboarding_service_impl.dart @@ -6,7 +6,7 @@ import 'dart:io'; import 'package:at_chops/at_chops.dart'; import 'package:at_client/at_client.dart'; -import 'package:at_onboarding_cli/src/onboard/at_security_keys.dart'; +import 'package:at_auth/at_auth.dart'; import 'package:at_onboarding_cli/src/util/at_onboarding_exceptions.dart'; import 'package:at_server_status/at_server_status.dart'; import 'package:at_utils/at_utils.dart'; @@ -118,35 +118,22 @@ class AtOnboardingServiceImpl implements AtOnboardingService { // check and wait till secondary exists await _waitUntilSecondaryCreated(atLookUpImpl); - if (await isOnboarded()) { - throw AtActivateException('atsign is already activated'); - } - - try { - // authenticate into secondary using cram secret - _isAtsignOnboarded = (await atLookUpImpl - .authenticate_cram(atOnboardingPreference.cramSecret)); - - if (_isAtsignOnboarded) { - logger.info('Cram authentication successful'); - await _activateAtsign(atLookUpImpl); - } else { - throw AtActivateException( - 'Cram authentication failed. Please check the cram key' - ' and try again \n(or) contact support@atsign.com'); - } - } on Exception catch (e) { - if (e.toString().contains('Auth failed')) { - throw AtActivateException( - 'Cram authentication failed. Please check the cram key' - ' and try again \n(or) contact support@atsign.com'); - } - logger.severe('Caught exception: $e'); - } on Error catch (e, trace) { - logger.severe('Caught error: $e $trace'); - } finally { - await atLookUpImpl.close(); - } + // if (await isOnboarded()) { + // throw AtActivateException('atsign is already activated'); + // } + + var atAuthService = AtAuthImpl(); + var atOnboardingRequest = AtOnboardingRequest(_atSign); + atOnboardingRequest.rootDomain = atOnboardingPreference.rootDomain; + atOnboardingRequest.rootPort = atOnboardingPreference.rootPort; + atOnboardingRequest.enableEnrollment = + atOnboardingPreference.enableEnrollmentDuringOnboard; + atOnboardingRequest.appName = atOnboardingPreference.appName; + atOnboardingRequest.deviceName = atOnboardingPreference.deviceName; + atOnboardingRequest.publicKeyId = atOnboardingPreference.publicKeyId; + var atOnboardingResponse = await atAuthService.onboard( + atOnboardingRequest, atOnboardingPreference.cramSecret!); + print('****atOnboardingResponse: $atOnboardingResponse'); return _isAtsignOnboarded; } diff --git a/packages/at_onboarding_cli/lib/src/onboard/at_security_keys.dart b/packages/at_onboarding_cli/lib/src/onboard/at_security_keys.dart deleted file mode 100644 index e307a66c..00000000 --- a/packages/at_onboarding_cli/lib/src/onboard/at_security_keys.dart +++ /dev/null @@ -1,12 +0,0 @@ -/// Holder for different encryption keys that will be stored in .atKeys file. -/// Apkam symmetric key, enrollmentId and defaultSelfEncryptionKey will be stored in unencrypted format in .atKeys file. -/// All other values will be encrypted before saving to .atKeys file. -class AtSecurityKeys { - String? apkamPublicKey; - String? apkamPrivateKey; - String? defaultEncryptionPublicKey; - String? defaultEncryptionPrivateKey; - String? defaultSelfEncryptionKey; - String? apkamSymmetricKey; - String? enrollmentId; -} diff --git a/packages/at_onboarding_cli/pubspec.yaml b/packages/at_onboarding_cli/pubspec.yaml index 15d147d3..4041c51a 100644 --- a/packages/at_onboarding_cli/pubspec.yaml +++ b/packages/at_onboarding_cli/pubspec.yaml @@ -27,6 +27,18 @@ dependencies: http: ^0.13.6 at_chops: ^1.0.4 +dependency_overrides: + at_auth: + git: + url: https://github.com/atsign-foundation/at_libraries + path: packages/at_auth + ref: at_auth_new_package + at_chops: + git: + url: https://github.com/atsign-foundation/at_libraries + path: packages/at_chops + ref: at_auth_new_package + dev_dependencies: lints: ^2.1.0 test: ^1.24.2