Extend error information in json output for received messages from untrusted identity

Fixes #91
This commit is contained in:
AsamK 2021-08-22 19:28:13 +02:00
parent 4f67ac674b
commit 9a9dd3b217
3 changed files with 18 additions and 2 deletions

View file

@ -28,8 +28,9 @@ public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler
if (exception != null) { if (exception != null) {
object.put("error", new JsonError(exception)); object.put("error", new JsonError(exception));
} }
if (envelope != null) { if (envelope != null) {
object.put("envelope", new JsonMessageEnvelope(envelope, content, m)); object.put("envelope", new JsonMessageEnvelope(envelope, content, exception, m));
} }
jsonWriter.write(object); jsonWriter.write(object);

View file

@ -7,7 +7,11 @@ public class JsonError {
@JsonProperty @JsonProperty
final String message; final String message;
@JsonProperty
final String type;
public JsonError(Throwable exception) { public JsonError(Throwable exception) {
this.message = exception.getMessage(); this.message = exception.getMessage();
this.type = exception.getClass().getSimpleName();
} }
} }

View file

@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.Signal; import org.asamk.Signal;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.signal.libsignal.metadata.ProtocolUntrustedIdentityException;
import org.whispersystems.signalservice.api.messages.SignalServiceContent; import org.whispersystems.signalservice.api.messages.SignalServiceContent;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope; import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.util.InvalidNumberException; import org.whispersystems.signalservice.api.util.InvalidNumberException;
@ -59,7 +60,9 @@ public class JsonMessageEnvelope {
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
final JsonTypingMessage typingMessage; final JsonTypingMessage typingMessage;
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content, Manager m) { public JsonMessageEnvelope(
SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception, Manager m
) {
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) { if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
var source = envelope.getSourceAddress(); var source = envelope.getSourceAddress();
this.source = getLegacyIdentifier(source); this.source = getLegacyIdentifier(source);
@ -74,6 +77,14 @@ public class JsonMessageEnvelope {
this.sourceUuid = source.getUuid().transform(UUID::toString).orNull(); this.sourceUuid = source.getUuid().transform(UUID::toString).orNull();
this.sourceDevice = content.getSenderDevice(); this.sourceDevice = content.getSenderDevice();
this.relay = null; this.relay = null;
} else if (exception instanceof ProtocolUntrustedIdentityException) {
var e = (ProtocolUntrustedIdentityException) exception;
final var source = m.resolveSignalServiceAddress(e.getSender());
this.source = getLegacyIdentifier(source);
this.sourceNumber = source.getNumber().orNull();
this.sourceUuid = source.getUuid().transform(UUID::toString).orNull();
this.sourceDevice = e.getSenderDevice();
this.relay = null;
} else { } else {
this.source = null; this.source = null;
this.sourceNumber = null; this.sourceNumber = null;