-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #469 from atsign-foundation/no_internet
fix: update exception handling for AtLookup.findSecondary()
- Loading branch information
Showing
4 changed files
with
48 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,8 @@ class AtAuthImpl implements AtAuth { | |
} | ||
if (atAuthKeys == null) { | ||
throw AtAuthenticationException( | ||
'keys either were not provided in the AtAuthRequest, or could not be read from provided keys file'); | ||
'keys either were not provided in the AtAuthRequest,' | ||
' or could not be read from provided keys file'); | ||
} | ||
enrollmentIdFromRequest ??= atAuthKeys.enrollmentId; | ||
var pkamPrivateKey = atAuthKeys.apkamPrivateKey; | ||
|
@@ -86,10 +87,12 @@ class AtAuthImpl implements AtAuth { | |
var pkamResponse = (await pkamAuthenticator! | ||
.authenticate(enrollmentId: enrollmentIdFromRequest)); | ||
isPkamAuthenticated = pkamResponse.isSuccessful; | ||
} on Exception catch (e) { | ||
_logger.severe('Caught exception: $e'); | ||
} on AtException catch (e) { | ||
_logger.severe('Caught $e'); | ||
throw AtAuthenticationException( | ||
'Unable to authenticate- ${e.toString()}'); | ||
'Unable to authenticate | Cause: ${e.message}'); | ||
} on Exception catch (e) { | ||
throw AtAuthenticationException('Unable to authenticate | Cause: $e'); | ||
} | ||
_logger.finer( | ||
'PKAM auth result: ${isPkamAuthenticated ? 'success' : 'failed'}'); | ||
|
@@ -113,7 +116,7 @@ class AtAuthImpl implements AtAuth { | |
if (!cramAuthResult.isSuccessful) { | ||
throw AtAuthenticationException( | ||
'Cram authentication failed. Please check the cram key' | ||
' and try again \n(or) contact [email protected]'); | ||
' and try again (or) contact [email protected]'); | ||
} | ||
//2. generate key pairs | ||
var atAuthKeys = _generateKeyPairs(atOnboardingRequest.authMode, | ||
|
@@ -127,7 +130,8 @@ class AtAuthImpl implements AtAuth { | |
//3. update pkam public key through enrollment or manually based on app preference | ||
String? enrollmentIdFromServer; | ||
if (atOnboardingRequest.enableEnrollment) { | ||
// server will update the apkam public key during enrollment.So don't have to manually update in this scenario. | ||
// server will update the apkam public key during enrollment. | ||
// So don't have to manually update in this scenario. | ||
enrollmentIdFromServer = await _sendOnboardingEnrollment( | ||
atOnboardingRequest, atAuthKeys, atLookUp!); | ||
atAuthKeys.enrollmentId = enrollmentIdFromServer; | ||
|
@@ -142,20 +146,20 @@ class AtAuthImpl implements AtAuth { | |
_logger.finer('PkamPublicKey update result: $pkamUpdateResult'); | ||
} | ||
|
||
//3. Close connection to server | ||
//4. Close connection to server | ||
try { | ||
await (atLookUp as AtLookupImpl).close(); | ||
} on Exception catch (e) { | ||
_logger.severe('error while closing connection to server: $e'); | ||
} | ||
|
||
//4. Init _atLookUp again and attempt pkam auth | ||
//5. Init _atLookUp again and attempt pkam auth | ||
// atLookUp = AtLookupImpl(atOnboardingRequest.atSign, | ||
// atOnboardingRequest.rootDomain, atOnboardingRequest.rootPort); | ||
atLookUp!.atChops = atChops; | ||
|
||
var isPkamAuthenticated = false; | ||
//5. Do pkam auth | ||
//6. Do pkam auth | ||
pkamAuthenticator ??= | ||
PkamAuthenticator(atOnboardingRequest.atSign, atLookUp!); | ||
try { | ||
|
@@ -169,7 +173,8 @@ class AtAuthImpl implements AtAuth { | |
throw AtAuthenticationException('Pkam auth returned false'); | ||
} | ||
|
||
//5. If Pkam auth is success, update encryption public key to secondary and delete cram key from server | ||
//7. If Pkam auth is success, update encryption public key to secondary | ||
// and delete cram key from server | ||
final encryptionPublicKey = atAuthKeys.defaultEncryptionPublicKey; | ||
UpdateVerbBuilder updateBuilder = UpdateVerbBuilder() | ||
..atKey = 'publickey' | ||
|
@@ -178,7 +183,8 @@ class AtAuthImpl implements AtAuth { | |
..sharedBy = atOnboardingRequest.atSign; | ||
String? encryptKeyUpdateResult = await atLookUp!.executeVerb(updateBuilder); | ||
_logger.info('Encryption public key update result $encryptKeyUpdateResult'); | ||
// deleting cram secret from the keystore as cram auth is complete | ||
|
||
//8. Delete cram secret from the keystore as cram auth is complete | ||
DeleteVerbBuilder deleteBuilder = DeleteVerbBuilder() | ||
..atKey = AtConstants.atCramSecret; | ||
String? deleteResponse = await atLookUp!.executeVerb(deleteBuilder); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters