Use slf4j simple logger

This commit is contained in:
AsamK 2020-12-25 22:34:30 +01:00
parent 6a82029ab4
commit 5c754b6f5d
12 changed files with 237 additions and 183 deletions

View file

@ -55,6 +55,8 @@ import org.signal.zkgroup.groups.GroupSecretParams;
import org.signal.zkgroup.profiles.ClientZkProfileOperations;
import org.signal.zkgroup.profiles.ProfileKey;
import org.signal.zkgroup.profiles.ProfileKeyCredential;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyException;
@ -173,6 +175,8 @@ import static org.asamk.signal.manager.ServiceConfig.getIasKeyStore;
public class Manager implements Closeable {
final static Logger logger = LoggerFactory.getLogger(Manager.class);
private final SleepTimer timer = new UptimeSleepTimer();
private final SignalServiceConfiguration serviceConfiguration;
@ -274,7 +278,7 @@ public class Manager implements Closeable {
}
public static Manager init(
String username, String settingsPath, SignalServiceConfiguration serviceConfiguration, String userAgent
String username, File settingsPath, SignalServiceConfiguration serviceConfiguration, String userAgent
) throws IOException {
PathConfig pathConfig = PathConfig.createDefault(settingsPath);
@ -590,7 +594,7 @@ public class Manager implements Closeable {
try {
profile = retrieveRecipientProfile(address, profileKey);
} catch (IOException e) {
System.err.println("Failed to retrieve profile, ignoring: " + e.getMessage());
logger.warn("Failed to retrieve profile, ignoring: {}", e.getMessage());
profileEntry.setRequestPending(false);
return null;
}
@ -613,7 +617,7 @@ public class Manager implements Closeable {
profileAndCredential = profileHelper.retrieveProfileSync(address,
SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL);
} catch (IOException e) {
System.err.println("Failed to retrieve profile key credential, ignoring: " + e.getMessage());
logger.warn("Failed to retrieve profile key credential, ignoring: {}", e.getMessage());
return null;
}
@ -646,7 +650,7 @@ public class Manager implements Closeable {
? null
: retrieveProfileAvatar(address, encryptedProfile.getAvatar(), profileKey);
} catch (Throwable e) {
System.err.println("Failed to retrieve profile avatar, ignoring: " + e.getMessage());
logger.warn("Failed to retrieve profile avatar, ignoring: {}", e.getMessage());
}
ProfileCipher profileCipher = new ProfileCipher(profileKey);
@ -1327,7 +1331,7 @@ public class Manager implements Closeable {
try {
certificate = accountManager.getSenderCertificate();
} catch (IOException e) {
System.err.println("Failed to get sender certificate: " + e);
logger.warn("Failed to get sender certificate, ignoring: {}", e.getMessage());
return null;
}
// TODO cache for a day
@ -1366,7 +1370,7 @@ public class Manager implements Closeable {
missingUuids.stream().map(a -> a.getNumber().get()).collect(Collectors.toSet()),
CDS_MRENCLAVE);
} catch (IOException | Quote.InvalidQuoteFormatException | UnauthenticatedQuoteException | SignatureException | UnauthenticatedResponseException e) {
System.err.println("Failed to resolve uuids from server: " + e.getMessage());
logger.warn("Failed to resolve uuids from server, ignoring: {}", e.getMessage());
registeredUsers = new HashMap<>();
}
@ -1570,8 +1574,9 @@ public class Manager implements Closeable {
try {
retrieveGroupAvatarAttachment(avatar.asPointer(), groupV1.getGroupId());
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
System.err.println("Failed to retrieve group avatar (" + avatar.asPointer()
.getRemoteId() + "): " + e.getMessage());
logger.warn("Failed to retrieve avatar for group {}, ignoring: {}",
groupId.toBase64(),
e.getMessage());
}
}
}
@ -1593,7 +1598,7 @@ public class Manager implements Closeable {
}
case DELIVER:
if (groupV1 == null && !isSync) {
actions.add(new SendGroupInfoRequestAction(source, groupV1.getGroupId()));
actions.add(new SendGroupInfoRequestAction(source, groupId));
}
break;
case QUIT: {
@ -1658,10 +1663,9 @@ public class Manager implements Closeable {
try {
retrieveAttachment(attachment.asPointer());
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
System.err.println("Failed to retrieve attachment ("
+ attachment.asPointer().getRemoteId()
+ "): "
+ e.getMessage());
logger.warn("Failed to retrieve attachment ({}), ignoring: {}",
attachment.asPointer().getRemoteId(),
e.getMessage());
}
}
}
@ -1686,10 +1690,9 @@ public class Manager implements Closeable {
try {
retrieveAttachment(attachment);
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
System.err.println("Failed to retrieve attachment ("
+ attachment.getRemoteId()
+ "): "
+ e.getMessage());
logger.warn("Failed to retrieve preview image ({}), ignoring: {}",
attachment.getRemoteId(),
e.getMessage());
}
}
}
@ -1703,10 +1706,9 @@ public class Manager implements Closeable {
try {
retrieveAttachment(attachment.asPointer());
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
System.err.println("Failed to retrieve attachment ("
+ attachment.asPointer().getRemoteId()
+ "): "
+ e.getMessage());
logger.warn("Failed to retrieve quote attachment thumbnail ({}), ignoring: {}",
attachment.asPointer().getRemoteId(),
e.getMessage());
}
}
}
@ -1734,11 +1736,9 @@ public class Manager implements Closeable {
// Received a v2 group message for a v1 group, we need to locally migrate the group
account.getGroupStore().deleteGroup(groupInfo.getGroupId());
groupInfoV2 = new GroupInfoV2(groupId, groupMasterKey);
System.err.println("Locally migrated group "
+ groupInfo.getGroupId().toBase64()
+ " to group v2, id: "
+ groupInfoV2.getGroupId().toBase64()
+ " !!!");
logger.info("Locally migrated group {} to group v2, id: {}",
groupInfo.getGroupId().toBase64(),
groupInfoV2.getGroupId().toBase64());
} else if (groupInfo instanceof GroupInfoV2) {
groupInfoV2 = (GroupInfoV2) groupInfo;
} else {
@ -1757,10 +1757,13 @@ public class Manager implements Closeable {
}
if (group != null) {
storeProfileKeysFromMembers(group);
try {
retrieveGroupAvatar(groupId, groupSecretParams, group.getAvatar());
} catch (IOException e) {
System.err.println("Failed to download group avatar, ignoring ...");
final String avatar = group.getAvatar();
if (avatar != null && !avatar.isEmpty()) {
try {
retrieveGroupAvatar(groupId, groupSecretParams, avatar);
} catch (IOException e) {
logger.warn("Failed to download group avatar, ignoring: {}", e.getMessage());
}
}
}
groupInfoV2.setGroup(group);
@ -1830,7 +1833,7 @@ public class Manager implements Closeable {
try {
Files.delete(fileEntry.toPath());
} catch (IOException e) {
System.err.println("Failed to delete cached message file “" + fileEntry + "”: " + e.getMessage());
logger.warn("Failed to delete cached message file “{}”, ignoring: {}", fileEntry, e.getMessage());
}
return;
}
@ -1848,7 +1851,7 @@ public class Manager implements Closeable {
try {
Files.delete(fileEntry.toPath());
} catch (IOException e) {
System.err.println("Failed to delete cached message file “" + fileEntry + "”: " + e.getMessage());
logger.warn("Failed to delete cached message file “{}”, ignoring: {}", fileEntry, e.getMessage());
}
}
@ -1880,8 +1883,7 @@ public class Manager implements Closeable {
File cacheFile = getMessageCacheFile(source, now, envelope1.getTimestamp());
Utils.storeEnvelope(envelope1, cacheFile);
} catch (IOException e) {
System.err.println("Failed to store encrypted message in disk cache, ignoring: "
+ e.getMessage());
logger.warn("Failed to store encrypted message in disk cache, ignoring: {}", e.getMessage());
}
});
if (result.isPresent()) {
@ -1910,7 +1912,7 @@ public class Manager implements Closeable {
if (returnOnTimeout) return;
continue;
} catch (InvalidVersionException e) {
System.err.println("Ignoring error: " + e.getMessage());
logger.warn("Error while receiving messages, ignoring: {}", e.getMessage());
continue;
}
@ -1954,7 +1956,7 @@ public class Manager implements Closeable {
// Try to delete directory if empty
new File(getMessageCachePath()).delete();
} catch (IOException e) {
System.err.println("Failed to delete cached message file “" + cacheFile + "”: " + e.getMessage());
logger.warn("Failed to delete cached message file “{}”, ignoring: {}", cacheFile, e.getMessage());
}
}
}
@ -2088,16 +2090,18 @@ public class Manager implements Closeable {
}
}
} catch (Exception e) {
logger.warn("Failed to handle received sync groups “{}”, ignoring: {}",
tmpFile,
e.getMessage());
e.printStackTrace();
} finally {
if (tmpFile != null) {
try {
Files.delete(tmpFile.toPath());
} catch (IOException e) {
System.err.println("Failed to delete received groups temp file “"
+ tmpFile
+ "”: "
+ e.getMessage());
logger.warn("Failed to delete received groups temp file “{}”, ignoring: {}",
tmpFile,
e.getMessage());
}
}
}
@ -2114,8 +2118,8 @@ public class Manager implements Closeable {
try {
setGroupBlocked(groupId, true);
} catch (GroupNotFoundException e) {
System.err.println("BlockedListMessage contained groupID that was not found in GroupStore: "
+ groupId.toBase64());
logger.warn("BlockedListMessage contained groupID that was not found in GroupStore: {}",
groupId.toBase64());
}
}
}
@ -2176,10 +2180,9 @@ public class Manager implements Closeable {
try {
Files.delete(tmpFile.toPath());
} catch (IOException e) {
System.err.println("Failed to delete received contacts temp file “"
+ tmpFile
+ "”: "
+ e.getMessage());
logger.warn("Failed to delete received contacts temp file “{}”, ignoring: {}",
tmpFile,
e.getMessage());
}
}
}
@ -2275,7 +2278,9 @@ public class Manager implements Closeable {
try {
Files.delete(tmpFile.toPath());
} catch (IOException e) {
System.err.println("Failed to delete received avatar temp file “" + tmpFile + "”: " + e.getMessage());
logger.warn("Failed to delete received group avatar temp file “{}”, ignoring: {}",
tmpFile,
e.getMessage());
}
}
return outputFile;
@ -2303,7 +2308,9 @@ public class Manager implements Closeable {
try {
Files.delete(tmpFile.toPath());
} catch (IOException e) {
System.err.println("Failed to delete received avatar temp file “" + tmpFile + "”: " + e.getMessage());
logger.warn("Failed to delete received profile avatar temp file “{}”, ignoring: {}",
tmpFile,
e.getMessage());
}
}
return outputFile;
@ -2343,10 +2350,9 @@ public class Manager implements Closeable {
try {
Files.delete(tmpFile.toPath());
} catch (IOException e) {
System.err.println("Failed to delete received attachment temp file “"
+ tmpFile
+ "”: "
+ e.getMessage());
logger.warn("Failed to delete received attachment temp file “{}”, ignoring: {}",
tmpFile,
e.getMessage());
}
}
return outputFile;
@ -2397,7 +2403,7 @@ public class Manager implements Closeable {
try {
Files.delete(groupsFile.toPath());
} catch (IOException e) {
System.err.println("Failed to delete groups temp file “" + groupsFile + "”: " + e.getMessage());
logger.warn("Failed to delete groups temp file “{}”, ignoring: {}", groupsFile, e.getMessage());
}
}
}
@ -2462,7 +2468,7 @@ public class Manager implements Closeable {
try {
Files.delete(contactsFile.toPath());
} catch (IOException e) {
System.err.println("Failed to delete contacts temp file “" + contactsFile + "”: " + e.getMessage());
logger.warn("Failed to delete contacts temp file “{}”, ignoring: {}", contactsFile, e.getMessage());
}
}
}

View file

@ -1,30 +1,34 @@
package org.asamk.signal.manager;
import java.io.File;
public class PathConfig {
private final String dataPath;
private final String attachmentsPath;
private final String avatarsPath;
private final File dataPath;
private final File attachmentsPath;
private final File avatarsPath;
public static PathConfig createDefault(final String settingsPath) {
return new PathConfig(settingsPath + "/data", settingsPath + "/attachments", settingsPath + "/avatars");
public static PathConfig createDefault(final File settingsPath) {
return new PathConfig(new File(settingsPath, "/data"),
new File(settingsPath, "/attachments"),
new File(settingsPath, "/avatars"));
}
private PathConfig(final String dataPath, final String attachmentsPath, final String avatarsPath) {
private PathConfig(final File dataPath, final File attachmentsPath, final File avatarsPath) {
this.dataPath = dataPath;
this.attachmentsPath = attachmentsPath;
this.avatarsPath = avatarsPath;
}
public String getDataPath() {
return dataPath;
return dataPath.getPath();
}
public String getAttachmentsPath() {
return attachmentsPath;
return attachmentsPath.getPath();
}
public String getAvatarsPath() {
return avatarsPath;
return avatarsPath.getPath();
}
}

View file

@ -31,6 +31,7 @@ import org.whispersystems.signalservice.api.util.UptimeSleepTimer;
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
@ -45,7 +46,7 @@ public class ProvisioningManager {
private final int registrationId;
private final String password;
public ProvisioningManager(String settingsPath, SignalServiceConfiguration serviceConfiguration, String userAgent) {
public ProvisioningManager(File settingsPath, SignalServiceConfiguration serviceConfiguration, String userAgent) {
this.pathConfig = PathConfig.createDefault(settingsPath);
this.serviceConfiguration = serviceConfiguration;
this.userAgent = userAgent;

View file

@ -6,6 +6,7 @@ import org.asamk.signal.manager.GroupIdV2;
import org.asamk.signal.manager.GroupLinkPassword;
import org.asamk.signal.manager.GroupUtils;
import org.asamk.signal.storage.groups.GroupInfoV2;
import org.asamk.signal.storage.profiles.SignalProfile;
import org.asamk.signal.util.IOUtils;
import org.signal.storageservice.protos.groups.AccessControl;
import org.signal.storageservice.protos.groups.GroupChange;
@ -20,6 +21,8 @@ import org.signal.zkgroup.groups.GroupMasterKey;
import org.signal.zkgroup.groups.GroupSecretParams;
import org.signal.zkgroup.groups.UuidCiphertext;
import org.signal.zkgroup.profiles.ProfileKeyCredential;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil;
@ -44,6 +47,8 @@ import java.util.stream.Collectors;
public class GroupHelper {
final static Logger logger = LoggerFactory.getLogger(GroupHelper.class);
private final ProfileKeyCredentialProvider profileKeyCredentialProvider;
private final ProfileProvider profileProvider;
@ -78,7 +83,7 @@ public class GroupHelper {
groupSecretParams);
return groupsV2Api.getGroup(groupSecretParams, groupsV2AuthorizationString);
} catch (IOException | VerificationFailedException | InvalidGroupStateException e) {
System.err.println("Failed to retrieve Group V2 info, ignoring ...");
logger.warn("Failed to retrieve Group V2 info, ignoring: {}", e.getMessage());
return null;
}
}
@ -111,11 +116,11 @@ public class GroupHelper {
groupsV2Api.putNewGroup(newGroup, groupAuthForToday);
decryptedGroup = groupsV2Api.getGroup(groupSecretParams, groupAuthForToday);
} catch (IOException | VerificationFailedException | InvalidGroupStateException e) {
System.err.println("Failed to create V2 group: " + e.getMessage());
logger.warn("Failed to create V2 group: {}", e.getMessage());
return null;
}
if (decryptedGroup == null) {
System.err.println("Failed to create V2 group!");
logger.warn("Failed to create V2 group, unknown error!");
return null;
}
@ -141,7 +146,7 @@ public class GroupHelper {
final ProfileKeyCredential profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(
selfAddressProvider.getSelfAddress());
if (profileKeyCredential == null) {
System.err.println("Cannot create a V2 group as self does not have a versioned profile");
logger.warn("Cannot create a V2 group as self does not have a versioned profile");
return null;
}
@ -165,22 +170,23 @@ public class GroupHelper {
}
private boolean areMembersValid(final Collection<SignalServiceAddress> members) {
final int noUuidCapability = members.stream()
final Set<String> noUuidCapability = members.stream()
.filter(address -> !address.getUuid().isPresent())
.collect(Collectors.toUnmodifiableSet())
.size();
if (noUuidCapability > 0) {
System.err.println("Cannot create a V2 group as " + noUuidCapability + " members don't have a UUID.");
.map(SignalServiceAddress::getLegacyIdentifier)
.collect(Collectors.toSet());
if (noUuidCapability.size() > 0) {
logger.warn("Cannot create a V2 group as some members don't have a UUID: {}",
String.join(", ", noUuidCapability));
return false;
}
final int noGv2Capability = members.stream()
final Set<SignalProfile> noGv2Capability = members.stream()
.map(profileProvider::getProfile)
.filter(profile -> profile != null && !profile.getCapabilities().gv2)
.collect(Collectors.toUnmodifiableSet())
.size();
if (noGv2Capability > 0) {
System.err.println("Cannot create a V2 group as " + noGv2Capability + " members don't support Groups V2.");
.collect(Collectors.toSet());
if (noGv2Capability.size() > 0) {
logger.warn("Cannot create a V2 group as some members don't support Groups V2: {}",
noGv2Capability.stream().map(SignalProfile::getName).collect(Collectors.joining(", ")));
return false;
}
@ -219,7 +225,9 @@ public class GroupHelper {
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(groupSecretParams);
if (!areMembersValid(newMembers)) return null;
if (!areMembersValid(newMembers)) {
throw new IOException("Failed to update group");
}
Set<GroupCandidate> candidates = newMembers.stream()
.map(member -> new GroupCandidate(member.getUuid().get(),