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: Uptake public key hash changes #2160

Merged
merged 20 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fbb6244
fix: Uptake public key hash changes
sitaram-kalluri Nov 15, 2024
db95194
fix: Add dependency_overrides in the pubspec.yaml
sitaram-kalluri Nov 26, 2024
8182577
fix: Add functional test to verify publicKeyHash is set in metadata b…
sitaram-kalluri Nov 27, 2024
65940f5
fix: Add E2E test to verify publicKeyHash
sitaram-kalluri Nov 27, 2024
dc70d7b
Merge remote-tracking branch 'origin/trunk' into 2121-uptake-pubkeyha…
sitaram-kalluri Nov 27, 2024
2d4223c
fix: Remove hard coded atSign from E2E test to verify publicKeyHash
sitaram-kalluri Nov 27, 2024
25b567f
fix: Add version check for second atSign
sitaram-kalluri Nov 27, 2024
a8656d9
fix: Skip publicKeyHash E2E test
sitaram-kalluri Nov 27, 2024
0eb9ca3
fix: Add randomId to have unique keys on each run
sitaram-kalluri Nov 27, 2024
24194dc
fix: Remove the skip tag
sitaram-kalluri Nov 27, 2024
c0924fa
Merge branch 'trunk' into 2121-uptake-pubkeyhash-changes
sitaram-kalluri Dec 5, 2024
4fb2928
fix: Update the server version to fix th E2E test
sitaram-kalluri Dec 5, 2024
04517b2
Merge branch 'trunk' into 2121-uptake-pubkeyhash-changes
sitaram-kalluri Dec 9, 2024
79d45da
fix: Update the server version in the E2E test log.
sitaram-kalluri Dec 9, 2024
cb2efb8
Merge remote-tracking branch 'origin/2121-uptake-pubkeyhash-changes' …
sitaram-kalluri Dec 9, 2024
594d592
Merge remote-tracking branch 'origin/trunk' into 2121-uptake-pubkeyha…
sitaram-kalluri Dec 9, 2024
c3c2321
fix: Update the version to 3.1.1
sitaram-kalluri Dec 9, 2024
7ce9aea
fix: Replace not null check with isNotNullOrEmpty
sitaram-kalluri Dec 10, 2024
85db4dc
Merge branch 'trunk' into 2121-uptake-pubkeyhash-changes
sitaram-kalluri Dec 10, 2024
075b674
Merge branch 'trunk' into 2121-uptake-pubkeyhash-changes
gkc Dec 11, 2024
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
2 changes: 2 additions & 0 deletions packages/at_secondary_server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 3.1.1
- fix: Store "publicKeyHash" value in the keystore
# 3.1.0
- feat: sync skip deletes until changes
- fix: Enable persistence of the Initialization Vector for "defaultEncryptionPrivateKey" and "selfEncryptionKey" in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ class ResourceManager {
commandBody =
'${AtConstants.encryptingKeyName}:${atNotification.atMetadata!.encKeyName}:$commandBody';
}
if (atNotification.atMetadata!.pubKeyHash != null) {
commandBody =
'${AtConstants.sharedWithPublicKeyHash}:${atNotification.atMetadata!.pubKeyHash?.hash}:${AtConstants.sharedWithPublicKeyHashingAlgo}:${atNotification.atMetadata!.pubKeyHash?.hashingAlgo}:$commandBody';
}
if (atNotification.atMetadata!.pubKeyCS != null) {
commandBody =
'${AtConstants.sharedWithPublicKeyCheckSum}:${atNotification.atMetadata!.pubKeyCS}:$commandBody';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ abstract class AbstractUpdateVerbHandler extends ChangeVerbHandler {
verbParams[AtConstants.sharedKeyEncryptedEncryptingKeyName];
metadata.skeEncAlgo =
verbParams[AtConstants.sharedKeyEncryptedEncryptingAlgo];
if (verbParams[AtConstants.sharedWithPublicKeyHash].isNotNullOrEmpty &&
verbParams[AtConstants.sharedWithPublicKeyHashingAlgo]
.isNotNullOrEmpty) {
metadata.pubKeyHash = PublicKeyHash(
verbParams[AtConstants.sharedWithPublicKeyHash]!,
verbParams[AtConstants.sharedWithPublicKeyHashingAlgo]!);
}

updateParams.metadata = metadata;
return updateParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class MonitorVerbHandler extends AbstractVerbHandler {
"skeEncKeyName": atNotification.atMetadata?.skeEncKeyName,
"skeEncAlgo": atNotification.atMetadata?.skeEncAlgo,
"sharedKeyEnc": atNotification.atMetadata?.sharedKeyEnc,
"pubKeyHash":
jsonEncode(atNotification.atMetadata?.pubKeyHash?.toJson())
};

await _checkAndSend(notification);
Expand Down Expand Up @@ -222,7 +224,8 @@ class Notification {
"availableAt": atNotification.atMetadata?.availableAt.toString(),
"expiresAt":
(atNotification.atMetadata?.expiresAt ?? atNotification.expiresAt)
.toString()
.toString(),
'pubKeyHash': jsonEncode(atNotification.atMetadata?.pubKeyHash?.toJson())
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ class NotifyVerbHandler extends AbstractVerbHandler {
if (verbParams[AtConstants.sharedWithPublicKeyCheckSum] != null) {
atMetadata.pubKeyCS = verbParams[AtConstants.sharedWithPublicKeyCheckSum];
}
if (verbParams[AtConstants.sharedWithPublicKeyHash].isNotNullOrEmpty &&
verbParams[AtConstants.sharedWithPublicKeyHashingAlgo]
.isNotNullOrEmpty) {
atMetadata.pubKeyHash = PublicKeyHash(
verbParams[AtConstants.sharedWithPublicKeyHash]!,
verbParams[AtConstants.sharedWithPublicKeyHashingAlgo]!);
}
if (verbParams[AtConstants.encryptingKeyName] != null) {
atMetadata.encKeyName = verbParams[AtConstants.encryptingKeyName];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,24 @@ class SyncProgressiveVerbHandler extends AbstractVerbHandler {
if (metaData == null) {
return metaDataMap;
}
metaData.toJson().forEach((key, value) {
if (value != null) {
metaDataMap[key] = value.toString();
Iterator itr = metaData.toJson().entries.iterator;
while (itr.moveNext()) {
// The value of [AtConstants.sharedWithPublicKeyHash] stores a Map containing
// the hash value and the hashing algorithm used for hashing the data.
// For example, {"hash":"dummy_value", "hashingAlgo":"sha512"}.
// Using toString() will not allow convert this into a Map, which is necessary
// for constructing the PublicKeyHash type on the client side.
// Therefore, a JSON-encoded string is used here, and on the client side,
// "jsonDecode" will be used to retrieve the Map and build the PublicKeyHash instance.
if (itr.current.key == AtConstants.sharedWithPublicKeyHash &&
itr.current.value != null) {
metaDataMap[itr.current.key] = jsonEncode(itr.current.value);
continue;
}
if (itr.current.value != null) {
metaDataMap[itr.current.key] = itr.current.value.toString();
}
});
}
return metaDataMap;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/at_secondary_server/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_secondary
description: Implementation of secondary server.
version: 3.1.0
version: 3.1.1
repository: https://github.com/atsign-foundation/at_server
homepage: https://www.example.com
publish_to: none
Expand Down
11 changes: 9 additions & 2 deletions packages/at_secondary_server/test/sync_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:collection';
import 'dart:convert';
import 'dart:io';

import 'package:at_chops/at_chops.dart';
import 'package:at_commons/at_commons.dart';
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart';
import 'package:at_secondary/src/connection/inbound/inbound_connection_impl.dart';
Expand All @@ -10,8 +11,8 @@ import 'package:at_secondary/src/utils/handler_util.dart';
import 'package:at_secondary/src/utils/secondary_util.dart';
import 'package:at_secondary/src/verb/handler/sync_progressive_verb_handler.dart';
import 'package:at_server_spec/at_verb_spec.dart';
import 'package:test/test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

import 'test_utils.dart';

Expand Down Expand Up @@ -115,7 +116,10 @@ void main() {
..ttb = 1000
..ttr = 100
..isBinary = false
..encoding = 'base64'));
..encoding = 'base64'
..pubKeyHash =
PublicKeyHash('dummy_hash', HashingAlgoType.sha512.name)
..pubKeyCS = 'dummy_pub_key_cs'));

verbHandler = SyncProgressiveVerbHandler(keyStoreManager.getKeyStore());
var response = Response();
Expand All @@ -136,6 +140,9 @@ void main() {
expect(syncResponseMap['metadata']['ttr'], '100');
expect(syncResponseMap['metadata']['isBinary'], 'false');
expect(syncResponseMap['metadata']['encoding'], 'base64');
expect(syncResponseMap['metadata']['pubKeyCS'], 'dummy_pub_key_cs');
expect(syncResponseMap['metadata']['pubKeyHash'],
'{"hash":"dummy_hash","hashingAlgo":"sha512"}');
});

when(() => mockKeyStore.isKeyExists(any())).thenReturn(true);
Expand Down
45 changes: 43 additions & 2 deletions tests/at_end2end_test/test/lookup_verb_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:convert';
import 'dart:math';

import 'package:test/test.dart';
import 'package:uuid/uuid.dart';
import 'package:version/version.dart';

import 'e2e_test_utils.dart' as e2e;

Expand Down Expand Up @@ -34,16 +37,54 @@ void main() {
///Update verb on bob atsign
var lastValue = Random().nextInt(5);
var value = 'Q7878R$lastValue';
await sh1.writeCommand('update:$atSign_2:special-code$atSign_1 $value');
var randomId = Uuid().v4();
await sh1.writeCommand(
'update:$atSign_2:special-code-$randomId$atSign_1 $value');
String response = await sh1.read();
print('update verb response : $response');
assert(
(!response.contains('Invalid syntax')) && (!response.contains('null')));

///lookup verb alice atsign
await sh2.writeCommand('lookup:special-code$atSign_1');
await sh2.writeCommand('lookup:special-code-$randomId$atSign_1');
response = await sh2.read(timeoutMillis: 4000);
print('lookup verb response : $response');
expect(response, contains('data:$value'));
}, timeout: Timeout(Duration(minutes: 3)));

test('A test to verify lookup metadata contains public key hash value',
() async {
Version atSign1ServerVersion = Version.parse(await sh1.getVersion());
if (atSign1ServerVersion < Version(3, 1, 1)) {
print(
'Found $atSign_1 with server version: $atSign1ServerVersion. This test is only applicable for server version least 3.1.1. Skipping the test');
return;
}
Version atSign2ServerVersion = Version.parse(await sh2.getVersion());
if (atSign2ServerVersion < Version(3, 1, 1)) {
print(
'Found $atSign_2 with server version: $atSign2ServerVersion. This test is only applicable for server version least 3.1.1. Skipping the test');
return;
}
var lastValue = Random().nextInt(5);
var randomHashValue = Uuid().v4().hashCode;
var value = 'Q7878R$lastValue';
await sh1.writeCommand(
'update:pubKeyHash:hashedValue-$randomHashValue:hashingAlgo:sha512:$atSign_2:special-code-$randomHashValue$atSign_1 $value');
String response = await sh1.read();
assert(
(!response.contains('Invalid syntax')) && (!response.contains('null')));

///lookup verb alice atsign
await sh2.writeCommand('lookup:all:special-code-$randomHashValue$atSign_1');
response = await sh2.read(timeoutMillis: 4000);
response = response.replaceAll('data:', '');
var decodedResponse = jsonDecode(response);
expect(decodedResponse['key'],
'$atSign_2:special-code-$randomHashValue$atSign_1');
expect(decodedResponse['metaData']['pubKeyHash']['hash'],
'hashedValue-$randomHashValue');
expect(decodedResponse['metaData']['pubKeyHash']['hashingAlgo'], 'sha512');
expect(decodedResponse['data'], value);
});
}
20 changes: 20 additions & 0 deletions tests/at_functional_test/test/sync_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ void main() {
assert((response.contains('Invalid syntax')));
});

test('A test to verify publicKeyHash in set in sync response', () async {
String namespace = '.func.test';
String randomId = Uuid().v4();

var response = await firstAtSignConnection.sendRequestToServer(
'update:pubKeyHash:dummy_hash:hashingAlgo:sha512:$secondAtSign:twitter-$randomId$namespace$firstAtSign bob_tweet');
assert(
(!response.contains('Invalid syntax')) && (!response.contains('null')));
String commitId = response.replaceAll('data:', '');
int syncId = int.parse(commitId);
// sync with regex
response = await firstAtSignConnection
.sendRequestToServer('sync:from:${syncId - 1}:limit:5:$namespace');
response = response.replaceAll('data:', '');
var responseMap = jsonDecode(response);
var publicKeyHashMap = jsonDecode(responseMap[0]['metadata']['pubKeyHash']);
expect(publicKeyHashMap['hash'], 'dummy_hash');
expect(publicKeyHashMap['hashingAlgo'], 'sha512');
});

group('A group of tests to verify sync entries', () {
late OutboundConnectionFactory authenticatedSocket =
OutboundConnectionFactory();
Expand Down
Loading