feat: Make moxxmpp_socket Flutter independent

This commit is contained in:
PapaTutuWawa 2022-11-08 16:58:36 +01:00
parent 4855a289d9
commit 565089e1c8
8 changed files with 38 additions and 18 deletions

View File

@ -10,8 +10,8 @@ This package contains the actual XMPP code that is platform-independent.
### moxxmpp_socket
`moxxmpp_socket` contains the implementation of the `BaseSocketWrapper` class that
allows the user to resolve SRV records and thus support XEP-0368. Due to how DNS
resolution is implemented, Flutter is required.
implements the RFC6120 connection algorithm and XEP-0368 direct TLS connections,
if a DNS implementation is given, and supports StartTLS.
## License

View File

@ -1,4 +0,0 @@
# This is a generated file; do not edit or check into version control.
moxdns=/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns-0.1.4/
moxdns_android=/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns_android-0.1.4/
moxdns_linux=/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns_linux-0.1.4/

View File

@ -1 +0,0 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[],"android":[{"name":"moxdns_android","path":"/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns_android-0.1.4/","native_build":true,"dependencies":[]}],"macos":[],"linux":[{"name":"moxdns_linux","path":"/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns_linux-0.1.4/","native_build":true,"dependencies":[]}],"windows":[],"web":[]},"dependencyGraph":[{"name":"moxdns","dependencies":["moxdns_android","moxdns_linux"]},{"name":"moxdns_android","dependencies":["moxdns"]},{"name":"moxdns_linux","dependencies":["moxdns"]}],"date_created":"2022-11-08 14:21:52.966343","version":"3.3.3"}

View File

@ -1,6 +1,15 @@
# moxxmpp_socket
A socket for moxxmpp that does SRV resolution.
A socket for moxxmpp that implements the connection algorithm as specified by
[RFC6210](https://xmpp.org/rfcs/rfc6120.html) and [XEP-0368](https://xmpp.org/extensions/xep-0368.html),
while also supporting StartTLS and direct TLS.
In order to make this package independent of Flutter, I removed DNS SRV resolution from
the package. The `TCPSocketWrapper` contains a method called `srvQuery` that can be
overridden by the user. It takes the domain to query and a DNSSEC flag and is expected
to return the list of SRV records, encoded by `MoxSrvRecord` objects. To perform the
resolution, one can use any DNS library. A Flutter plugin implementing SRV resolution
is, for example, [moxdns](https://codeberg.org/moxxy/moxdns).
## License

View File

@ -0,0 +1,8 @@
/// A data class to represent a DNS SRV record.
class MoxSrvRecord {
MoxSrvRecord(this.priority, this.weight, this.target, this.port);
final int priority;
final int weight;
final int port;
final String target;
}

View File

@ -1,7 +1,7 @@
import 'package:moxdns/moxdns.dart';
import 'package:moxxmpp_socket/src/record.dart';
/// Sorts the SRV records according to priority and weight.
int srvRecordSortComparator(SrvRecord a, SrvRecord b) {
int srvRecordSortComparator(MoxSrvRecord a, MoxSrvRecord b) {
if (a.priority < b.priority) {
return -1;
} else {

View File

@ -2,8 +2,9 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:logging/logging.dart';
import 'package:moxdns/moxdns.dart';
import 'package:meta/meta.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket/src/record.dart';
import 'package:moxxmpp_socket/src/rfc_2782.dart';
/// TCP socket implementation for XmppConnection
@ -39,6 +40,16 @@ class TCPSocketWrapper extends BaseSocketWrapper {
_socketSubscription?.cancel();
}
/// Called on connect to perform a SRV query against [domain]. If [dnssec] is true,
/// then DNSSEC validation should be performed.
///
/// Returns a list of SRV records. If none are available or an error occured, an empty
/// list is returned.
@visibleForOverriding
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
return <MoxSrvRecord>[];
}
bool _onBadCertificate(dynamic certificate, String domain) {
_log.fine('Bad certificate: ${certificate.toString()}');
//final isExpired = certificate.endValidity.isAfter(DateTime.now());
@ -49,7 +60,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
Future<bool> _xep368Connect(String domain) async {
// TODO(Unknown): Maybe do DNSSEC one day
final results = await MoxdnsPlugin.srvQuery('_xmpps-client._tcp.$domain', false);
final results = await srvQuery('_xmpps-client._tcp.$domain', false);
if (results.isEmpty) {
return false;
}
@ -90,7 +101,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
Future<bool> _rfc6120Connect(String domain) async {
// TODO(Unknown): Maybe do DNSSEC one day
final results = await MoxdnsPlugin.srvQuery('_xmpp-client._tcp.$domain', false);
final results = await srvQuery('_xmpp-client._tcp.$domain', false);
results.sort(srvRecordSortComparator);
for (final srv in results) {

View File

@ -1,18 +1,15 @@
name: moxxmpp_socket
description: A socket for moxxmpp that resolves SRV records
description: A socket for moxxmpp that implements the RFC6120 connection algorithm
version: 0.1.0
homepage: https://codeberg.org/moxxy/moxxmpp
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
environment:
sdk: '>=2.18.0 <3.0.0'
flutter: '>=2.13.0-0.1'
dependencies:
logging: 1.0.2
moxdns:
hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: 0.1.4
meta: ^1.6.0
moxxmpp:
hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: 0.1.0