From 1a7ad25d624f3742530e9fe50dfce546105e3c01 Mon Sep 17 00:00:00 2001 From: srieteja Date: Thu, 11 Jul 2024 13:54:55 +0530 Subject: [PATCH 1/9] feat: introduce at_signing_algo and hashing_algo in at_auth --- packages/at_auth/lib/src/at_auth_impl.dart | 8 +++++--- packages/at_auth/lib/src/auth/at_auth_request.dart | 7 +++++++ .../at_auth/lib/src/onboard/at_onboarding_request.dart | 7 +++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/at_auth/lib/src/at_auth_impl.dart b/packages/at_auth/lib/src/at_auth_impl.dart index acc62c53..0533597e 100644 --- a/packages/at_auth/lib/src/at_auth_impl.dart +++ b/packages/at_auth/lib/src/at_auth_impl.dart @@ -74,9 +74,9 @@ class AtAuthImpl implements AtAuth { } atLookUp ??= AtLookupImpl( atAuthRequest.atSign, atAuthRequest.rootDomain, atAuthRequest.rootPort); - var atChops = _createAtChops(atAuthKeys); - this.atChops = atChops; - atLookUp!.atChops = atChops; + atLookUp?.signingAlgoType = atAuthRequest.signingAlgoType; + atLookUp?.hashingAlgoType = atAuthRequest.hashingAlgoType; + atLookUp!.atChops = atChops = _createAtChops(atAuthKeys); _logger.finer('Authenticating using PKAM'); var isPkamAuthenticated = false; pkamAuthenticator ??= PkamAuthenticator(atAuthRequest.atSign, atLookUp!); @@ -106,6 +106,8 @@ class AtAuthImpl implements AtAuth { atEnrollmentBase = AtEnrollmentImpl(atOnboardingRequest.atSign); atLookUp ??= AtLookupImpl(atOnboardingRequest.atSign, atOnboardingRequest.rootDomain, atOnboardingRequest.rootPort); + atLookUp?.signingAlgoType = atOnboardingRequest.signingAlgoType; + atLookUp?.hashingAlgoType = atOnboardingRequest.hashingAlgoType; //1. cram auth cramAuthenticator ??= diff --git a/packages/at_auth/lib/src/auth/at_auth_request.dart b/packages/at_auth/lib/src/auth/at_auth_request.dart index ae69474e..ca473494 100644 --- a/packages/at_auth/lib/src/auth/at_auth_request.dart +++ b/packages/at_auth/lib/src/auth/at_auth_request.dart @@ -1,4 +1,5 @@ import 'package:at_auth/src/keys/at_auth_keys.dart'; +import 'package:at_chops/at_chops.dart'; import 'package:at_commons/at_commons.dart'; /// Represents an authentication request of an atSign. @@ -31,4 +32,10 @@ class AtAuthRequest { /// public key id from secure element if [authMode] is [PkamAuthMode.sim] String? publicKeyId; + + /// Signing algorithm to use for pkam authentication + SigningAlgoType signingAlgoType = SigningAlgoType.rsa2048; + + /// Hashing algorithm to use for pkam authentication + HashingAlgoType hashingAlgoType = HashingAlgoType.sha256; } diff --git a/packages/at_auth/lib/src/onboard/at_onboarding_request.dart b/packages/at_auth/lib/src/onboard/at_onboarding_request.dart index 1c0c071d..f286d51c 100644 --- a/packages/at_auth/lib/src/onboard/at_onboarding_request.dart +++ b/packages/at_auth/lib/src/onboard/at_onboarding_request.dart @@ -1,3 +1,4 @@ +import 'package:at_chops/at_chops.dart'; import 'package:at_commons/at_commons.dart'; class AtOnboardingRequest { @@ -13,4 +14,10 @@ class AtOnboardingRequest { /// public key id if [authMode] is [PkamAuthMode.sim] String? publicKeyId; + + /// Signing algorithm to use for cram authentication + SigningAlgoType signingAlgoType = SigningAlgoType.rsa2048; + + /// Hashing algorithm to use for cram authentication + HashingAlgoType hashingAlgoType = HashingAlgoType.sha256; } From 46b986480440844131493b22f54c577670193d3a Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Mon, 29 Jul 2024 16:27:21 +0530 Subject: [PATCH 2/9] fix: handle edge cases for sim auth + minor refactoring --- packages/at_auth/lib/src/at_auth_impl.dart | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/at_auth/lib/src/at_auth_impl.dart b/packages/at_auth/lib/src/at_auth_impl.dart index 4c8935f8..7c61a519 100644 --- a/packages/at_auth/lib/src/at_auth_impl.dart +++ b/packages/at_auth/lib/src/at_auth_impl.dart @@ -72,13 +72,12 @@ class AtAuthImpl implements AtAuth { 'Unable to read PkamPrivateKey from provided atKeys file/atAuthKeys object', exceptionScenario: ExceptionScenario.invalidValueProvided); } - atLookUp ??= AtLookupImpl( - atAuthRequest.atSign, atAuthRequest.rootDomain, atAuthRequest.rootPort); - atLookUp?.signingAlgoType = atAuthRequest.signingAlgoType; - atLookUp?.hashingAlgoType = atAuthRequest.hashingAlgoType; - atLookUp!.atChops = atChops = _createAtChops(atAuthKeys); // ??= to support mocking atChops ??= _createAtChops(atAuthKeys); + atLookUp ??= AtLookupImpl( + atAuthRequest.atSign, atAuthRequest.rootDomain, atAuthRequest.rootPort); + atLookUp!.signingAlgoType = atAuthRequest.signingAlgoType; + atLookUp!.hashingAlgoType = atAuthRequest.hashingAlgoType; atLookUp!.atChops = atChops; _logger.finer('Authenticating using PKAM'); @@ -106,6 +105,11 @@ class AtAuthImpl implements AtAuth { @override Future onboard( AtOnboardingRequest atOnboardingRequest, String cramSecret) async { + if (atOnboardingRequest.authMode == PkamAuthMode.sim && atChops == null) { + throw AtPublicKeyNotFoundException( + 'AtChops cannot be null when AuthMode is sim. ' + 'PKAMPublicKey needs to be read from sim using AtChops'); + } var atOnboardingResponse = AtOnboardingResponse(atOnboardingRequest.atSign); atEnrollmentBase = AtEnrollmentImpl(atOnboardingRequest.atSign); atLookUp ??= AtLookupImpl(atOnboardingRequest.atSign, @@ -145,8 +149,8 @@ class AtAuthImpl implements AtAuth { } //5. Init _atLookUp again and attempt pkam auth - // atLookUp = AtLookupImpl(atOnboardingRequest.atSign, - // atOnboardingRequest.rootDomain, atOnboardingRequest.rootPort); + atLookUp = AtLookupImpl(atOnboardingRequest.atSign, + atOnboardingRequest.rootDomain, atOnboardingRequest.rootPort); atLookUp!.atChops = atChops; var isPkamAuthenticated = false; @@ -161,7 +165,7 @@ class AtAuthImpl implements AtAuth { throw AtAuthenticationException('Pkam auth failed - $e '); } if (!isPkamAuthenticated) { - throw AtAuthenticationException('Pkam auth returned false'); + throw AtAuthenticationException('Pkam auth unsuccessful'); } //7. If Pkam auth is success, update encryption public key to secondary @@ -331,7 +335,7 @@ class AtAuthImpl implements AtAuth { } else if (authMode == PkamAuthMode.sim) { // get the public key from secure element pkamPublicKey = atChops!.readPublicKey(publicKeyId!); - _logger.info('pkam public key from sim: ${atKeysFile.apkamPublicKey}'); + _logger.info('PKAM public key from sim: $pkamPublicKey'); // encryption key pair and self encryption symmetric key // are not available to injected at_chops. Set it here @@ -340,8 +344,8 @@ class AtAuthImpl implements AtAuth { atChops!.atChopsKeys.apkamSymmetricKey = apkamSymmetricKey; } atKeysFile.apkamPublicKey = pkamPublicKey; - //Standard order of an atKeys file is -> - // pkam keypair -> encryption keypair -> selfEncryption key -> enrollmentId --> apkam symmetric key --> + // Standard order of an atKeys file is -> pkam keypair -> encryption keypair + // --> selfEncryption key -> enrollmentId --> apkam symmetric key --> // @sign: selfEncryptionKey[self encryption key again] // note: "->" stands for "followed by" atKeysFile.defaultEncryptionPublicKey = From 56f7d8be8b937f6cbde8f3e352304e18ea767dc1 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Mon, 29 Jul 2024 16:30:22 +0530 Subject: [PATCH 3/9] fix: populate hashing and signing algo in onb_cli when calling onboard/authenticate in at_auth --- packages/at_auth/lib/src/auth/cram_authenticator.dart | 3 +-- packages/at_auth/lib/src/auth/pkam_authenticator.dart | 3 +-- .../lib/src/onboard/at_onboarding_response.dart | 2 +- .../lib/src/onboard/at_onboarding_service_impl.dart | 11 +++++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/at_auth/lib/src/auth/cram_authenticator.dart b/packages/at_auth/lib/src/auth/cram_authenticator.dart index d88ec55e..8d185e7e 100644 --- a/packages/at_auth/lib/src/auth/cram_authenticator.dart +++ b/packages/at_auth/lib/src/auth/cram_authenticator.dart @@ -12,9 +12,8 @@ class CramAuthenticator { Future authenticate() async { var authResult = AtAuthResponse(_atSign); try { - bool cramResult = + authResult.isSuccessful = await (atLookup as AtLookupImpl).cramAuthenticate(_cramSecret); - authResult.isSuccessful = cramResult; } on UnAuthenticatedException catch (e) { throw UnAuthenticatedException( 'cram auth failed for $_atSign - ${e.toString()}'); diff --git a/packages/at_auth/lib/src/auth/pkam_authenticator.dart b/packages/at_auth/lib/src/auth/pkam_authenticator.dart index af97be7a..3fa08f66 100644 --- a/packages/at_auth/lib/src/auth/pkam_authenticator.dart +++ b/packages/at_auth/lib/src/auth/pkam_authenticator.dart @@ -10,9 +10,8 @@ class PkamAuthenticator { Future authenticate({String? enrollmentId}) async { var authResult = AtAuthResponse(_atSign); try { - bool pkamResult = + authResult.isSuccessful = await _atLookup.pkamAuthenticate(enrollmentId: enrollmentId); - authResult.isSuccessful = pkamResult; } on UnAuthenticatedException catch (e) { throw UnAuthenticatedException( 'pkam auth failed for $_atSign - ${e.toString()}'); diff --git a/packages/at_auth/lib/src/onboard/at_onboarding_response.dart b/packages/at_auth/lib/src/onboard/at_onboarding_response.dart index 28c422dd..0079eaad 100644 --- a/packages/at_auth/lib/src/onboard/at_onboarding_response.dart +++ b/packages/at_auth/lib/src/onboard/at_onboarding_response.dart @@ -9,6 +9,6 @@ class AtOnboardingResponse { @override String toString() { - return 'AtOnboardingResponse{atSign: $atSign, enrollmentId: $enrollmentId, isSuccessful: $isSuccessful}'; + return 'AtOnboardingResponse: {atSign: $atSign, enrollmentId: $enrollmentId, isSuccessful: $isSuccessful}'; } } 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 b65b3843..034a64c1 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 @@ -116,6 +116,10 @@ class AtOnboardingServiceImpl implements AtOnboardingService { atOnboardingRequest.deviceName = atOnboardingPreference.deviceName; atOnboardingRequest.publicKeyId = atOnboardingPreference.publicKeyId; atOnboardingRequest.authMode = atOnboardingPreference.authMode; + atOnboardingRequest.signingAlgoType = + atOnboardingPreference.signingAlgoType; + atOnboardingRequest.hashingAlgoType = + atOnboardingPreference.hashingAlgoType; AtOnboardingResponse atOnboardingResponse = await atAuth! .onboard(atOnboardingRequest, atOnboardingPreference.cramSecret!); @@ -481,7 +485,9 @@ class AtOnboardingServiceImpl implements AtOnboardingService { ..authMode = atOnboardingPreference.authMode ..rootDomain = atOnboardingPreference.rootDomain ..rootPort = atOnboardingPreference.rootPort - ..publicKeyId = atOnboardingPreference.publicKeyId; + ..publicKeyId = atOnboardingPreference.publicKeyId + ..signingAlgoType = atOnboardingPreference.signingAlgoType + ..hashingAlgoType = atOnboardingPreference.hashingAlgoType; var atAuthResponse = await atAuth!.authenticate(atAuthRequest); logger.finer('Auth response: $atAuthResponse'); if (atAuthResponse.isSuccessful && @@ -654,7 +660,8 @@ class AtOnboardingServiceImpl implements AtOnboardingService { @override Future close() async { logger.info('Closing'); - if (_atLookUp != null && (_atLookUp as AtLookupImpl).isConnectionAvailable()) { + if (_atLookUp != null && + (_atLookUp as AtLookupImpl).isConnectionAvailable()) { await _atLookUp!.close(); } atClient?.notificationService.stopAllSubscriptions(); From 90e742c9a0aade63de82b65a0d2b3248256cc686 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Mon, 29 Jul 2024 16:30:50 +0530 Subject: [PATCH 4/9] test: add expect statements to validate current changes --- .../test/ecc_secure_element_mock_test.dart | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart b/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart index 543559bb..40f51135 100644 --- a/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart +++ b/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart @@ -11,13 +11,14 @@ import 'package:at_demo_data/at_demo_data.dart' as at_demos; import 'utils/at_chops_secure_element_mock.dart'; import 'package:at_auth/at_auth.dart' as at_auth; import 'utils/onboarding_service_impl_override.dart'; +import 'package:at_auth/src/at_auth_impl.dart'; /// Usage: dart main.dart void main() { AtSignLogger.root_level = 'WARNING'; var logger = AtSignLogger('OnboardSecureElementTest'); - final atSign = '@egcreditbureau🛠'.trim(); + test('Test auth functionality using secure element mock', () async { AtOnboardingPreference preference = getPreferences(atSign); AtOnboardingService onboardingService = @@ -25,14 +26,11 @@ void main() { // create empty keys in AtChops. Encryption key pair will be set later on after generation final atChopsImpl = AtChopsSecureElementMock(AtChopsKeys.create(null, null)); - AtLookUp atLookupInstance = - AtLookupImpl(atSign, preference.rootDomain, preference.rootPort); - atLookupInstance.signingAlgoType = preference.signingAlgoType; - atLookupInstance.hashingAlgoType = preference.hashingAlgoType; at_auth.AtAuth atAuthInstance = at_auth.atAuthBase - .atAuth(atLookUp: atLookupInstance, atChops: atChopsImpl); + .atAuth(atChops: atChopsImpl); onboardingService.atAuth = atAuthInstance; atChopsImpl.init(); + logger.info('Onboarding the atSign: $atSign'); bool isOnboarded = await onboardingService.onboard(); expect(isOnboarded, true); @@ -44,7 +42,7 @@ void main() { logger.info('Authentication completed successfully for atSign: $atSign'); // update a key - AtClient? atClient = await onboardingService.atClient; + AtClient? atClient = onboardingService.atClient; await insertSelfEncKey(atClient, atSign, selfEncryptionKey: await getSelfEncryptionKey(preference.atKeysFilePath!)); @@ -60,6 +58,11 @@ void main() { var deleteResponse = await atClient?.delete(key); stdout.writeln('[Test] Got Delete Response: $deleteResponse'); expect(deleteResponse, true); + // validate that signing algo and hashing algo set in AtOnboardingPreference + // is passed forward to AtAuth instance + AtLookupImpl? atLookupImpl = (onboardingService.atAuth as AtAuthImpl).atLookUp as AtLookupImpl?; + expect(atLookupImpl!.signingAlgoType, SigningAlgoType.ecc_secp256r1); + expect(atLookupImpl.hashingAlgoType, HashingAlgoType.sha256); }); tearDown(() async { @@ -79,7 +82,7 @@ AtOnboardingPreference getPreferences(String atSign) { ..commitLogPath = 'storage/commitLog' ..rootDomain = 'vip.ve.atsign.zone' ..fetchOfflineNotifications = true - ..atKeysFilePath = 'test/storage/files/$atSign' + '_key.atKeys' + ..atKeysFilePath = 'test/storage/files/${atSign}_key.atKeys' ..signingAlgoType = SigningAlgoType.ecc_secp256r1 ..hashingAlgoType = HashingAlgoType.sha256 ..authMode = PkamAuthMode.sim From 80ee358b9c1edc570d0697cfd75b3a6ed0660c78 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Mon, 29 Jul 2024 16:31:15 +0530 Subject: [PATCH 5/9] build[deps]: use dep override for at_auth in onb_cli --- packages/at_onboarding_cli/pubspec.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/at_onboarding_cli/pubspec.yaml b/packages/at_onboarding_cli/pubspec.yaml index 05e3f2c3..adc38965 100644 --- a/packages/at_onboarding_cli/pubspec.yaml +++ b/packages/at_onboarding_cli/pubspec.yaml @@ -31,6 +31,10 @@ dependencies: at_cli_commons: ^1.1.0 at_persistence_secondary_server: ^3.0.62 +dependency_overrides: + at_auth: + path: ../at_auth + dev_dependencies: lints: ^2.1.0 test: ^1.24.2 From a6cb627c7232a97fda975c70f7213a85dc0f8a77 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Mon, 29 Jul 2024 16:45:03 +0530 Subject: [PATCH 6/9] fix: do not create a new AtLookup instance in AtAuthImpl.onboard() --- packages/at_auth/lib/src/at_auth_impl.dart | 13 ++++--------- .../test/ecc_secure_element_mock_test.dart | 9 +++++---- .../test/utils/at_chops_secure_element_mock.dart | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/at_auth/lib/src/at_auth_impl.dart b/packages/at_auth/lib/src/at_auth_impl.dart index 7c61a519..357801f8 100644 --- a/packages/at_auth/lib/src/at_auth_impl.dart +++ b/packages/at_auth/lib/src/at_auth_impl.dart @@ -141,20 +141,15 @@ class AtAuthImpl implements AtAuth { atOnboardingRequest, atAuthKeys, atLookUp!); atAuthKeys.enrollmentId = enrollmentIdFromServer; - //4. Close connection to server + //4. Close existing authenticated connection to server try { await (atLookUp as AtLookupImpl).close(); } on Exception catch (e) { _logger.severe('error while closing connection to server: $e'); } - //5. Init _atLookUp again and attempt pkam auth - atLookUp = AtLookupImpl(atOnboardingRequest.atSign, - atOnboardingRequest.rootDomain, atOnboardingRequest.rootPort); - atLookUp!.atChops = atChops; - var isPkamAuthenticated = false; - //6. Do pkam auth + //5. Do pkam auth pkamAuthenticator ??= PkamAuthenticator(atOnboardingRequest.atSign, atLookUp!); try { @@ -168,7 +163,7 @@ class AtAuthImpl implements AtAuth { throw AtAuthenticationException('Pkam auth unsuccessful'); } - //7. If Pkam auth is success, update encryption public key to secondary + //6. If Pkam auth is success, update encryption public key to secondary // and delete cram key from server final encryptionPublicKey = atAuthKeys.defaultEncryptionPublicKey; UpdateVerbBuilder updateBuilder = UpdateVerbBuilder() @@ -180,7 +175,7 @@ class AtAuthImpl implements AtAuth { String? encryptKeyUpdateResult = await atLookUp!.executeVerb(updateBuilder); _logger.info('Encryption public key update result $encryptKeyUpdateResult'); - //8. Delete cram secret from the keystore as cram auth is complete + //7. Delete cram secret from the keystore as cram auth is complete DeleteVerbBuilder deleteBuilder = DeleteVerbBuilder() ..atKey = (AtKey()..key = AtConstants.atCramSecret); String? deleteResponse = await atLookUp!.executeVerb(deleteBuilder); diff --git a/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart b/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart index 40f51135..c26f98a8 100644 --- a/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart +++ b/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart @@ -19,15 +19,15 @@ void main() { var logger = AtSignLogger('OnboardSecureElementTest'); final atSign = '@egcreditbureau🛠'.trim(); - test('Test auth functionality using secure element mock', () async { + test('Validate auth functionality using secure element mock', () async { AtOnboardingPreference preference = getPreferences(atSign); AtOnboardingService onboardingService = OnboardingServiceImplOverride(atSign, preference); // create empty keys in AtChops. Encryption key pair will be set later on after generation final atChopsImpl = AtChopsSecureElementMock(AtChopsKeys.create(null, null)); - at_auth.AtAuth atAuthInstance = at_auth.atAuthBase - .atAuth(atChops: atChopsImpl); + at_auth.AtAuth atAuthInstance = + at_auth.atAuthBase.atAuth(atChops: atChopsImpl); onboardingService.atAuth = atAuthInstance; atChopsImpl.init(); @@ -60,7 +60,8 @@ void main() { expect(deleteResponse, true); // validate that signing algo and hashing algo set in AtOnboardingPreference // is passed forward to AtAuth instance - AtLookupImpl? atLookupImpl = (onboardingService.atAuth as AtAuthImpl).atLookUp as AtLookupImpl?; + AtLookupImpl? atLookupImpl = + (onboardingService.atAuth as AtAuthImpl).atLookUp as AtLookupImpl?; expect(atLookupImpl!.signingAlgoType, SigningAlgoType.ecc_secp256r1); expect(atLookupImpl.hashingAlgoType, HashingAlgoType.sha256); }); diff --git a/tests/at_onboarding_cli_functional_tests/test/utils/at_chops_secure_element_mock.dart b/tests/at_onboarding_cli_functional_tests/test/utils/at_chops_secure_element_mock.dart index e40207a7..03038c8c 100644 --- a/tests/at_onboarding_cli_functional_tests/test/utils/at_chops_secure_element_mock.dart +++ b/tests/at_onboarding_cli_functional_tests/test/utils/at_chops_secure_element_mock.dart @@ -29,7 +29,7 @@ class AtChopsSecureElementMock extends AtChopsImpl { ..result = base64Signature ..atSigningMetaData = atSigningMetadata ..atSigningResultType = AtSigningResultType.string; - print('at signing result: $atSigningResult'); + print('[AtChopsSecureElementMock] AtSigningResult: $atSigningResult'); return atSigningResult; } @@ -46,7 +46,7 @@ class AtChopsSecureElementMock extends AtChopsImpl { @override String readPublicKey(String publicKeyId) { - print('public key in read public key: ${eccPublicKey.toString()}'); + print('[AtChopsSecureElementMock] Reading public key from SIM: ${eccPublicKey.toString()}'); return eccPublicKey.toString(); } } From 66f034e3426d325577ab9f04d57bf9f2c3b250fb Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Tue, 30 Jul 2024 16:59:29 +0530 Subject: [PATCH 7/9] test: add functional test to validate changes --- .../test/at_onboarding_cli_test.dart | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart b/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart index 97709459..78a9cdae 100644 --- a/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart +++ b/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart @@ -9,6 +9,8 @@ import 'package:at_onboarding_cli/src/activate_cli/activate_cli.dart' as activate_cli; import 'package:at_utils/at_utils.dart'; import 'package:test/test.dart'; +import 'package:at_auth/src/at_auth_impl.dart'; +import 'package:at_chops/at_chops.dart'; import 'utils/onboarding_service_impl_override.dart'; @@ -77,7 +79,7 @@ void main() { AtOnboardingService onboardingService = AtOnboardingServiceImpl(atSign, preference); await onboardingService.authenticate(); - AtClient? atClient = await onboardingService.atClient; + AtClient? atClient = onboardingService.atClient; AtKey key = AtKey(); key.key = 'testKey3'; key.namespace = 'wavi'; @@ -86,6 +88,32 @@ void main() { expect('value3', response?.value); }); + test( + 'validate that signing algo and hashing algo set in AtOnboardingPreference is passed forward to AtAuth instance', + () async { + /// test is being skipped as sha512 is not being recognized by at_server + /// as a valid hashing algo although at_chops supports sha512. This + /// test can be un-skipped once this bug has been resolved + String atSign = '@eve🛠'; + await _createKeys(atSign); + AtOnboardingPreference preference = getPreferences(atSign); + await generateAtKeysFile(atSign, preference.atKeysFilePath!); + SigningAlgoType signingAlgo = SigningAlgoType.rsa2048; + HashingAlgoType hashingAlgo = HashingAlgoType.sha512; + preference.hashingAlgoType = hashingAlgo; + preference.signingAlgoType = signingAlgo; + AtOnboardingService onboardingService = + AtOnboardingServiceImpl(atSign, preference); + await onboardingService.authenticate(); + // validating on the atLookup instance in AtAuth to ensure that the algo's + // passed through OnboardingPref are passed to the AtLookup instance that + // communicates with the at_server + AtLookupImpl? atLookupImpl = + (onboardingService.atAuth as AtAuthImpl).atLookUp as AtLookupImpl?; + expect(atLookupImpl!.signingAlgoType, signingAlgo); + expect(atLookupImpl.hashingAlgoType, hashingAlgo); + }, skip: true); + test('A test to verify atKeysFilePath is set when null is provided', () async { String atSign = '@eve🛠'; @@ -115,7 +143,7 @@ void main() { await generateAtKeysFile(atSign, atOnboardingPreference.atKeysFilePath!); await _createKeys(atSign); bool status = await atOnboardingService.authenticate(); - atClient = await atOnboardingService.atClient; + atClient = atOnboardingService.atClient; expect(true, status); expect(at_demos.pkamPrivateKeyMap[atSign], @@ -146,6 +174,7 @@ void main() { () async { AtOnboardingService atOnboardingService = AtOnboardingServiceImpl(atSign, atOnboardingPreference); + bool status = await atOnboardingService.onboard(); expect(status, true); bool status2 = await atOnboardingService.authenticate(); @@ -165,9 +194,6 @@ void main() { // Skipping this test until the issue can be resolved group('A group of tests to verify activate_cli', () { String atSign = '@murali🛠'; - AtOnboardingPreference onboardingPreference = getPreferences(atSign); - AtOnboardingService onboardingService = - OnboardingServiceImplOverride(atSign, onboardingPreference); test( 'A test to verify atSign is activated and .atKeys file is generated using activate_cli', () async { @@ -182,10 +208,9 @@ void main() { // perform activation of atSign await activate_cli.wrappedMain(args); - /// ToDo: test should NOT exit with status 0 after activation is complete - /// Exiting with status 0 is ideal behaviour, but for the sake of the test we need to be - /// able to run the following assertions. - + AtOnboardingPreference onboardingPreference = getPreferences(atSign); + AtOnboardingService onboardingService = + AtOnboardingServiceImpl(atSign, onboardingPreference); // Authenticate atSign with the .atKeys file generated via the activate_cli tool expect(await File(onboardingPreference.atKeysFilePath!).exists(), true); expect(await onboardingService.authenticate(), true); From 2c0e62c23f80077c61e1d6863e4d9fa5b701c10c Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Tue, 30 Jul 2024 17:00:36 +0530 Subject: [PATCH 8/9] build[deps]: remove dep override --- packages/at_onboarding_cli/pubspec.yaml | 4 ---- .../test/ecc_secure_element_mock_test.dart | 8 -------- 2 files changed, 12 deletions(-) diff --git a/packages/at_onboarding_cli/pubspec.yaml b/packages/at_onboarding_cli/pubspec.yaml index af5d22a1..ead9d993 100644 --- a/packages/at_onboarding_cli/pubspec.yaml +++ b/packages/at_onboarding_cli/pubspec.yaml @@ -31,10 +31,6 @@ dependencies: at_cli_commons: ^1.1.0 at_persistence_secondary_server: ^3.0.62 -dependency_overrides: - at_auth: - path: ../at_auth - dev_dependencies: lints: ^2.1.0 test: ^1.24.2 diff --git a/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart b/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart index c26f98a8..1e963828 100644 --- a/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart +++ b/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart @@ -3,7 +3,6 @@ import 'dart:io'; import 'package:at_chops/at_chops.dart'; import 'package:at_client/at_client.dart'; -import 'package:at_lookup/at_lookup.dart'; import 'package:at_onboarding_cli/at_onboarding_cli.dart'; import 'package:at_utils/at_logger.dart'; import 'package:test/test.dart'; @@ -11,7 +10,6 @@ import 'package:at_demo_data/at_demo_data.dart' as at_demos; import 'utils/at_chops_secure_element_mock.dart'; import 'package:at_auth/at_auth.dart' as at_auth; import 'utils/onboarding_service_impl_override.dart'; -import 'package:at_auth/src/at_auth_impl.dart'; /// Usage: dart main.dart void main() { @@ -58,12 +56,6 @@ void main() { var deleteResponse = await atClient?.delete(key); stdout.writeln('[Test] Got Delete Response: $deleteResponse'); expect(deleteResponse, true); - // validate that signing algo and hashing algo set in AtOnboardingPreference - // is passed forward to AtAuth instance - AtLookupImpl? atLookupImpl = - (onboardingService.atAuth as AtAuthImpl).atLookUp as AtLookupImpl?; - expect(atLookupImpl!.signingAlgoType, SigningAlgoType.ecc_secp256r1); - expect(atLookupImpl.hashingAlgoType, HashingAlgoType.sha256); }); tearDown(() async { From 498bc9ce77eaec98ba43eaabc97c5eca5c449865 Mon Sep 17 00:00:00 2001 From: Sri Teja T Date: Tue, 8 Oct 2024 23:46:01 +0530 Subject: [PATCH 9/9] test: unskip functional test --- .../test/at_onboarding_cli_test.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart b/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart index 78a9cdae..c28f217c 100644 --- a/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart +++ b/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart @@ -91,9 +91,6 @@ void main() { test( 'validate that signing algo and hashing algo set in AtOnboardingPreference is passed forward to AtAuth instance', () async { - /// test is being skipped as sha512 is not being recognized by at_server - /// as a valid hashing algo although at_chops supports sha512. This - /// test can be un-skipped once this bug has been resolved String atSign = '@eve🛠'; await _createKeys(atSign); AtOnboardingPreference preference = getPreferences(atSign); @@ -112,7 +109,7 @@ void main() { (onboardingService.atAuth as AtAuthImpl).atLookUp as AtLookupImpl?; expect(atLookupImpl!.signingAlgoType, signingAlgo); expect(atLookupImpl.hashingAlgoType, hashingAlgo); - }, skip: true); + }); test('A test to verify atKeysFilePath is set when null is provided', () async {