mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Extend error information in json output for received messages from untrusted identity
Fixes #91
This commit is contained in:
parent
4f67ac674b
commit
9a9dd3b217
3 changed files with 18 additions and 2 deletions
|
@ -28,8 +28,9 @@ public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler
|
|||
if (exception != null) {
|
||||
object.put("error", new JsonError(exception));
|
||||
}
|
||||
|
||||
if (envelope != null) {
|
||||
object.put("envelope", new JsonMessageEnvelope(envelope, content, m));
|
||||
object.put("envelope", new JsonMessageEnvelope(envelope, content, exception, m));
|
||||
}
|
||||
|
||||
jsonWriter.write(object);
|
||||
|
|
|
@ -7,7 +7,11 @@ public class JsonError {
|
|||
@JsonProperty
|
||||
final String message;
|
||||
|
||||
@JsonProperty
|
||||
final String type;
|
||||
|
||||
public JsonError(Throwable exception) {
|
||||
this.message = exception.getMessage();
|
||||
this.type = exception.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
|
||||
import org.asamk.Signal;
|
||||
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.SignalServiceEnvelope;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
@ -59,7 +60,9 @@ public class JsonMessageEnvelope {
|
|||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
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()) {
|
||||
var source = envelope.getSourceAddress();
|
||||
this.source = getLegacyIdentifier(source);
|
||||
|
@ -74,6 +77,14 @@ public class JsonMessageEnvelope {
|
|||
this.sourceUuid = source.getUuid().transform(UUID::toString).orNull();
|
||||
this.sourceDevice = content.getSenderDevice();
|
||||
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 {
|
||||
this.source = null;
|
||||
this.sourceNumber = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue