fix(xep): Fix failure with multiple SCRAM negotiators and SASL2

This commit is contained in:
PapaTutuWawa 2024-11-16 17:57:29 +01:00
parent 9eb94e5f48
commit 09a849c6eb
5 changed files with 26 additions and 11 deletions

View File

@ -1,2 +1,4 @@
set -ex
prosodyctl --config ./prosody.cfg.lua register testuser1 localhost abc123
prosodyctl --config ./prosody.cfg.lua register testuser2 localhost abc123

View File

@ -3,14 +3,16 @@ description: A sample command-line application.
version: 1.0.0
environment:
sdk: '>=2.18.0 <3.0.0'
sdk: ">=3.0.0 <4.0.0"
dependencies:
logging: ^1.0.2
moxxmpp: 0.3.0
moxxmpp_socket_tcp: 0.3.0
logging: ^1.3.0
moxxmpp:
path: ../packages/moxxmpp
moxxmpp_socket_tcp:
path: ../packages/moxxmpp_socket_tcp
dev_dependencies:
lints: ^2.0.0
test: ^1.16.0
very_good_analysis: ^3.0.1
build_runner: ^2.4.13
test: ^1.25.8
very_good_analysis: ^6.0.0

View File

@ -4,6 +4,8 @@ import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
import 'package:test/test.dart';
class TestingTCPSocketWrapper extends TCPSocketWrapper {
TestingTCPSocketWrapper() : super(true);
@override
bool onBadCertificate(dynamic certificate, String domain) {
return true;
@ -27,7 +29,7 @@ void main() {
ClientToServerNegotiator(),
TestingTCPSocketWrapper(),
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@localhost'),
jid: JID.fromString('testuser1@localhost'),
password: 'abc123',
host: '127.0.0.1',
port: 5222,
@ -40,6 +42,8 @@ void main() {
]);
await conn.registerFeatureNegotiators([
SaslPlainNegotiator(),
SaslScramNegotiator(9, '', '', ScramHashType.sha1),
SaslScramNegotiator(10, '', '', ScramHashType.sha256),
ResourceBindingNegotiator(),
FASTSaslNegotiator(),
Bind2Negotiator(),

View File

@ -96,7 +96,9 @@ class SaslPlainNegotiator extends Sasl2AuthenticationNegotiator {
@override
Future<Result<bool, NegotiatorError>> onSasl2Success(XMLNode response) async {
state = NegotiatorState.done;
if (pickedForSasl2) {
state = NegotiatorState.done;
}
return const Result(true);
}

View File

@ -363,6 +363,11 @@ class SaslScramNegotiator extends Sasl2AuthenticationNegotiator {
@override
Future<Result<bool, NegotiatorError>> onSasl2Success(XMLNode response) async {
// Don't do anything if we have not been picked for SASL2.
if (!pickedForSasl2) {
return const Result(true);
}
// When we're done with SASL2, check the additional data to verify the server
// signature.
state = NegotiatorState.done;