Skip to content

Commit

Permalink
Merge pull request #1962 from atsign-foundation/apkam_notification_fix
Browse files Browse the repository at this point in the history
fix: add encryptedAPKAMSymmetricKey to enrollment notification
  • Loading branch information
gkc authored May 22, 2024
2 parents b4aae86 + 1c4e634 commit b34ef41
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ class EnrollVerbHandler extends AbstractVerbHandler {
var notificationValue = {};
notificationValue[AtConstants.apkamEncryptedSymmetricKey] =
enrollParams.encryptedAPKAMSymmetricKey;
// send both encryptedAPKAMSymmetricKey and encryptedApkamSymmetricKey in notification
// after the server is released, use encryptedAPKAMSymmetricKey. Modify the constant name in at_commons and client side code.
notificationValue['encryptedAPKAMSymmetricKey'] =
enrollParams.encryptedAPKAMSymmetricKey;
notificationValue[AtConstants.appName] = enrollParams.appName;
notificationValue[AtConstants.deviceName] = enrollParams.deviceName;
notificationValue[AtConstants.namespace] = enrollParams.namespaces;
Expand Down
29 changes: 23 additions & 6 deletions packages/at_secondary_server/test/monitor_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:at_secondary/src/verb/handler/enroll_verb_handler.dart';
import 'package:at_secondary/src/verb/handler/monitor_verb_handler.dart';
import 'package:at_secondary/src/verb/handler/otp_verb_handler.dart';
import 'package:at_server_spec/at_server_spec.dart';
import 'package:test/expect.dart';
import 'package:test/test.dart';
import 'package:uuid/uuid.dart';

Expand Down Expand Up @@ -360,6 +361,7 @@ void main() {
',"deviceName":"$deviceName"'
',"namespaces":${jsonEncode(namespaces)}'
',"apkamPublicKey":"dummy_apkam_public_key"'
',"encryptedAPKAMSymmetricKey":"dummy_encrypted_apkam_symm_key"'
'}';
HashMap<String, String?> enrollmentRequestVerbParams =
getVerbParam(VerbSyntax.enroll, enrollmentRequest);
Expand Down Expand Up @@ -415,10 +417,15 @@ void main() {

// Verify that the monitor connection receives the
// enrollment request notification
var notificationJson = jsonDecode(
pkamMC.lastWrittenData!.replaceAll('notification:', '').trim());
expect(notificationJson['value'], isNotNull);
final valueJson = jsonDecode(notificationJson['value']);
expect(valueJson['appName'], 'mvt_app_2');
expect(valueJson['deviceName'], 'mvt_dev_2');
expect(valueJson['namespace'], equals({'app_2_namespace': 'rw'}));
expect(
jsonDecode(pkamMC.lastWrittenData!
.replaceAll('notification:', '')
.trim())['key'],
notificationJson['key'],
'$nextEnrollmentId'
'.new.enrollments.__manage'
'@alice');
Expand Down Expand Up @@ -467,10 +474,20 @@ void main() {

// Verify that the APKAM monitor connection receives the
// enrollment request notification
var notificationJson = jsonDecode(
apkamMC.lastWrittenData!.replaceAll('notification:', '').trim());
expect(notificationJson['value'], isNotNull);
final valueJson = jsonDecode(notificationJson['value']);
//TODO remove encryptedApkamSymmetricKey in the future
expect(valueJson['encryptedApkamSymmetricKey'],
'dummy_encrypted_apkam_symm_key');
expect(valueJson['encryptedAPKAMSymmetricKey'],
'dummy_encrypted_apkam_symm_key');
expect(valueJson['appName'], 'mvt_app_2');
expect(valueJson['deviceName'], 'mvt_dev_2');
expect(valueJson['namespace'], equals({'app_2_namespace': 'rw'}));
expect(
jsonDecode(apkamMC.lastWrittenData!
.replaceAll('notification:', '')
.trim())['key'],
notificationJson['key'],
'$nextEnrollmentId'
'.new.enrollments.__manage'
'@alice');
Expand Down
3 changes: 3 additions & 0 deletions tests/at_functional_test/test/enroll_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,11 @@ void main() {
expect(notificationValue['appName'], 'buzz');
expect(notificationValue['deviceName'], deviceName);
expect(notificationValue['namespace'], {'buzz': 'rw'});
// TODO remove encryptedApkamSymmetricKey and use encryptedAPKAMSymmetricKey constant name in future
expect(notificationValue['encryptedApkamSymmetricKey'],
apkamEncryptedKeysMap['encryptedApkamSymmetricKey']);
expect(notificationValue['encryptedAPKAMSymmetricKey'],
apkamEncryptedKeysMap['encryptedApkamSymmetricKey']);
monitorSocket.close();
}
/* Setting count to 4 to wait until server returns 4 responses
Expand Down

0 comments on commit b34ef41

Please sign in to comment.