Skip to content

Commit

Permalink
Merge pull request #590 from atsign-foundation/sec_context
Browse files Browse the repository at this point in the history
feat:support for optional decryptPackets parameter
  • Loading branch information
srieteja authored Jul 25, 2022
2 parents f4166c9 + 2d9e277 commit f606426
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 7 deletions.
8 changes: 7 additions & 1 deletion at_client/lib/src/client/remote_secondary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ class RemoteSecondary implements Secondary {
_atSign = AtUtils.formatAtSign(atSign)!;
_preference = preference;
privateKey ??= preference.privateKey;
SecureSocketConfig secureSocketConfig = SecureSocketConfig();
secureSocketConfig.decryptPackets = preference.decryptPackets;
secureSocketConfig.pathToCerts = preference.pathToCerts;
secureSocketConfig.tlsKeysSavePath = preference.tlsKeysSavePath;
atLookUp = AtLookupImpl(atSign, preference.rootDomain, preference.rootPort,
privateKey: privateKey, cramSecret: preference.cramSecret);
privateKey: privateKey,
cramSecret: preference.cramSecret,
secureSocketConfig: secureSocketConfig);
}

/// Executes the command returned by [VerbBuilder] build command on a remote secondary server.
Expand Down
17 changes: 13 additions & 4 deletions at_client/lib/src/manager/monitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:at_client/src/preference/monitor_preference.dart';
import 'package:at_client/src/response/default_response_parser.dart';
import 'package:at_client/src/util/network_util.dart';
import 'package:at_commons/at_builders.dart';
import 'package:at_commons/at_commons.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_utils/at_logger.dart';
import 'package:crypton/crypton.dart';
Expand Down Expand Up @@ -278,7 +277,10 @@ class Monitor {

//2. create a connection to secondary server
var outboundConnection =
await _monitorOutboundConnectionFactory.createConnection(secondaryUrl);
await _monitorOutboundConnectionFactory.createConnection(secondaryUrl,
decryptPackets: _preference.decryptPackets,
pathToCerts: _preference.pathToCerts,
tlsKeysSavePath: _preference.tlsKeysSavePath);
return outboundConnection;
}

Expand Down Expand Up @@ -408,12 +410,19 @@ class MonitorConnectivityChecker {
}

class MonitorOutboundConnectionFactory {
Future<OutboundConnection> createConnection(String secondaryUrl) async {
Future<OutboundConnection> createConnection(String secondaryUrl,
{decryptPackets, pathToCerts, tlsKeysSavePath}) async {
var secondaryInfo = _getSecondaryInfo(secondaryUrl);
var host = secondaryInfo[0];
var port = secondaryInfo[1];

var secureSocket = await SecureSocket.connect(host, int.parse(port));
SecureSocketConfig secureSocketConfig = SecureSocketConfig();
secureSocketConfig.decryptPackets = decryptPackets;
secureSocketConfig.pathToCerts = pathToCerts;
secureSocketConfig.tlsKeysSavePath = tlsKeysSavePath;

SecureSocket secureSocket = await SecureSocketUtil.createSecureSocket(
host, port, secureSocketConfig);
return OutboundConnectionImpl(secureSocket);
}

Expand Down
10 changes: 10 additions & 0 deletions at_client/lib/src/preference/at_client_preference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ class AtClientPreference {
int fileEncryptionChunkSize = 4096;

Duration monitorHeartbeatInterval = Duration(seconds: 10);

///[OptionalParameter] when set to true logs TLS Keys to file.
bool decryptPackets = false;

///[OptionalParameter] location where the TLS keys will be saved when [decryptPackets] is set to true
String? tlsKeysSavePath;

///[OptionalParameter] path to trusted certificates. Required to create security context.
String? pathToCerts;

}

@Deprecated("Use SyncService")
Expand Down
5 changes: 5 additions & 0 deletions at_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ dependencies:
meta: ^1.7.0

#dependency_overrides:
# at_lookup:
# git:
# url: https://github.com/atsign-foundation/at_libraries.git
# path: at_lookup
# ref: sec_socket_util
# at_persistence_spec:
# git:
# url: https://github.com/atsign-foundation/at_server.git
Expand Down
12 changes: 10 additions & 2 deletions at_client/test/monitor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ void main() {
var fakeSecondaryUrl = "monitor_test:12345";
var fakePrivateKey =
'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCDVMetu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YHPwhPO1fysAZcJD3E1oLkttzSgB+2MD1VOTkpwEhLE74cqI6jqZV5qe7eOw7FvTT7npxd64UXAEUUurfjNz11HbGo/8pXDrB3o5qoHwzV7RPg9RByrqETKoMuUSk1FwjPSr9efQKBgAdC7w4Fkvu+aY20cMOfLnT6fsA2l3FNf2bJCPrxWFKnLbdgRkYxrMs/JOJTXT+n93DUj3V4OK3036AsEsuStbti4ra0b7g3eSnoE+2tVXl8q6Qz/rbYhKxR919ZgZc/OVdiPbVKUaYHFYSFHmKgHO6fM8DGcdOALUx/NoIOqSTxAoGBALUdiw8iyI98TFgmbSYjUj5id4MrYKXaR7ndS/SQFOBfJWVH09t5bTxXjKxKsK914/bIqEI71aussf5daOHhC03LdZIQx0ZcCdb2gL8vHNTQoqX75bLRN7J+zBKlwWjjrbhZCMLE/GtAJQNbpJ7jOrVeDwMAF8pK+Put9don44Gx';

var fakeCertsLocation = '/home/ubuntu/Desktop/cert.pem';
var fakeTlsKeysSavePath = '/home/ubuntu/Desktop/cert.pem';
AtClientPreference atClientPreference = AtClientPreference();
atClientPreference.privateKey = fakePrivateKey;
atClientPreference.decryptPackets = true;
atClientPreference.tlsKeysSavePath = fakeTlsKeysSavePath;
atClientPreference.pathToCerts = fakeCertsLocation;

group('Monitor constructor and start tests', () {
setUp(() {
Expand All @@ -68,7 +72,11 @@ void main() {
when(() => mockOutboundConnection.getSocket())
.thenAnswer((_) => mockSocket);
when(() => mockMonitorOutboundConnectionFactory.createConnection(
fakeSecondaryUrl)).thenAnswer((_) async => mockOutboundConnection);
fakeSecondaryUrl,
decryptPackets: true,
tlsKeysSavePath: fakeTlsKeysSavePath,
pathToCerts: fakeCertsLocation))
.thenAnswer((_) async => mockOutboundConnection);
when(() => mockSocket.listen(any(),
onError: any(named: "onError"),
onDone: any(named: "onDone"))).thenAnswer((Invocation invocation) {
Expand Down
6 changes: 6 additions & 0 deletions at_end2end_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ dependencies:
# path: at_commons
# ref: trunk

# at_lookup:
# git:
# url: https://github.com/atsign-foundation/at_libraries.git
# path: at_lookup
# ref: sec_socket_util

dev_dependencies:
pedantic: ^1.10.0
test: ^1.16.0
6 changes: 6 additions & 0 deletions at_functional_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ dependencies:
# path: at_commons
# ref: trunk

# at_lookup:
# git:
# url: https://github.com/atsign-foundation/at_libraries.git
# path: at_lookup
# ref: sec_socket_util

dev_dependencies:
test: ^1.17.2
lints: ^1.0.1
Expand Down
30 changes: 30 additions & 0 deletions at_functional_test/test/testData/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN CERTIFICATE-----
MIIFLDCCBBSgAwIBAgISBAAOlxS2nBvkxSahxke0Vb4dMA0GCSqGSIb3DQEBCwUA
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
EwJSMzAeFw0yMjA3MTUwNjQxMTFaFw0yMjEwMTMwNjQxMTBaMB0xGzAZBgNVBAMT
EnZpcC52ZS5hdHNpZ24uem9uZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBAL6sK1lj/xk61tqJbU+BjKLFcXmCrpidsgOjTuIaNyGzlA2A9ct9Paoh5cQ5
jVlDptOaCq7YJ1B0OmO13nPPRkMNkm/cleQh3L0KOESSriSr+wOzs2nXxHas+7US
U3bU5aRotvptozifQcgAUJKVgKBgicG2yJlDDJK1R6ZyifnHRmiOX/7z/06ecD2d
KW3ujOfL+PLJtJXELdklHXw4vrXMAyw+p+2BL26sX5L0QWuBZGYwyoGnesQaOgiG
xOomxES8kM7dUiU8h2B07V9Lc0BxPz7M/xekyKOnd8VbxTSpfpE9T7lQN+ZP3Mvg
S5t8o6UEasq7Ln1JwC/z6W8oAp8CAwEAAaOCAk8wggJLMA4GA1UdDwEB/wQEAwIF
oDAdBgNVHSUEFjA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Nr1HEJj3KF10R2DvFIz3GyOP
S9ffV+eYSxNCS/TlPOggYi/z1a2Xs0Kwe4spm+DQ8lY=
-----END CERTIFICATE-----
3 changes: 3 additions & 0 deletions at_functional_test/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class TestUtils {
preference.isLocalStoreRequired = true;
preference.privateKey = demo_credentials.pkamPrivateKeyMap[atsign];
preference.rootDomain = 'vip.ve.atsign.zone';
preference.decryptPackets = true;
preference.pathToCerts = 'test/testData/cert.pem';
preference.tlsKeysSavePath = 'test/tlsKeysFile';
return preference;
}
}

0 comments on commit f606426

Please sign in to comment.