Compare commits
9 Commits
moxxmpp_so
...
moxxmpp-v0
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d9010b11c | |||
| 9cc735d854 | |||
| 988db718a2 | |||
| afaca7a558 | |||
| 3172450b70 | |||
| 848d83dc1f | |||
| 2f089535a3 | |||
| 608ba8ce4a | |||
| d5493a185a |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -10,3 +10,6 @@ build/
|
||||
# Omit committing pubspec.lock for library packages; see
|
||||
# https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
pubspec.lock
|
||||
|
||||
# Omit pubspec override files generated by melos
|
||||
**/pubspec_overrides.yaml
|
||||
|
||||
@@ -18,6 +18,10 @@ if a DNS implementation is given, and supports StartTLS.
|
||||
To begin, use [melos](https://github.com/invertase/melos) to bootstrap the project: `melos bootstrap`. Then, the example
|
||||
can be run with `flutter run` on Linux or Android.
|
||||
|
||||
To run the example, make sure that Flutter is correctly set up and working. If you use
|
||||
the development shell provided by the NixOS Flake, ensure that `ANDROID_HOME` and
|
||||
`ANDROID_AVD_HOME` are pointing to the correct directories.
|
||||
|
||||
## License
|
||||
|
||||
See `./LICENSE`.
|
||||
|
||||
@@ -12,3 +12,4 @@ analyzer:
|
||||
- "**/*.g.dart"
|
||||
- "**/*.freezed.dart"
|
||||
- "test/"
|
||||
- "integration_test/"
|
||||
|
||||
@@ -69,7 +69,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
RosterManager(),
|
||||
PingManager(),
|
||||
MessageManager(),
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
])
|
||||
..registerFeatureNegotiators([
|
||||
ResourceBindingNegotiator(),
|
||||
|
||||
@@ -16,10 +16,10 @@ dependencies:
|
||||
version: 0.1.4+1
|
||||
moxxmpp:
|
||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
||||
version: 0.1.1
|
||||
version: 0.1.2+2
|
||||
moxxmpp_socket_tcp:
|
||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
||||
version: 0.1.1
|
||||
version: 0.1.2+2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
@@ -58,9 +58,7 @@
|
||||
CPATH = "${pkgs.xorg.libX11.dev}/include:${pkgs.xorg.xorgproto}/include";
|
||||
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ atk cairo epoxy gdk-pixbuf glib gtk3 harfbuzz pango ];
|
||||
|
||||
ANDROID_HOME = (toString ./.) + "/.android/sdk";
|
||||
JAVA_HOME = pinnedJDK;
|
||||
ANDROID_AVD_HOME = (toString ./.) + "/.android/avd";
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
1
packages/moxxmpp/.pubignore
Normal file
1
packages/moxxmpp/.pubignore
Normal file
@@ -0,0 +1 @@
|
||||
pubspec_overrides.yaml
|
||||
@@ -1,3 +1,15 @@
|
||||
## 0.1.2+2
|
||||
|
||||
- **FIX**: Fix reconnections when the connection is awaited.
|
||||
|
||||
## 0.1.2+1
|
||||
|
||||
- **FIX**: A certificate rejection does not crash the connection.
|
||||
|
||||
## 0.1.2
|
||||
|
||||
- **FEAT**: Remove Moxxy specific strings.
|
||||
|
||||
## 0.1.1
|
||||
|
||||
- **REFACTOR**: Move packages into packages/.
|
||||
|
||||
@@ -1 +1 @@
|
||||
include: ../analysis_options.yaml
|
||||
include: ../../analysis_options.yaml
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:moxxmpp/moxxmpp.dart';
|
||||
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
Logger.root.level = Level.ALL;
|
||||
Logger.root.onRecord.listen((record) {
|
||||
print('${record.level.name}: ${record.time}: ${record.message}');
|
||||
});
|
||||
final log = Logger('FailureReconnectionTest');
|
||||
|
||||
test('Failing an awaited connection', () async {
|
||||
var errors = 0;
|
||||
final connection = XmppConnection(
|
||||
TestingSleepReconnectionPolicy(10),
|
||||
TCPSocketWrapper(false),
|
||||
);
|
||||
connection.registerFeatureNegotiators([
|
||||
StartTlsNegotiator(),
|
||||
]);
|
||||
connection.registerManagers([
|
||||
DiscoManager(),
|
||||
RosterManager(),
|
||||
PingManager(),
|
||||
MessageManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
]);
|
||||
connection.asBroadcastStream().listen((event) {
|
||||
if (event is ConnectionStateChangedEvent) {
|
||||
if (event.state == XmppConnectionState.error) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connection.setConnectionSettings(
|
||||
ConnectionSettings(
|
||||
jid: JID.fromString('testuser@no-sasl.badxmpp.eu'),
|
||||
password: 'abc123',
|
||||
useDirectTLS: true,
|
||||
allowPlainAuth: true,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await connection.connectAwaitable();
|
||||
log.info('Connection failed as expected');
|
||||
expect(result.success, false);
|
||||
expect(errors, 1);
|
||||
|
||||
log.info('Waiting 20 seconds for unexpected reconnections');
|
||||
await Future.delayed(const Duration(seconds: 20));
|
||||
expect(errors, 1);
|
||||
}, timeout: Timeout.factor(2));
|
||||
}
|
||||
@@ -163,6 +163,8 @@ class XmppConnection {
|
||||
/// Completers for certain actions
|
||||
// ignore: use_late_for_private_fields_and_variables
|
||||
Completer<XmppConnectionResult>? _connectionCompleter;
|
||||
/// Controls whether an XmppSocketClosureEvent triggers a reconnection.
|
||||
bool _socketClosureTriggersReconnect = true;
|
||||
|
||||
/// Negotiators
|
||||
final Map<String, XmppFeatureNegotiatorBase> _featureNegotiators;
|
||||
@@ -350,8 +352,18 @@ class XmppConnection {
|
||||
_log.severe('handleError: Called with null');
|
||||
}
|
||||
|
||||
// TODO(Unknown): This may be too harsh for every error
|
||||
await _setConnectionState(XmppConnectionState.notConnected);
|
||||
// Whenever we encounter an error that would trigger a reconnection attempt while
|
||||
// the connection result is being awaited, don't attempt a reconnection but instead
|
||||
// try to gracefully disconnect.
|
||||
if (_connectionCompleter != null) {
|
||||
_log.info('Not triggering reconnection since connection result is being awaited');
|
||||
await _disconnect(triggeredByUser: false, state: XmppConnectionState.error);
|
||||
_connectionCompleter?.complete(const XmppConnectionResult(false));
|
||||
_connectionCompleter = null;
|
||||
return;
|
||||
}
|
||||
|
||||
await _setConnectionState(XmppConnectionState.error);
|
||||
await _reconnectionPolicy.onFailure();
|
||||
}
|
||||
|
||||
@@ -360,8 +372,12 @@ class XmppConnection {
|
||||
if (event is XmppSocketErrorEvent) {
|
||||
await handleError(event.error);
|
||||
} else if (event is XmppSocketClosureEvent) {
|
||||
if (_socketClosureTriggersReconnect) {
|
||||
_log.fine('Received XmppSocketClosureEvent. Reconnecting...');
|
||||
await _reconnectionPolicy.onFailure();
|
||||
} else {
|
||||
_log.fine('Received XmppSocketClosureEvent. No reconnection attempt since _socketClosureTriggersReconnect is false...');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,6 +812,9 @@ class XmppConnection {
|
||||
|
||||
_updateRoutingState(RoutingState.handleStanzas);
|
||||
await _onNegotiationsDone();
|
||||
} else if (_currentNegotiator!.state == NegotiatorState.error) {
|
||||
_log.severe('Negotiator returned an error');
|
||||
await handleError(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -956,16 +975,31 @@ class XmppConnection {
|
||||
|
||||
/// Attempt to gracefully close the session
|
||||
Future<void> disconnect() async {
|
||||
await _disconnect(state: XmppConnectionState.notConnected);
|
||||
}
|
||||
|
||||
Future<void> _disconnect({required XmppConnectionState state, bool triggeredByUser = true}) async {
|
||||
_reconnectionPolicy.setShouldReconnect(false);
|
||||
_socketClosureTriggersReconnect = false;
|
||||
|
||||
if (triggeredByUser) {
|
||||
getPresenceManager().sendUnavailablePresence();
|
||||
}
|
||||
|
||||
_socket.prepareDisconnect();
|
||||
|
||||
if (triggeredByUser) {
|
||||
sendRawString('</stream:stream>');
|
||||
await _setConnectionState(XmppConnectionState.notConnected);
|
||||
}
|
||||
|
||||
await _setConnectionState(state);
|
||||
_socket.close();
|
||||
|
||||
if (triggeredByUser) {
|
||||
// Clear Stream Management state, if available
|
||||
await getStreamManagementManager()?.resetState();
|
||||
}
|
||||
}
|
||||
|
||||
/// Make sure that all required managers are registered
|
||||
void _runPreConnectionAssertions() {
|
||||
@@ -1000,7 +1034,7 @@ class XmppConnection {
|
||||
}
|
||||
|
||||
await _reconnectionPolicy.reset();
|
||||
|
||||
_socketClosureTriggersReconnect = true;
|
||||
await _sendEvent(ConnectingEvent());
|
||||
|
||||
final smManager = getStreamManagementManager();
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
const smManager = 'im.moxxy.streammangementmanager';
|
||||
const discoManager = 'im.moxxy.discomanager';
|
||||
const messageManager = 'im.moxxy.messagemanager';
|
||||
const rosterManager = 'im.moxxy.rostermanager';
|
||||
const presenceManager = 'im.moxxy.presencemanager';
|
||||
const csiManager = 'im.moxxy.csimanager';
|
||||
const carbonsManager = 'im.moxxy.carbonsmanager';
|
||||
const vcardManager = 'im.moxxy.vcardmanager';
|
||||
const pubsubManager = 'im.moxxy.pubsubmanager';
|
||||
const userAvatarManager = 'im.moxxy.useravatarmanager';
|
||||
const stableIdManager = 'im.moxxy.stableidmanager';
|
||||
const simsManager = 'im.moxxy.simsmanager';
|
||||
const messageDeliveryReceiptManager = 'im.moxxy.messagedeliveryreceiptmanager';
|
||||
const chatMarkerManager = 'im.moxxy.chatmarkermanager';
|
||||
const oobManager = 'im.moxxy.oobmanager';
|
||||
const sfsManager = 'im.moxxy.sfsmanager';
|
||||
const messageRepliesManager = 'im.moxxy.messagerepliesmanager';
|
||||
const blockingManager = 'im.moxxy.blockingmanager';
|
||||
const httpFileUploadManager = 'im.moxxy.httpfileuploadmanager';
|
||||
const chatStateManager = 'im.moxxy.chatstatemanager';
|
||||
const pingManager = 'im.moxxy.ping';
|
||||
const fileUploadNotificationManager = 'im.moxxy.fileuploadnotificationmanager';
|
||||
const omemoManager = 'org.moxxy.omemomanager';
|
||||
const emeManager = 'org.moxxy.ememanager';
|
||||
const cryptographicHashManager = 'org.moxxy.cryptographichashmanager';
|
||||
const delayedDeliveryManager = 'org.moxxy.delayeddeliverymanager';
|
||||
const smManager = 'im.moxxmpp.streammangementmanager';
|
||||
const discoManager = 'im.moxxmpp.discomanager';
|
||||
const messageManager = 'im.moxxmpp.messagemanager';
|
||||
const rosterManager = 'im.moxxmpp.rostermanager';
|
||||
const presenceManager = 'im.moxxmpp.presencemanager';
|
||||
const csiManager = 'im.moxxmpp.csimanager';
|
||||
const carbonsManager = 'im.moxxmpp.carbonsmanager';
|
||||
const vcardManager = 'im.moxxmpp.vcardmanager';
|
||||
const pubsubManager = 'im.moxxmpp.pubsubmanager';
|
||||
const userAvatarManager = 'im.moxxmpp.useravatarmanager';
|
||||
const stableIdManager = 'im.moxxmpp.stableidmanager';
|
||||
const simsManager = 'im.moxxmpp.simsmanager';
|
||||
const messageDeliveryReceiptManager = 'im.moxxmpp.messagedeliveryreceiptmanager';
|
||||
const chatMarkerManager = 'im.moxxmpp.chatmarkermanager';
|
||||
const oobManager = 'im.moxxmpp.oobmanager';
|
||||
const sfsManager = 'im.moxxmpp.sfsmanager';
|
||||
const messageRepliesManager = 'im.moxxmpp.messagerepliesmanager';
|
||||
const blockingManager = 'im.moxxmpp.blockingmanager';
|
||||
const httpFileUploadManager = 'im.moxxmpp.httpfileuploadmanager';
|
||||
const chatStateManager = 'im.moxxmpp.chatstatemanager';
|
||||
const pingManager = 'im.moxxmpp.ping';
|
||||
const fileUploadNotificationManager = 'im.moxxmpp.fileuploadnotificationmanager';
|
||||
const omemoManager = 'org.moxxmpp.omemomanager';
|
||||
const emeManager = 'org.moxxmpp.ememanager';
|
||||
const cryptographicHashManager = 'org.moxxmpp.cryptographichashmanager';
|
||||
const delayedDeliveryManager = 'org.moxxmpp.delayeddeliverymanager';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const saslPlainNegotiator = 'im.moxxy.sasl.plain';
|
||||
const saslScramSha1Negotiator = 'im.moxxy.sasl.scram.sha1';
|
||||
const saslScramSha256Negotiator = 'im.moxxy.sasl.scram.sha256';
|
||||
const saslScramSha512Negotiator = 'im.moxxy.sasl.scram.sha512';
|
||||
const csiNegotiator = 'im.moxxy.xeps.csi';
|
||||
const rosterNegotiator = 'im.moxxy.core.roster';
|
||||
const resourceBindingNegotiator = 'im.moxxy.core.resource';
|
||||
const streamManagementNegotiator = 'im.moxxy.xeps.sm';
|
||||
const startTlsNegotiator = 'im.moxxy.core.starttls';
|
||||
const saslPlainNegotiator = 'im.moxxmpp.sasl.plain';
|
||||
const saslScramSha1Negotiator = 'im.moxxmpp.sasl.scram.sha1';
|
||||
const saslScramSha256Negotiator = 'im.moxxmpp.sasl.scram.sha256';
|
||||
const saslScramSha512Negotiator = 'im.moxxmpp.sasl.scram.sha512';
|
||||
const csiNegotiator = 'im.moxxmpp.xeps.csi';
|
||||
const rosterNegotiator = 'im.moxxmpp.core.roster';
|
||||
const resourceBindingNegotiator = 'im.moxxmpp.core.resource';
|
||||
const streamManagementNegotiator = 'im.moxxmpp.xeps.sm';
|
||||
const startTlsNegotiator = 'im.moxxmpp.core.starttls';
|
||||
|
||||
@@ -14,9 +14,11 @@ import 'package:moxxmpp/src/xeps/xep_0115.dart';
|
||||
import 'package:moxxmpp/src/xeps/xep_0414.dart';
|
||||
|
||||
class PresenceManager extends XmppManagerBase {
|
||||
|
||||
PresenceManager() : _capabilityHash = null, super();
|
||||
PresenceManager(this._capHashNode) : _capabilityHash = null, super();
|
||||
String? _capabilityHash;
|
||||
final String _capHashNode;
|
||||
|
||||
String get capabilityHashNode => _capHashNode;
|
||||
|
||||
@override
|
||||
String getId() => presenceManager;
|
||||
@@ -93,7 +95,7 @@ class PresenceManager extends XmppManagerBase {
|
||||
xmlns: capsXmlns,
|
||||
attributes: {
|
||||
'hash': 'sha-1',
|
||||
'node': 'http://moxxy.im',
|
||||
'node': _capHashNode,
|
||||
'ver': await getCapabilityHash()
|
||||
},
|
||||
)
|
||||
|
||||
@@ -93,6 +93,7 @@ class ExponentialBackoffReconnectionPolicy extends ReconnectionPolicy {
|
||||
final isReconnecting = await isReconnectionRunning();
|
||||
if (shouldReconnect) {
|
||||
if (!isReconnecting) {
|
||||
await setIsReconnecting(true);
|
||||
await performReconnect!();
|
||||
} else {
|
||||
// Should never happen.
|
||||
@@ -117,7 +118,6 @@ class ExponentialBackoffReconnectionPolicy extends ReconnectionPolicy {
|
||||
Future<void> onFailure() async {
|
||||
_log.finest('Failure occured. Starting exponential backoff');
|
||||
_counter++;
|
||||
await setIsReconnecting(true);
|
||||
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
@@ -148,3 +148,23 @@ class TestingReconnectionPolicy extends ReconnectionPolicy {
|
||||
@override
|
||||
Future<void> reset() async {}
|
||||
}
|
||||
|
||||
/// A reconnection policy for tests that waits a constant number of seconds before
|
||||
/// attempting a reconnection.
|
||||
@visibleForTesting
|
||||
class TestingSleepReconnectionPolicy extends ReconnectionPolicy {
|
||||
TestingSleepReconnectionPolicy(this._sleepAmount) : super();
|
||||
final int _sleepAmount;
|
||||
|
||||
@override
|
||||
Future<void> onSuccess() async {}
|
||||
|
||||
@override
|
||||
Future<void> onFailure() async {
|
||||
await Future<void>.delayed(Duration(seconds: _sleepAmount));
|
||||
await performReconnect!();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> reset() async {}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ class DiscoManager extends XmppManagerBase {
|
||||
final query = stanza.firstTag('query')!;
|
||||
final node = query.attributes['node'] as String?;
|
||||
final capHash = await presence.getCapabilityHash();
|
||||
final isCapabilityNode = node == 'http://moxxy.im#$capHash';
|
||||
final isCapabilityNode = node == '${presence.capabilityHashNode}#$capHash';
|
||||
|
||||
if (!isCapabilityNode && node != null) {
|
||||
await getAttributes().sendStanza(Stanza.iq(
|
||||
@@ -200,7 +200,7 @@ class DiscoManager extends XmppManagerBase {
|
||||
xmlns: discoInfoXmlns,
|
||||
attributes: {
|
||||
...!isCapabilityNode ? {} : {
|
||||
'node': 'http://moxxy.im#$capHash'
|
||||
'node': '${presence.capabilityHashNode}#$capHash'
|
||||
}
|
||||
},
|
||||
children: [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: moxxmpp
|
||||
description: A pure-Dart XMPP library
|
||||
version: 0.1.1
|
||||
version: 0.1.2+2
|
||||
homepage: https://codeberg.org/moxxy/moxxmpp
|
||||
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
||||
|
||||
@@ -29,5 +29,8 @@ dependencies:
|
||||
|
||||
dev_dependencies:
|
||||
build_runner: ^2.1.11
|
||||
moxxmpp_socket_tcp:
|
||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
||||
version: ^0.1.2+2
|
||||
test: ^1.16.0
|
||||
very_good_analysis: ^3.0.1
|
||||
|
||||
@@ -60,7 +60,7 @@ void main() {
|
||||
StubNegotiator2(),
|
||||
])
|
||||
..registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
|
||||
@@ -53,7 +53,7 @@ void main() {
|
||||
ignoreId: true,
|
||||
),
|
||||
StringExpectation(
|
||||
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxy.im' ver='QRTBC5cg/oYd+UOTYazSQR4zb/I=' /></presence>",
|
||||
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxmpp.example' ver='QRTBC5cg/oYd+UOTYazSQR4zb/I=' /></presence>",
|
||||
'',
|
||||
),
|
||||
StanzaExpectation(
|
||||
@@ -73,7 +73,7 @@ void main() {
|
||||
allowPlainAuth: true,
|
||||
),);
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
|
||||
@@ -242,7 +242,7 @@ void main() {
|
||||
),);
|
||||
final sm = StreamManagementManager();
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
@@ -343,7 +343,7 @@ void main() {
|
||||
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
|
||||
),
|
||||
StringExpectation(
|
||||
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxy.im' ver='QRTBC5cg/oYd+UOTYazSQR4zb/I=' /></presence>",
|
||||
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxmpp.example' ver='QRTBC5cg/oYd+UOTYazSQR4zb/I=' /></presence>",
|
||||
'<iq type="result" />',
|
||||
),
|
||||
StanzaExpectation(
|
||||
@@ -364,7 +364,7 @@ void main() {
|
||||
),);
|
||||
final sm = StreamManagementManager();
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
@@ -518,7 +518,7 @@ void main() {
|
||||
allowPlainAuth: true,
|
||||
),);
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
@@ -610,7 +610,7 @@ void main() {
|
||||
allowPlainAuth: true,
|
||||
),);
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
@@ -702,7 +702,7 @@ void main() {
|
||||
allowPlainAuth: true,
|
||||
),);
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
|
||||
@@ -104,7 +104,7 @@ void main() {
|
||||
attributes: {
|
||||
// TODO: Somehow make the test ignore this attribute
|
||||
'ver': 'QRTBC5cg/oYd+UOTYazSQR4zb/I=',
|
||||
'node': 'http://moxxy.im',
|
||||
'node': 'http://moxxmpp.example',
|
||||
'hash': 'sha-1'
|
||||
},
|
||||
)
|
||||
@@ -126,7 +126,7 @@ void main() {
|
||||
allowPlainAuth: true,
|
||||
),);
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
@@ -180,7 +180,7 @@ void main() {
|
||||
allowPlainAuth: true,
|
||||
),);
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
@@ -234,7 +234,7 @@ void main() {
|
||||
allowPlainAuth: true,
|
||||
),);
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
@@ -289,7 +289,7 @@ void main() {
|
||||
allowPlainAuth: false,
|
||||
),);
|
||||
conn.registerManagers([
|
||||
PresenceManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
RosterManager(),
|
||||
DiscoManager(),
|
||||
PingManager(),
|
||||
|
||||
1
packages/moxxmpp_socket_tcp/.pubignore
Normal file
1
packages/moxxmpp_socket_tcp/.pubignore
Normal file
@@ -0,0 +1 @@
|
||||
pubspec_overrides.yaml
|
||||
@@ -1,3 +1,15 @@
|
||||
## 0.1.2+2
|
||||
|
||||
- **FIX**: Fix reconnections when the connection is awaited.
|
||||
|
||||
## 0.1.2+1
|
||||
|
||||
- **FIX**: A certificate rejection does not crash the connection.
|
||||
|
||||
## 0.1.2
|
||||
|
||||
- **FEAT**: Make onBadCertificate available.
|
||||
|
||||
## 0.1.1
|
||||
|
||||
- **REFACTOR**: Move packages into packages/.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
include: ../analysis_options.yaml
|
||||
include: ../../analysis_options.yaml
|
||||
|
||||
analyzer:
|
||||
exclude:
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:moxxmpp/moxxmpp.dart';
|
||||
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
Future<void> _runTest(String domain) async {
|
||||
var gotTLSException = false;
|
||||
final socket = TCPSocketWrapper(false);
|
||||
final log = Logger('TestLogger');
|
||||
socket.getEventStream().listen((event) {
|
||||
if (event is XmppSocketTLSFailedEvent) {
|
||||
log.info('Got XmppSocketTLSFailedEvent from socket');
|
||||
gotTLSException = true;
|
||||
}
|
||||
});
|
||||
|
||||
final connection = XmppConnection(
|
||||
ExponentialBackoffReconnectionPolicy(),
|
||||
socket,
|
||||
);
|
||||
connection.registerFeatureNegotiators([
|
||||
StartTlsNegotiator(),
|
||||
]);
|
||||
connection.registerManagers([
|
||||
DiscoManager(),
|
||||
RosterManager(),
|
||||
PingManager(),
|
||||
MessageManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
]);
|
||||
|
||||
connection.setConnectionSettings(
|
||||
ConnectionSettings(
|
||||
jid: JID.fromString('testuser@$domain'),
|
||||
password: 'abc123',
|
||||
useDirectTLS: true,
|
||||
allowPlainAuth: true,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await connection.connectAwaitable();
|
||||
expect(result.success, false);
|
||||
expect(gotTLSException, true);
|
||||
}
|
||||
|
||||
void main() {
|
||||
Logger.root.level = Level.ALL;
|
||||
Logger.root.onRecord.listen((record) {
|
||||
print('${record.level.name}: ${record.time}: ${record.message}');
|
||||
});
|
||||
|
||||
for (final domain in [
|
||||
'self-signed.badxmpp.eu',
|
||||
'expired.badxmpp.eu',
|
||||
'wrong-name.badxmpp.eu',
|
||||
'missing-chain.badxmpp.eu',
|
||||
// TODO(Unknown): Technically, this one should not fail
|
||||
//'ecdsa.badxmpp.eu',
|
||||
]) {
|
||||
test('$domain with connectAwaitable', () async {
|
||||
await _runTest(domain);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
library moxxmpp_socket_tcp;
|
||||
|
||||
export 'src/events.dart';
|
||||
export 'src/record.dart';
|
||||
export 'src/socket.dart';
|
||||
|
||||
4
packages/moxxmpp_socket_tcp/lib/src/events.dart
Normal file
4
packages/moxxmpp_socket_tcp/lib/src/events.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
import 'package:moxxmpp/moxxmpp.dart';
|
||||
|
||||
/// Triggered when TLS errors occur
|
||||
class XmppSocketTLSFailedEvent extends XmppSocketEvent {}
|
||||
@@ -4,6 +4,7 @@ import 'dart:io';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:moxxmpp/moxxmpp.dart';
|
||||
import 'package:moxxmpp_socket_tcp/src/events.dart';
|
||||
import 'package:moxxmpp_socket_tcp/src/record.dart';
|
||||
import 'package:moxxmpp_socket_tcp/src/rfc_2782.dart';
|
||||
|
||||
@@ -50,11 +51,12 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
||||
return <MoxSrvRecord>[];
|
||||
}
|
||||
|
||||
bool _onBadCertificate(dynamic certificate, String domain) {
|
||||
_log.fine('Bad certificate: ${certificate.toString()}');
|
||||
//final isExpired = certificate.endValidity.isAfter(DateTime.now());
|
||||
// TODO(Unknown): Either validate the certificate ourselves or use a platform native
|
||||
// hostname verifier (or Dart adds it themselves)
|
||||
/// Called when we encounter a certificate we cannot verify. [certificate] refers to the certificate
|
||||
/// in question, while [domain] refers to the domain we try to validate the certificate against.
|
||||
///
|
||||
/// Return true if the certificate should be accepted. Return false if it should be rejected.
|
||||
@visibleForOverriding
|
||||
bool onBadCertificate(dynamic certificate, String domain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,6 +67,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
||||
return false;
|
||||
}
|
||||
|
||||
var failedDueToTLS = false;
|
||||
results.sort(srvRecordSortComparator);
|
||||
for (final srv in results) {
|
||||
try {
|
||||
@@ -83,18 +86,26 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
||||
sock,
|
||||
host: domain,
|
||||
supportedProtocols: const [ xmppClientALPNId ],
|
||||
onBadCertificate: (cert) => _onBadCertificate(cert, domain),
|
||||
onBadCertificate: (cert) => onBadCertificate(cert, domain),
|
||||
);
|
||||
|
||||
_ignoreSocketClosure = false;
|
||||
_secure = true;
|
||||
_log.finest('Success!');
|
||||
return true;
|
||||
} on SocketException catch(e) {
|
||||
} on Exception catch(e) {
|
||||
_log.finest('Failure! $e');
|
||||
_ignoreSocketClosure = false;
|
||||
|
||||
if (e is HandshakeException) {
|
||||
failedDueToTLS = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (failedDueToTLS) {
|
||||
_eventStream.add(XmppSocketTLSFailedEvent());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -117,7 +128,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
||||
_ignoreSocketClosure = false;
|
||||
_log.finest('Success!');
|
||||
return true;
|
||||
} on SocketException catch(e) {
|
||||
} on Exception catch(e) {
|
||||
_log.finest('Failure! $e');
|
||||
_ignoreSocketClosure = false;
|
||||
continue;
|
||||
@@ -141,7 +152,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
||||
);
|
||||
_log.finest('Success!');
|
||||
return true;
|
||||
} on SocketException catch(e) {
|
||||
} on Exception catch(e) {
|
||||
_log.finest('Failure! $e');
|
||||
_ignoreSocketClosure = false;
|
||||
return false;
|
||||
@@ -175,15 +186,21 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
||||
_socket = await SecureSocket.secure(
|
||||
_socket!,
|
||||
supportedProtocols: const [ xmppClientALPNId ],
|
||||
onBadCertificate: (cert) => _onBadCertificate(cert, domain),
|
||||
onBadCertificate: (cert) => onBadCertificate(cert, domain),
|
||||
);
|
||||
|
||||
_secure = true;
|
||||
_ignoreSocketClosure = false;
|
||||
_setupStreams();
|
||||
return true;
|
||||
} on SocketException {
|
||||
} on Exception catch (e) {
|
||||
_log.severe('Failed to secure socket: $e');
|
||||
_ignoreSocketClosure = false;
|
||||
|
||||
if (e is HandshakeException) {
|
||||
_eventStream.add(XmppSocketTLSFailedEvent());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -292,7 +309,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
||||
|
||||
try {
|
||||
_socket!.write(data);
|
||||
} on SocketException catch (e) {
|
||||
} on Exception catch (e) {
|
||||
_log.severe(e);
|
||||
_eventStream.add(XmppSocketErrorEvent(e));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: moxxmpp_socket_tcp
|
||||
description: A socket for moxxmpp using TCP that implements the RFC6120 connection algorithm and XEP-0368
|
||||
version: 0.1.1
|
||||
version: 0.1.2+2
|
||||
homepage: https://codeberg.org/moxxy/moxxmpp
|
||||
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
||||
|
||||
@@ -12,7 +12,7 @@ dependencies:
|
||||
meta: ^1.6.0
|
||||
moxxmpp:
|
||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
||||
version: ^0.1.1
|
||||
version: ^0.1.2+2
|
||||
|
||||
dev_dependencies:
|
||||
lints: ^2.0.0
|
||||
|
||||
Reference in New Issue
Block a user