Commit 5a9a7d8b authored by Finn Herzfeld's avatar Finn Herzfeld 🌵

Improve error reporting when message sending fails.

Add this to the pile of undocumented crap that signld might do
parent 16d3dbe0
Pipeline #2959 passed with stages
in 13 minutes and 17 seconds
/**
* Copyright (C) 2019 Finn Herzfeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.finn.signald;
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
class JsonNetworkFailureException {
public String number;
JsonNetworkFailureException(NetworkFailureException e) {
this.number = e.getE164number();
}
}
/**
* Copyright (C) 2019 Finn Herzfeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.finn.signald;
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
class JsonUnregisteredUserException {
public String number;
JsonUnregisteredUserException(UnregisteredUserException e) {
this.number = e.getE164Number();
}
}
/**
* Copyright (C) 2019 Finn Herzfeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.finn.signald;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.whispersystems.libsignal.IdentityKey;
import org.asamk.signal.util.Hex;
class JsonUntrustedIdentityException {
public String number;
public String fingerprint;
public String safety_number;
JsonUntrustedIdentityException(UntrustedIdentityException e, Manager m) {
this.number = e.getE164Number();
IdentityKey key = e.getIdentityKey();
this.fingerprint = Hex.toStringCondensed(key.getPublicKey().serialize());
this.safety_number = m.computeSafetyNumber(this.number, key);
}
}
......@@ -996,29 +996,19 @@ class Manager {
message = messageBuilder.build();
try {
messageSender.sendMessage(address, getAccessFor(address), message);
} catch (UntrustedIdentityException e) {
} catch(UntrustedIdentityException e) {
signalProtocolStore.saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
untrustedIdentities.add(e);
} catch (UnregisteredUserException e) {
logger.warn("UntrustedIdentityException sending message to " + e.getE164Number());
} catch(UnregisteredUserException e) {
unregisteredUsers.add(e);
} catch (PushNetworkException e) {
logger.warn("UnregisteredUserException when sending message to %s" + address.getNumber());
} catch(PushNetworkException e) {
networkExceptions.add(new NetworkFailureException(address.getNumber(), e));
logger.warn("PushNetworkException when sending message to %s" + address.getNumber());
}
}
if (!untrustedIdentities.isEmpty() || !unregisteredUsers.isEmpty() || !networkExceptions.isEmpty()) {
logger.warn("EncapsulatedExceptions being thrown!");
if(!untrustedIdentities.isEmpty()) {
logger.warn("untrustedIdentities not empty");
}
if(!unregisteredUsers.isEmpty()) {
logger.warn("unregisteredUsers not empty");
}
if(!networkExceptions.isEmpty()) {
logger.warn("networkExceptions not empty");
}
throw new EncapsulatedExceptions(untrustedIdentities, unregisteredUsers, networkExceptions);
}
}
......
......@@ -26,6 +26,10 @@ import org.whispersystems.signalservice.api.push.ContactTokenDetails;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.asamk.signal.AttachmentInvalidException;
import org.asamk.signal.UserAlreadyExists;
......@@ -233,13 +237,26 @@ public class SocketHandler implements Runnable {
}
}
if(request.recipientGroupId != null) {
byte[] groupId = Base64.decode(request.recipientGroupId);
manager.sendGroupMessage(request.messageBody, attachments, groupId, quote);
} else {
manager.sendMessage(request.messageBody, attachments, request.recipientNumber, quote);
try {
if(request.recipientGroupId != null) {
byte[] groupId = Base64.decode(request.recipientGroupId);
manager.sendGroupMessage(request.messageBody, attachments, groupId, quote);
} else {
manager.sendMessage(request.messageBody, attachments, request.recipientNumber, quote);
}
this.reply("success", new JsonStatusMessage(0, "success"), request.id);
} catch(EncapsulatedExceptions e) {
for(UntrustedIdentityException i: e.getUntrustedIdentityExceptions()) {
this.reply("untrusted_identity", new JsonUntrustedIdentityException(i, manager), request.id);
}
for(UnregisteredUserException i: e.getUnregisteredUserExceptions()) {
this.reply("unregistered_user", new JsonUnregisteredUserException(i), request.id);
}
for(NetworkFailureException i: e.getNetworkExceptions()) {
this.reply("network_failure", new JsonNetworkFailureException(i), request.id);
}
}
this.reply("success", new JsonStatusMessage(0, "success"), request.id);
}
private void listAccounts(JsonRequest request) throws JsonProcessingException, IOException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment