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

fix: Return encryptedAPKAMSymmetricKey in enroll list #1824

Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class EnrollDataStoreValue {
late String apkamPublicKey;
EnrollRequestType? requestType;
EnrollApproval? approval;
String? encryptedAPKAMSymmetricKey;

EnrollDataStoreValue(
this.sessionId, this.appName, this.deviceName, this.apkamPublicKey);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class EnrollVerbHandler extends AbstractVerbHandler {
AtData()..data = enrollParams.apkamPublicKey!);
enrollData = AtData()..data = jsonEncode(enrollmentValue.toJson());
} else {
enrollmentValue.encryptedAPKAMSymmetricKey = enrollParams.encryptedAPKAMSymmetricKey;
enrollmentValue.approval = EnrollApproval(EnrollmentStatus.pending.name);
await _storeNotification(key, enrollParams, currentAtSign);
responseJson['status'] = 'pending';
Expand Down Expand Up @@ -340,7 +341,8 @@ class EnrollVerbHandler extends AbstractVerbHandler {
enrollmentRequestsMap[enrollmentKey] = {
'appName': enrollDataStoreValue.appName,
'deviceName': enrollDataStoreValue.deviceName,
'namespace': enrollDataStoreValue.namespaces
'namespace': enrollDataStoreValue.namespaces,
'encryptedAPKAMSymmetricKey' : enrollDataStoreValue.encryptedAPKAMSymmetricKey
};
}
}
Expand All @@ -357,7 +359,8 @@ class EnrollVerbHandler extends AbstractVerbHandler {
enrollmentRequestsMap[enrollmentKey] = {
'appName': enrollDataStoreValue.appName,
'deviceName': enrollDataStoreValue.deviceName,
'namespace': enrollDataStoreValue.namespaces
'namespace': enrollDataStoreValue.namespaces,
'encryptedAPKAMSymmetricKey' : enrollDataStoreValue.encryptedAPKAMSymmetricKey
};
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/at_secondary_server/test/enroll_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void main() {

test('A test to verify enrollment list', () async {
String enrollmentRequest =
'enroll:request:{"appName":"wavi","deviceName":"mydevice","namespaces":{"wavi":"r"},"apkamPublicKey":"dummy_apkam_public_key"}';
'enroll:request:{"appName":"wavi","deviceName":"mydevice","namespaces":{"wavi":"r"},"apkamPublicKey":"dummy_apkam_public_key","encryptedAPKAMSymmetricKey":"dummy_encrypted_apkam_key"}';
HashMap<String, String?> verbParams =
getVerbParam(VerbSyntax.enroll, enrollmentRequest);
inboundConnection.metaData.isAuthenticated = true;
Expand All @@ -134,7 +134,11 @@ void main() {
verbParams = getVerbParam(VerbSyntax.enroll, enrollmentList);
await enrollVerbHandler.processVerb(
response, verbParams, inboundConnection);
var responseMap = jsonDecode(response.data!);
expect(response.data?.contains(enrollmentId), true);
expect(responseMap['$enrollmentId.new.enrollments.__manage@alice']['appName'],'wavi');
expect(responseMap['$enrollmentId.new.enrollments.__manage@alice']['deviceName'],'mydevice');
expect(responseMap['$enrollmentId.new.enrollments.__manage@alice']['namespace']['wavi'],'r');
});

test('A test to verify enrollment list with enrollmentId is populated',
Expand Down Expand Up @@ -187,7 +191,7 @@ void main() {
print('OTP: ${response.data}');
// Enroll request
enrollmentRequest =
'enroll:request:{"appName":"wavi","deviceName":"mydevice","namespaces":{"wavi":"r"},"otp":"${response.data}","apkamPublicKey":"dummy_apkam_public_key"}';
'enroll:request:{"appName":"wavi","deviceName":"mydevice","namespaces":{"wavi":"r"},"otp":"${response.data}","apkamPublicKey":"dummy_apkam_public_key","encryptedAPKAMSymmetricKey":"default_apkam_symmetric_key"}';
enrollmentRequestVerbParams =
getVerbParam(VerbSyntax.enroll, enrollmentRequest);
inboundConnection.metaData.isAuthenticated = false;
Expand Down Expand Up @@ -218,6 +222,7 @@ void main() {
expect(responseTest['appName'], 'wavi');
expect(responseTest['deviceName'], 'mydevice');
expect(responseTest['namespace']['wavi'], 'r');
expect(responseTest['encryptedAPKAMSymmetricKey'],'default_apkam_symmetric_key');
expect(
enrollListResponse.containsKey(
'$enrollmentIdOne.$newEnrollmentKeyPattern.$enrollManageNamespace$alice'),
Expand Down
50 changes: 47 additions & 3 deletions tests/at_functional_test/test/enroll_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,48 @@ void main() {
true);
});

test(
'enroll request on APKAM authenticated connection and verify enroll:list',
() async {
int randomNumber = Uuid().v4().hashCode;
await firstAtSignConnection.authenticateConnection(
authType: AuthType.pkam);
// send an enroll request with the keys from the setEncryptionKeys method
String enrollRequest =
'enroll:request:{"appName":"atmosphere-$randomNumber","deviceName":"pixel-$randomNumber","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"${apkamEncryptedKeysMap['encryptedDefaultEncPrivateKey']}","encryptedDefaultSelfEncryptionKey":"${apkamEncryptedKeysMap['encryptedSelfEncKey']}","apkamPublicKey":"${pkamPublicKeyMap[firstAtSign]!}","encryptedAPKAMSymmetricKey":"dummy_apkam_$randomNumber"}';
String enrollResponse =
(await firstAtSignConnection.sendRequestToServer(enrollRequest))
.replaceFirst('data:', '');
var enrollJsonMap = jsonDecode(enrollResponse);
var enrollmentId = enrollJsonMap['enrollmentId'];
expect(enrollmentId, isNotEmpty);
expect(enrollJsonMap['status'], 'pending');
// enroll:list
String enrollListResponse =
await firstAtSignConnection.sendRequestToServer('enroll:list');
enrollListResponse = enrollListResponse.replaceAll('data:', '');
var enrollListResponseMap = jsonDecode(enrollListResponse);
expect(
enrollListResponseMap[
'$enrollmentId.new.enrollments.__manage$firstAtSign']['appName'],
'atmosphere-$randomNumber');
expect(
enrollListResponseMap[
'$enrollmentId.new.enrollments.__manage$firstAtSign']
['deviceName'],
'pixel-$randomNumber');
expect(
enrollListResponseMap[
'$enrollmentId.new.enrollments.__manage$firstAtSign']
['namespace']['wavi'],
'rw');
expect(
enrollListResponseMap[
'$enrollmentId.new.enrollments.__manage$firstAtSign']
['encryptedAPKAMSymmetricKey'],
'dummy_apkam_$randomNumber');
});

// Purpose of the tests
// 1. Do a pkam authentication
// 2. Send an enroll request
Expand Down Expand Up @@ -403,11 +445,13 @@ void main() {
serverResponse.contains(
'${enrollJson['enrollmentId']}.new.enrollments.__manage'),
true);
Map notificationValue = jsonDecode(jsonDecode(serverResponse.replaceAll('notification: ',''))['value']);
Map notificationValue = jsonDecode(jsonDecode(
serverResponse.replaceAll('notification: ', ''))['value']);
expect(notificationValue['appName'], 'buzz');
expect(notificationValue['deviceName'], 'pixel');
expect(notificationValue['namespace'], {'buzz':'rw'});
expect(notificationValue['encryptedApkamSymmetricKey'], apkamEncryptedKeysMap['encryptedApkamSymmetricKey']);
expect(notificationValue['namespace'], {'buzz': 'rw'});
expect(notificationValue['encryptedApkamSymmetricKey'],
apkamEncryptedKeysMap['encryptedApkamSymmetricKey']);
monitorSocket.close();
}
/* Setting count to 4 to wait until server returns 4 responses
Expand Down