Compare commits
10 Commits
c850924dd3
...
moxxmpp_so
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d9010b11c | |||
| 9cc735d854 | |||
| 988db718a2 | |||
| afaca7a558 | |||
| 3172450b70 | |||
| 848d83dc1f | |||
| 2f089535a3 | |||
| 608ba8ce4a | |||
| d5493a185a | |||
| 5641b54f8f |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -10,3 +10,6 @@ build/
|
|||||||
# Omit committing pubspec.lock for library packages; see
|
# Omit committing pubspec.lock for library packages; see
|
||||||
# https://dart.dev/guides/libraries/private-files#pubspeclock.
|
# https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||||
pubspec.lock
|
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
|
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.
|
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
|
## License
|
||||||
|
|
||||||
See `./LICENSE`.
|
See `./LICENSE`.
|
||||||
|
|||||||
@@ -12,3 +12,4 @@ analyzer:
|
|||||||
- "**/*.g.dart"
|
- "**/*.g.dart"
|
||||||
- "**/*.freezed.dart"
|
- "**/*.freezed.dart"
|
||||||
- "test/"
|
- "test/"
|
||||||
|
- "integration_test/"
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
RosterManager(),
|
RosterManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
MessageManager(),
|
MessageManager(),
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
])
|
])
|
||||||
..registerFeatureNegotiators([
|
..registerFeatureNegotiators([
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ dependencies:
|
|||||||
version: 0.1.4+1
|
version: 0.1.4+1
|
||||||
moxxmpp:
|
moxxmpp:
|
||||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
version: 0.1.0
|
version: 0.1.2+2
|
||||||
moxxmpp_socket_tcp:
|
moxxmpp_socket_tcp:
|
||||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
version: 0.1.0
|
version: 0.1.2+2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -58,9 +58,7 @@
|
|||||||
CPATH = "${pkgs.xorg.libX11.dev}/include:${pkgs.xorg.xorgproto}/include";
|
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 ];
|
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ atk cairo epoxy gdk-pixbuf glib gtk3 harfbuzz pango ];
|
||||||
|
|
||||||
ANDROID_HOME = (toString ./.) + "/.android/sdk";
|
|
||||||
JAVA_HOME = pinnedJDK;
|
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,20 @@
|
|||||||
|
## 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/.
|
||||||
|
- **FEAT**: Fix moxxmpp_socket_tcp's pubspec.
|
||||||
|
|
||||||
## 0.1.0
|
## 0.1.0
|
||||||
|
|
||||||
- Initial version copied over from Moxxyv2
|
- Initial version copied over from Moxxyv2
|
||||||
|
|||||||
@@ -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
|
/// Completers for certain actions
|
||||||
// ignore: use_late_for_private_fields_and_variables
|
// ignore: use_late_for_private_fields_and_variables
|
||||||
Completer<XmppConnectionResult>? _connectionCompleter;
|
Completer<XmppConnectionResult>? _connectionCompleter;
|
||||||
|
/// Controls whether an XmppSocketClosureEvent triggers a reconnection.
|
||||||
|
bool _socketClosureTriggersReconnect = true;
|
||||||
|
|
||||||
/// Negotiators
|
/// Negotiators
|
||||||
final Map<String, XmppFeatureNegotiatorBase> _featureNegotiators;
|
final Map<String, XmppFeatureNegotiatorBase> _featureNegotiators;
|
||||||
@@ -350,8 +352,18 @@ class XmppConnection {
|
|||||||
_log.severe('handleError: Called with null');
|
_log.severe('handleError: Called with null');
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(Unknown): This may be too harsh for every error
|
// Whenever we encounter an error that would trigger a reconnection attempt while
|
||||||
await _setConnectionState(XmppConnectionState.notConnected);
|
// 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();
|
await _reconnectionPolicy.onFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,8 +372,12 @@ class XmppConnection {
|
|||||||
if (event is XmppSocketErrorEvent) {
|
if (event is XmppSocketErrorEvent) {
|
||||||
await handleError(event.error);
|
await handleError(event.error);
|
||||||
} else if (event is XmppSocketClosureEvent) {
|
} else if (event is XmppSocketClosureEvent) {
|
||||||
|
if (_socketClosureTriggersReconnect) {
|
||||||
_log.fine('Received XmppSocketClosureEvent. Reconnecting...');
|
_log.fine('Received XmppSocketClosureEvent. Reconnecting...');
|
||||||
await _reconnectionPolicy.onFailure();
|
await _reconnectionPolicy.onFailure();
|
||||||
|
} else {
|
||||||
|
_log.fine('Received XmppSocketClosureEvent. No reconnection attempt since _socketClosureTriggersReconnect is false...');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,6 +812,9 @@ class XmppConnection {
|
|||||||
|
|
||||||
_updateRoutingState(RoutingState.handleStanzas);
|
_updateRoutingState(RoutingState.handleStanzas);
|
||||||
await _onNegotiationsDone();
|
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
|
/// Attempt to gracefully close the session
|
||||||
Future<void> disconnect() async {
|
Future<void> disconnect() async {
|
||||||
|
await _disconnect(state: XmppConnectionState.notConnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _disconnect({required XmppConnectionState state, bool triggeredByUser = true}) async {
|
||||||
_reconnectionPolicy.setShouldReconnect(false);
|
_reconnectionPolicy.setShouldReconnect(false);
|
||||||
|
_socketClosureTriggersReconnect = false;
|
||||||
|
|
||||||
|
if (triggeredByUser) {
|
||||||
getPresenceManager().sendUnavailablePresence();
|
getPresenceManager().sendUnavailablePresence();
|
||||||
|
}
|
||||||
|
|
||||||
_socket.prepareDisconnect();
|
_socket.prepareDisconnect();
|
||||||
|
|
||||||
|
if (triggeredByUser) {
|
||||||
sendRawString('</stream:stream>');
|
sendRawString('</stream:stream>');
|
||||||
await _setConnectionState(XmppConnectionState.notConnected);
|
}
|
||||||
|
|
||||||
|
await _setConnectionState(state);
|
||||||
_socket.close();
|
_socket.close();
|
||||||
|
|
||||||
|
if (triggeredByUser) {
|
||||||
// Clear Stream Management state, if available
|
// Clear Stream Management state, if available
|
||||||
await getStreamManagementManager()?.resetState();
|
await getStreamManagementManager()?.resetState();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Make sure that all required managers are registered
|
/// Make sure that all required managers are registered
|
||||||
void _runPreConnectionAssertions() {
|
void _runPreConnectionAssertions() {
|
||||||
@@ -1000,7 +1034,7 @@ class XmppConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _reconnectionPolicy.reset();
|
await _reconnectionPolicy.reset();
|
||||||
|
_socketClosureTriggersReconnect = true;
|
||||||
await _sendEvent(ConnectingEvent());
|
await _sendEvent(ConnectingEvent());
|
||||||
|
|
||||||
final smManager = getStreamManagementManager();
|
final smManager = getStreamManagementManager();
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
const smManager = 'im.moxxy.streammangementmanager';
|
const smManager = 'im.moxxmpp.streammangementmanager';
|
||||||
const discoManager = 'im.moxxy.discomanager';
|
const discoManager = 'im.moxxmpp.discomanager';
|
||||||
const messageManager = 'im.moxxy.messagemanager';
|
const messageManager = 'im.moxxmpp.messagemanager';
|
||||||
const rosterManager = 'im.moxxy.rostermanager';
|
const rosterManager = 'im.moxxmpp.rostermanager';
|
||||||
const presenceManager = 'im.moxxy.presencemanager';
|
const presenceManager = 'im.moxxmpp.presencemanager';
|
||||||
const csiManager = 'im.moxxy.csimanager';
|
const csiManager = 'im.moxxmpp.csimanager';
|
||||||
const carbonsManager = 'im.moxxy.carbonsmanager';
|
const carbonsManager = 'im.moxxmpp.carbonsmanager';
|
||||||
const vcardManager = 'im.moxxy.vcardmanager';
|
const vcardManager = 'im.moxxmpp.vcardmanager';
|
||||||
const pubsubManager = 'im.moxxy.pubsubmanager';
|
const pubsubManager = 'im.moxxmpp.pubsubmanager';
|
||||||
const userAvatarManager = 'im.moxxy.useravatarmanager';
|
const userAvatarManager = 'im.moxxmpp.useravatarmanager';
|
||||||
const stableIdManager = 'im.moxxy.stableidmanager';
|
const stableIdManager = 'im.moxxmpp.stableidmanager';
|
||||||
const simsManager = 'im.moxxy.simsmanager';
|
const simsManager = 'im.moxxmpp.simsmanager';
|
||||||
const messageDeliveryReceiptManager = 'im.moxxy.messagedeliveryreceiptmanager';
|
const messageDeliveryReceiptManager = 'im.moxxmpp.messagedeliveryreceiptmanager';
|
||||||
const chatMarkerManager = 'im.moxxy.chatmarkermanager';
|
const chatMarkerManager = 'im.moxxmpp.chatmarkermanager';
|
||||||
const oobManager = 'im.moxxy.oobmanager';
|
const oobManager = 'im.moxxmpp.oobmanager';
|
||||||
const sfsManager = 'im.moxxy.sfsmanager';
|
const sfsManager = 'im.moxxmpp.sfsmanager';
|
||||||
const messageRepliesManager = 'im.moxxy.messagerepliesmanager';
|
const messageRepliesManager = 'im.moxxmpp.messagerepliesmanager';
|
||||||
const blockingManager = 'im.moxxy.blockingmanager';
|
const blockingManager = 'im.moxxmpp.blockingmanager';
|
||||||
const httpFileUploadManager = 'im.moxxy.httpfileuploadmanager';
|
const httpFileUploadManager = 'im.moxxmpp.httpfileuploadmanager';
|
||||||
const chatStateManager = 'im.moxxy.chatstatemanager';
|
const chatStateManager = 'im.moxxmpp.chatstatemanager';
|
||||||
const pingManager = 'im.moxxy.ping';
|
const pingManager = 'im.moxxmpp.ping';
|
||||||
const fileUploadNotificationManager = 'im.moxxy.fileuploadnotificationmanager';
|
const fileUploadNotificationManager = 'im.moxxmpp.fileuploadnotificationmanager';
|
||||||
const omemoManager = 'org.moxxy.omemomanager';
|
const omemoManager = 'org.moxxmpp.omemomanager';
|
||||||
const emeManager = 'org.moxxy.ememanager';
|
const emeManager = 'org.moxxmpp.ememanager';
|
||||||
const cryptographicHashManager = 'org.moxxy.cryptographichashmanager';
|
const cryptographicHashManager = 'org.moxxmpp.cryptographichashmanager';
|
||||||
const delayedDeliveryManager = 'org.moxxy.delayeddeliverymanager';
|
const delayedDeliveryManager = 'org.moxxmpp.delayeddeliverymanager';
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const saslPlainNegotiator = 'im.moxxy.sasl.plain';
|
const saslPlainNegotiator = 'im.moxxmpp.sasl.plain';
|
||||||
const saslScramSha1Negotiator = 'im.moxxy.sasl.scram.sha1';
|
const saslScramSha1Negotiator = 'im.moxxmpp.sasl.scram.sha1';
|
||||||
const saslScramSha256Negotiator = 'im.moxxy.sasl.scram.sha256';
|
const saslScramSha256Negotiator = 'im.moxxmpp.sasl.scram.sha256';
|
||||||
const saslScramSha512Negotiator = 'im.moxxy.sasl.scram.sha512';
|
const saslScramSha512Negotiator = 'im.moxxmpp.sasl.scram.sha512';
|
||||||
const csiNegotiator = 'im.moxxy.xeps.csi';
|
const csiNegotiator = 'im.moxxmpp.xeps.csi';
|
||||||
const rosterNegotiator = 'im.moxxy.core.roster';
|
const rosterNegotiator = 'im.moxxmpp.core.roster';
|
||||||
const resourceBindingNegotiator = 'im.moxxy.core.resource';
|
const resourceBindingNegotiator = 'im.moxxmpp.core.resource';
|
||||||
const streamManagementNegotiator = 'im.moxxy.xeps.sm';
|
const streamManagementNegotiator = 'im.moxxmpp.xeps.sm';
|
||||||
const startTlsNegotiator = 'im.moxxy.core.starttls';
|
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';
|
import 'package:moxxmpp/src/xeps/xep_0414.dart';
|
||||||
|
|
||||||
class PresenceManager extends XmppManagerBase {
|
class PresenceManager extends XmppManagerBase {
|
||||||
|
PresenceManager(this._capHashNode) : _capabilityHash = null, super();
|
||||||
PresenceManager() : _capabilityHash = null, super();
|
|
||||||
String? _capabilityHash;
|
String? _capabilityHash;
|
||||||
|
final String _capHashNode;
|
||||||
|
|
||||||
|
String get capabilityHashNode => _capHashNode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getId() => presenceManager;
|
String getId() => presenceManager;
|
||||||
@@ -93,7 +95,7 @@ class PresenceManager extends XmppManagerBase {
|
|||||||
xmlns: capsXmlns,
|
xmlns: capsXmlns,
|
||||||
attributes: {
|
attributes: {
|
||||||
'hash': 'sha-1',
|
'hash': 'sha-1',
|
||||||
'node': 'http://moxxy.im',
|
'node': _capHashNode,
|
||||||
'ver': await getCapabilityHash()
|
'ver': await getCapabilityHash()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ class ExponentialBackoffReconnectionPolicy extends ReconnectionPolicy {
|
|||||||
final isReconnecting = await isReconnectionRunning();
|
final isReconnecting = await isReconnectionRunning();
|
||||||
if (shouldReconnect) {
|
if (shouldReconnect) {
|
||||||
if (!isReconnecting) {
|
if (!isReconnecting) {
|
||||||
|
await setIsReconnecting(true);
|
||||||
await performReconnect!();
|
await performReconnect!();
|
||||||
} else {
|
} else {
|
||||||
// Should never happen.
|
// Should never happen.
|
||||||
@@ -117,7 +118,6 @@ class ExponentialBackoffReconnectionPolicy extends ReconnectionPolicy {
|
|||||||
Future<void> onFailure() async {
|
Future<void> onFailure() async {
|
||||||
_log.finest('Failure occured. Starting exponential backoff');
|
_log.finest('Failure occured. Starting exponential backoff');
|
||||||
_counter++;
|
_counter++;
|
||||||
await setIsReconnecting(true);
|
|
||||||
|
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
@@ -148,3 +148,23 @@ class TestingReconnectionPolicy extends ReconnectionPolicy {
|
|||||||
@override
|
@override
|
||||||
Future<void> reset() async {}
|
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 query = stanza.firstTag('query')!;
|
||||||
final node = query.attributes['node'] as String?;
|
final node = query.attributes['node'] as String?;
|
||||||
final capHash = await presence.getCapabilityHash();
|
final capHash = await presence.getCapabilityHash();
|
||||||
final isCapabilityNode = node == 'http://moxxy.im#$capHash';
|
final isCapabilityNode = node == '${presence.capabilityHashNode}#$capHash';
|
||||||
|
|
||||||
if (!isCapabilityNode && node != null) {
|
if (!isCapabilityNode && node != null) {
|
||||||
await getAttributes().sendStanza(Stanza.iq(
|
await getAttributes().sendStanza(Stanza.iq(
|
||||||
@@ -200,7 +200,7 @@ class DiscoManager extends XmppManagerBase {
|
|||||||
xmlns: discoInfoXmlns,
|
xmlns: discoInfoXmlns,
|
||||||
attributes: {
|
attributes: {
|
||||||
...!isCapabilityNode ? {} : {
|
...!isCapabilityNode ? {} : {
|
||||||
'node': 'http://moxxy.im#$capHash'
|
'node': '${presence.capabilityHashNode}#$capHash'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
name: moxxmpp
|
name: moxxmpp
|
||||||
description: A pure-Dart XMPP library
|
description: A pure-Dart XMPP library
|
||||||
version: 0.1.0
|
version: 0.1.2+2
|
||||||
homepage: https://codeberg.org/moxxy/moxxmpp
|
homepage: https://codeberg.org/moxxy/moxxmpp
|
||||||
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.18.0 <3.0.0'
|
sdk: '>=2.17.5 <3.0.0'
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
cryptography: ^2.0.5
|
cryptography: ^2.0.5
|
||||||
@@ -29,5 +29,8 @@ dependencies:
|
|||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.1.11
|
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
|
test: ^1.16.0
|
||||||
very_good_analysis: ^3.0.1
|
very_good_analysis: ^3.0.1
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void main() {
|
|||||||
StubNegotiator2(),
|
StubNegotiator2(),
|
||||||
])
|
])
|
||||||
..registerManagers([
|
..registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ void main() {
|
|||||||
ignoreId: true,
|
ignoreId: true,
|
||||||
),
|
),
|
||||||
StringExpectation(
|
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(
|
StanzaExpectation(
|
||||||
@@ -73,7 +73,7 @@ void main() {
|
|||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
),);
|
),);
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ void main() {
|
|||||||
),);
|
),);
|
||||||
final sm = StreamManagementManager();
|
final sm = StreamManagementManager();
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
@@ -343,7 +343,7 @@ void main() {
|
|||||||
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
|
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
|
||||||
),
|
),
|
||||||
StringExpectation(
|
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" />',
|
'<iq type="result" />',
|
||||||
),
|
),
|
||||||
StanzaExpectation(
|
StanzaExpectation(
|
||||||
@@ -364,7 +364,7 @@ void main() {
|
|||||||
),);
|
),);
|
||||||
final sm = StreamManagementManager();
|
final sm = StreamManagementManager();
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
@@ -518,7 +518,7 @@ void main() {
|
|||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
),);
|
),);
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
@@ -610,7 +610,7 @@ void main() {
|
|||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
),);
|
),);
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
@@ -702,7 +702,7 @@ void main() {
|
|||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
),);
|
),);
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ void main() {
|
|||||||
attributes: {
|
attributes: {
|
||||||
// TODO: Somehow make the test ignore this attribute
|
// TODO: Somehow make the test ignore this attribute
|
||||||
'ver': 'QRTBC5cg/oYd+UOTYazSQR4zb/I=',
|
'ver': 'QRTBC5cg/oYd+UOTYazSQR4zb/I=',
|
||||||
'node': 'http://moxxy.im',
|
'node': 'http://moxxmpp.example',
|
||||||
'hash': 'sha-1'
|
'hash': 'sha-1'
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -126,7 +126,7 @@ void main() {
|
|||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
),);
|
),);
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
@@ -180,7 +180,7 @@ void main() {
|
|||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
),);
|
),);
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
@@ -234,7 +234,7 @@ void main() {
|
|||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
),);
|
),);
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
@@ -289,7 +289,7 @@ void main() {
|
|||||||
allowPlainAuth: false,
|
allowPlainAuth: false,
|
||||||
),);
|
),);
|
||||||
conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager('http://moxxmpp.example'),
|
||||||
RosterManager(),
|
RosterManager(),
|
||||||
DiscoManager(),
|
DiscoManager(),
|
||||||
PingManager(),
|
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,20 @@
|
|||||||
|
## 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/.
|
||||||
|
- **FEAT**: Fix moxxmpp_socket_tcp's pubspec.
|
||||||
|
|
||||||
## 0.1.0
|
## 0.1.0
|
||||||
|
|
||||||
- Initial version.
|
- Initial version.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
include: ../analysis_options.yaml
|
include: ../../analysis_options.yaml
|
||||||
|
|
||||||
analyzer:
|
analyzer:
|
||||||
exclude:
|
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;
|
library moxxmpp_socket_tcp;
|
||||||
|
|
||||||
|
export 'src/events.dart';
|
||||||
export 'src/record.dart';
|
export 'src/record.dart';
|
||||||
export 'src/socket.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:logging/logging.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:moxxmpp/moxxmpp.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/record.dart';
|
||||||
import 'package:moxxmpp_socket_tcp/src/rfc_2782.dart';
|
import 'package:moxxmpp_socket_tcp/src/rfc_2782.dart';
|
||||||
|
|
||||||
@@ -50,11 +51,12 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
return <MoxSrvRecord>[];
|
return <MoxSrvRecord>[];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _onBadCertificate(dynamic certificate, String domain) {
|
/// Called when we encounter a certificate we cannot verify. [certificate] refers to the certificate
|
||||||
_log.fine('Bad certificate: ${certificate.toString()}');
|
/// in question, while [domain] refers to the domain we try to validate the certificate against.
|
||||||
//final isExpired = certificate.endValidity.isAfter(DateTime.now());
|
///
|
||||||
// TODO(Unknown): Either validate the certificate ourselves or use a platform native
|
/// Return true if the certificate should be accepted. Return false if it should be rejected.
|
||||||
// hostname verifier (or Dart adds it themselves)
|
@visibleForOverriding
|
||||||
|
bool onBadCertificate(dynamic certificate, String domain) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var failedDueToTLS = false;
|
||||||
results.sort(srvRecordSortComparator);
|
results.sort(srvRecordSortComparator);
|
||||||
for (final srv in results) {
|
for (final srv in results) {
|
||||||
try {
|
try {
|
||||||
@@ -83,18 +86,26 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
sock,
|
sock,
|
||||||
host: domain,
|
host: domain,
|
||||||
supportedProtocols: const [ xmppClientALPNId ],
|
supportedProtocols: const [ xmppClientALPNId ],
|
||||||
onBadCertificate: (cert) => _onBadCertificate(cert, domain),
|
onBadCertificate: (cert) => onBadCertificate(cert, domain),
|
||||||
);
|
);
|
||||||
|
|
||||||
_ignoreSocketClosure = false;
|
_ignoreSocketClosure = false;
|
||||||
_secure = true;
|
_secure = true;
|
||||||
_log.finest('Success!');
|
_log.finest('Success!');
|
||||||
return true;
|
return true;
|
||||||
} on SocketException catch(e) {
|
} on Exception catch(e) {
|
||||||
_log.finest('Failure! $e');
|
_log.finest('Failure! $e');
|
||||||
_ignoreSocketClosure = false;
|
_ignoreSocketClosure = false;
|
||||||
|
|
||||||
|
if (e is HandshakeException) {
|
||||||
|
failedDueToTLS = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failedDueToTLS) {
|
||||||
|
_eventStream.add(XmppSocketTLSFailedEvent());
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -117,7 +128,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
_ignoreSocketClosure = false;
|
_ignoreSocketClosure = false;
|
||||||
_log.finest('Success!');
|
_log.finest('Success!');
|
||||||
return true;
|
return true;
|
||||||
} on SocketException catch(e) {
|
} on Exception catch(e) {
|
||||||
_log.finest('Failure! $e');
|
_log.finest('Failure! $e');
|
||||||
_ignoreSocketClosure = false;
|
_ignoreSocketClosure = false;
|
||||||
continue;
|
continue;
|
||||||
@@ -141,7 +152,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
);
|
);
|
||||||
_log.finest('Success!');
|
_log.finest('Success!');
|
||||||
return true;
|
return true;
|
||||||
} on SocketException catch(e) {
|
} on Exception catch(e) {
|
||||||
_log.finest('Failure! $e');
|
_log.finest('Failure! $e');
|
||||||
_ignoreSocketClosure = false;
|
_ignoreSocketClosure = false;
|
||||||
return false;
|
return false;
|
||||||
@@ -175,15 +186,21 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
_socket = await SecureSocket.secure(
|
_socket = await SecureSocket.secure(
|
||||||
_socket!,
|
_socket!,
|
||||||
supportedProtocols: const [ xmppClientALPNId ],
|
supportedProtocols: const [ xmppClientALPNId ],
|
||||||
onBadCertificate: (cert) => _onBadCertificate(cert, domain),
|
onBadCertificate: (cert) => onBadCertificate(cert, domain),
|
||||||
);
|
);
|
||||||
|
|
||||||
_secure = true;
|
_secure = true;
|
||||||
_ignoreSocketClosure = false;
|
_ignoreSocketClosure = false;
|
||||||
_setupStreams();
|
_setupStreams();
|
||||||
return true;
|
return true;
|
||||||
} on SocketException {
|
} on Exception catch (e) {
|
||||||
|
_log.severe('Failed to secure socket: $e');
|
||||||
_ignoreSocketClosure = false;
|
_ignoreSocketClosure = false;
|
||||||
|
|
||||||
|
if (e is HandshakeException) {
|
||||||
|
_eventStream.add(XmppSocketTLSFailedEvent());
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,7 +309,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
_socket!.write(data);
|
_socket!.write(data);
|
||||||
} on SocketException catch (e) {
|
} on Exception catch (e) {
|
||||||
_log.severe(e);
|
_log.severe(e);
|
||||||
_eventStream.add(XmppSocketErrorEvent(e));
|
_eventStream.add(XmppSocketErrorEvent(e));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
name: moxxmpp_socket_tcp
|
name: moxxmpp_socket_tcp
|
||||||
description: A socket for moxxmpp using TCP that implements the RFC6120 connection algorithm and XEP-0368
|
description: A socket for moxxmpp using TCP that implements the RFC6120 connection algorithm and XEP-0368
|
||||||
version: 0.1.0
|
version: 0.1.2+2
|
||||||
homepage: https://codeberg.org/moxxy/moxxmpp
|
homepage: https://codeberg.org/moxxy/moxxmpp
|
||||||
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.18.0 <3.0.0'
|
sdk: '>=2.17.5 <3.0.0'
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
logging: ^1.0.2
|
logging: ^1.0.2
|
||||||
meta: ^1.6.0
|
meta: ^1.6.0
|
||||||
moxxmpp:
|
moxxmpp:
|
||||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
version: ^0.1.0
|
version: ^0.1.2+2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
lints: ^2.0.0
|
lints: ^2.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user