mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Add additional logging
This commit is contained in:
parent
fba7a6a75c
commit
e3fcc9b3ba
4 changed files with 37 additions and 13 deletions
|
@ -184,6 +184,11 @@
|
||||||
"name":"java.lang.String",
|
"name":"java.lang.String",
|
||||||
"allPublicMethods":true}
|
"allPublicMethods":true}
|
||||||
,
|
,
|
||||||
|
{
|
||||||
|
"name":"java.lang.Throwable",
|
||||||
|
"queryAllPublicMethods":true,
|
||||||
|
"methods":[{"name":"addSuppressed","parameterTypes":["java.lang.Throwable"] }]}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
"name":"java.lang.reflect.Method",
|
"name":"java.lang.reflect.Method",
|
||||||
"methods":[{"name":"isDefault","parameterTypes":[] }]}
|
"methods":[{"name":"isDefault","parameterTypes":[] }]}
|
||||||
|
|
|
@ -122,11 +122,14 @@ public class SignalAccount implements Closeable {
|
||||||
public static SignalAccount load(
|
public static SignalAccount load(
|
||||||
File dataPath, String account, boolean waitForLock, final TrustNewIdentity trustNewIdentity
|
File dataPath, String account, boolean waitForLock, final TrustNewIdentity trustNewIdentity
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
|
logger.trace("Opening account file");
|
||||||
final var fileName = getFileName(dataPath, account);
|
final var fileName = getFileName(dataPath, account);
|
||||||
final var pair = openFileChannel(fileName, waitForLock);
|
final var pair = openFileChannel(fileName, waitForLock);
|
||||||
try {
|
try {
|
||||||
var signalAccount = new SignalAccount(pair.first(), pair.second());
|
var signalAccount = new SignalAccount(pair.first(), pair.second());
|
||||||
|
logger.trace("Loading account file");
|
||||||
signalAccount.load(dataPath, trustNewIdentity);
|
signalAccount.load(dataPath, trustNewIdentity);
|
||||||
|
logger.trace("Migrating legacy parts of account file");
|
||||||
signalAccount.migrateLegacyConfigs();
|
signalAccount.migrateLegacyConfigs();
|
||||||
|
|
||||||
if (!account.equals(signalAccount.getAccount())) {
|
if (!account.equals(signalAccount.getAccount())) {
|
||||||
|
|
|
@ -84,6 +84,7 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
|
||||||
final var identityInfo = loadIdentityLocked(recipientId);
|
final var identityInfo = loadIdentityLocked(recipientId);
|
||||||
if (identityInfo != null && identityInfo.getIdentityKey().equals(identityKey)) {
|
if (identityInfo != null && identityInfo.getIdentityKey().equals(identityKey)) {
|
||||||
// Identity already exists, not updating the trust level
|
// Identity already exists, not updating the trust level
|
||||||
|
logger.trace("Not storing new identity for recipient {}, identity already stored", recipientId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,18 +102,23 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
|
||||||
isRetryingDecryption = retryingDecryption;
|
isRetryingDecryption = retryingDecryption;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setIdentityTrustLevel(
|
public boolean setIdentityTrustLevel(RecipientId recipientId, IdentityKey identityKey, TrustLevel trustLevel) {
|
||||||
RecipientId recipientId, IdentityKey identityKey, TrustLevel trustLevel
|
|
||||||
) {
|
|
||||||
synchronized (cachedIdentities) {
|
synchronized (cachedIdentities) {
|
||||||
final var identityInfo = loadIdentityLocked(recipientId);
|
final var identityInfo = loadIdentityLocked(recipientId);
|
||||||
if (identityInfo == null
|
if (identityInfo == null) {
|
||||||
|| !identityInfo.getIdentityKey().equals(identityKey)
|
logger.debug("Not updating trust level for recipient {}, identity not found", recipientId);
|
||||||
|| identityInfo.getTrustLevel() == trustLevel) {
|
return false;
|
||||||
// Identity not found or trust not changed, not updating the trust level
|
}
|
||||||
|
if (!identityInfo.getIdentityKey().equals(identityKey)) {
|
||||||
|
logger.debug("Not updating trust level for recipient {}, different identity found", recipientId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (identityInfo.getTrustLevel() == trustLevel) {
|
||||||
|
logger.debug("Not updating trust level for recipient {}, trust level already matches", recipientId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug("Updating trust level for recipient {} with trust {}", recipientId, trustLevel);
|
||||||
final var newIdentityInfo = new IdentityInfo(recipientId,
|
final var newIdentityInfo = new IdentityInfo(recipientId,
|
||||||
identityKey,
|
identityKey,
|
||||||
trustLevel,
|
trustLevel,
|
||||||
|
@ -134,20 +140,24 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
|
||||||
// TODO implement possibility for different handling of incoming/outgoing trust decisions
|
// TODO implement possibility for different handling of incoming/outgoing trust decisions
|
||||||
var identityInfo = loadIdentityLocked(recipientId);
|
var identityInfo = loadIdentityLocked(recipientId);
|
||||||
if (identityInfo == null) {
|
if (identityInfo == null) {
|
||||||
// Identity not found
|
logger.debug("Initial identity found for {}, saving.", recipientId);
|
||||||
saveIdentity(address, identityKey);
|
saveIdentity(address, identityKey);
|
||||||
return trustNewIdentity == TrustNewIdentity.ON_FIRST_USE;
|
identityInfo = loadIdentityLocked(recipientId);
|
||||||
}
|
} else if (!identityInfo.getIdentityKey().equals(identityKey)) {
|
||||||
|
|
||||||
if (!identityInfo.getIdentityKey().equals(identityKey)) {
|
|
||||||
// Identity found, but different
|
// Identity found, but different
|
||||||
if (direction == Direction.SENDING) {
|
if (direction == Direction.SENDING) {
|
||||||
|
logger.debug("Changed identity found for {}, saving.", recipientId);
|
||||||
saveIdentity(address, identityKey);
|
saveIdentity(address, identityKey);
|
||||||
identityInfo = loadIdentityLocked(recipientId);
|
identityInfo = loadIdentityLocked(recipientId);
|
||||||
|
} else {
|
||||||
|
logger.trace("Trusting identity for {} for {}: {}", recipientId, direction, false);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return identityInfo.isTrusted();
|
final var isTrusted = identityInfo != null && identityInfo.isTrusted();
|
||||||
|
logger.trace("Trusting identity for {} for {}: {}", recipientId, direction, isTrusted);
|
||||||
|
return isTrusted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +249,10 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeIdentityLocked(final RecipientId recipientId, final IdentityInfo identityInfo) {
|
private void storeIdentityLocked(final RecipientId recipientId, final IdentityInfo identityInfo) {
|
||||||
|
logger.trace("Storing identity info for {}, trust: {}, added: {}",
|
||||||
|
recipientId,
|
||||||
|
identityInfo.getTrustLevel(),
|
||||||
|
identityInfo.getDateAdded());
|
||||||
cachedIdentities.put(recipientId, identityInfo);
|
cachedIdentities.put(recipientId, identityInfo);
|
||||||
|
|
||||||
var storage = new IdentityStorage(Base64.getEncoder().encodeToString(identityInfo.getIdentityKey().serialize()),
|
var storage = new IdentityStorage(Base64.getEncoder().encodeToString(identityInfo.getIdentityKey().serialize()),
|
||||||
|
|
|
@ -290,6 +290,7 @@ public class App {
|
||||||
final TrustNewIdentity trustNewIdentity
|
final TrustNewIdentity trustNewIdentity
|
||||||
) throws CommandException {
|
) throws CommandException {
|
||||||
Manager manager;
|
Manager manager;
|
||||||
|
logger.trace("Loading account file for {}", account);
|
||||||
try {
|
try {
|
||||||
manager = Manager.init(account, dataPath, serviceEnvironment, BaseConfig.USER_AGENT, trustNewIdentity);
|
manager = Manager.init(account, dataPath, serviceEnvironment, BaseConfig.USER_AGENT, trustNewIdentity);
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
|
@ -304,6 +305,7 @@ public class App {
|
||||||
+ ")", e);
|
+ ")", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.trace("Checking account state");
|
||||||
try {
|
try {
|
||||||
manager.checkAccountState();
|
manager.checkAccountState();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue