mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Use var instead of explicit types
This commit is contained in:
parent
03c30519b1
commit
de273586b4
77 changed files with 850 additions and 1017 deletions
|
@ -29,7 +29,7 @@ public class AvatarStore {
|
|||
}
|
||||
|
||||
public StreamDetails retrieveGroupAvatar(GroupId groupId) throws IOException {
|
||||
final File groupAvatarFile = getGroupAvatarFile(groupId);
|
||||
final var groupAvatarFile = getGroupAvatarFile(groupId);
|
||||
return retrieveAvatar(groupAvatarFile);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,14 +20,14 @@ public class DeviceLinkInfo {
|
|||
final ECPublicKey deviceKey;
|
||||
|
||||
public static DeviceLinkInfo parseDeviceLinkUri(URI linkUri) throws InvalidKeyException {
|
||||
final String rawQuery = linkUri.getRawQuery();
|
||||
final var rawQuery = linkUri.getRawQuery();
|
||||
if (isEmpty(rawQuery)) {
|
||||
throw new RuntimeException("Invalid device link uri");
|
||||
}
|
||||
|
||||
Map<String, String> query = getQueryMap(rawQuery);
|
||||
String deviceIdentifier = query.get("uuid");
|
||||
String publicKeyEncoded = query.get("pub_key");
|
||||
var query = getQueryMap(rawQuery);
|
||||
var deviceIdentifier = query.get("uuid");
|
||||
var publicKeyEncoded = query.get("pub_key");
|
||||
|
||||
if (isEmpty(deviceIdentifier) || isEmpty(publicKeyEncoded)) {
|
||||
throw new RuntimeException("Invalid device link uri");
|
||||
|
@ -39,18 +39,18 @@ public class DeviceLinkInfo {
|
|||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException("Invalid device link uri", e);
|
||||
}
|
||||
ECPublicKey deviceKey = Curve.decodePoint(publicKeyBytes, 0);
|
||||
var deviceKey = Curve.decodePoint(publicKeyBytes, 0);
|
||||
|
||||
return new DeviceLinkInfo(deviceIdentifier, deviceKey);
|
||||
}
|
||||
|
||||
private static Map<String, String> getQueryMap(String query) {
|
||||
String[] params = query.split("&");
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (String param : params) {
|
||||
final String[] paramParts = param.split("=");
|
||||
String name = URLDecoder.decode(paramParts[0], StandardCharsets.UTF_8);
|
||||
String value = URLDecoder.decode(paramParts[1], StandardCharsets.UTF_8);
|
||||
var params = query.split("&");
|
||||
var map = new HashMap<String, String>();
|
||||
for (var param : params) {
|
||||
final var paramParts = param.split("=");
|
||||
var name = URLDecoder.decode(paramParts[0], StandardCharsets.UTF_8);
|
||||
var value = URLDecoder.decode(paramParts[1], StandardCharsets.UTF_8);
|
||||
map.put(name, value);
|
||||
}
|
||||
return map;
|
||||
|
@ -62,7 +62,7 @@ public class DeviceLinkInfo {
|
|||
}
|
||||
|
||||
public String createDeviceLinkUri() {
|
||||
final String deviceKeyString = Base64.getEncoder().encodeToString(deviceKey.serialize()).replace("=", "");
|
||||
final var deviceKeyString = Base64.getEncoder().encodeToString(deviceKey.serialize()).replace("=", "");
|
||||
return "tsdevice:/?uuid="
|
||||
+ URLEncoder.encode(deviceIdentifier, StandardCharsets.UTF_8)
|
||||
+ "&pub_key="
|
||||
|
|
|
@ -29,7 +29,7 @@ class SendReceiptAction implements HandleAction {
|
|||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final SendReceiptAction that = (SendReceiptAction) o;
|
||||
final var that = (SendReceiptAction) o;
|
||||
return timestamp == that.timestamp && address.equals(that.address);
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ class SendGroupInfoRequestAction implements HandleAction {
|
|||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final SendGroupInfoRequestAction that = (SendGroupInfoRequestAction) o;
|
||||
final var that = (SendGroupInfoRequestAction) o;
|
||||
|
||||
if (!address.equals(that.address)) return false;
|
||||
return groupId.equals(that.groupId);
|
||||
|
@ -118,7 +118,7 @@ class SendGroupInfoRequestAction implements HandleAction {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = address.hashCode();
|
||||
var result = address.hashCode();
|
||||
result = 31 * result + groupId.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ class SendGroupInfoAction implements HandleAction {
|
|||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final SendGroupInfoAction that = (SendGroupInfoAction) o;
|
||||
final var that = (SendGroupInfoAction) o;
|
||||
|
||||
if (!address.equals(that.address)) return false;
|
||||
return groupId.equals(that.groupId);
|
||||
|
@ -152,7 +152,7 @@ class SendGroupInfoAction implements HandleAction {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = address.hashCode();
|
||||
var result = address.hashCode();
|
||||
result = 31 * result + groupId.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class LibSignalLogger implements SignalProtocolLogger {
|
|||
|
||||
@Override
|
||||
public void log(final int priority, final String tag, final String message) {
|
||||
final String logMessage = String.format("[%s]: %s", tag, message);
|
||||
final var logMessage = String.format("[%s]: %s", tag, message);
|
||||
switch (priority) {
|
||||
case SignalProtocolLogger.VERBOSE:
|
||||
logger.trace(logMessage);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -79,37 +79,30 @@ public class ProvisioningManager {
|
|||
public static ProvisioningManager init(
|
||||
File settingsPath, ServiceEnvironment serviceEnvironment, String userAgent
|
||||
) {
|
||||
PathConfig pathConfig = PathConfig.createDefault(settingsPath);
|
||||
var pathConfig = PathConfig.createDefault(settingsPath);
|
||||
|
||||
final ServiceEnvironmentConfig serviceConfiguration = ServiceConfig.getServiceEnvironmentConfig(
|
||||
serviceEnvironment,
|
||||
userAgent);
|
||||
final var serviceConfiguration = ServiceConfig.getServiceEnvironmentConfig(serviceEnvironment, userAgent);
|
||||
|
||||
return new ProvisioningManager(pathConfig, serviceConfiguration, userAgent);
|
||||
}
|
||||
|
||||
public String getDeviceLinkUri() throws TimeoutException, IOException {
|
||||
String deviceUuid = accountManager.getNewDeviceUuid();
|
||||
var deviceUuid = accountManager.getNewDeviceUuid();
|
||||
|
||||
return new DeviceLinkInfo(deviceUuid, identityKey.getPublicKey().getPublicKey()).createDeviceLinkUri();
|
||||
}
|
||||
|
||||
public String finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
|
||||
SignalServiceAccountManager.NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(
|
||||
identityKey,
|
||||
false,
|
||||
true,
|
||||
registrationId,
|
||||
deviceName);
|
||||
var ret = accountManager.finishNewDeviceRegistration(identityKey, false, true, registrationId, deviceName);
|
||||
|
||||
String username = ret.getNumber();
|
||||
var username = ret.getNumber();
|
||||
// TODO do this check before actually registering
|
||||
if (SignalAccount.userExists(pathConfig.getDataPath(), username)) {
|
||||
throw new UserAlreadyExists(username, SignalAccount.getFileName(pathConfig.getDataPath(), username));
|
||||
}
|
||||
|
||||
// Create new account with the synced identity
|
||||
byte[] profileKeyBytes = ret.getProfileKey();
|
||||
var profileKeyBytes = ret.getProfileKey();
|
||||
ProfileKey profileKey;
|
||||
if (profileKeyBytes == null) {
|
||||
profileKey = KeyUtils.createProfileKey();
|
||||
|
@ -121,7 +114,7 @@ public class ProvisioningManager {
|
|||
}
|
||||
}
|
||||
|
||||
try (SignalAccount account = SignalAccount.createLinkedAccount(pathConfig.getDataPath(),
|
||||
try (var account = SignalAccount.createLinkedAccount(pathConfig.getDataPath(),
|
||||
username,
|
||||
ret.getUuid(),
|
||||
password,
|
||||
|
@ -131,7 +124,7 @@ public class ProvisioningManager {
|
|||
profileKey)) {
|
||||
account.save();
|
||||
|
||||
try (Manager m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
|
||||
try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
|
||||
|
||||
try {
|
||||
m.refreshPreKeys();
|
||||
|
|
|
@ -22,12 +22,8 @@ import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
|||
import org.asamk.signal.manager.helper.PinHelper;
|
||||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
import org.asamk.signal.manager.util.KeyUtils;
|
||||
import org.signal.zkgroup.profiles.ProfileKey;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.util.KeyHelper;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.KbsPinData;
|
||||
import org.whispersystems.signalservice.api.KeyBackupService;
|
||||
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
|
||||
import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
|
||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||
|
@ -82,7 +78,7 @@ public class RegistrationManager implements Closeable {
|
|||
groupsV2Operations,
|
||||
ServiceConfig.AUTOMATIC_NETWORK_RETRY,
|
||||
timer);
|
||||
final KeyBackupService keyBackupService = accountManager.getKeyBackupService(ServiceConfig.getIasKeyStore(),
|
||||
final var keyBackupService = accountManager.getKeyBackupService(ServiceConfig.getIasKeyStore(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getEnclaveName(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getServiceId(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getMrenclave(),
|
||||
|
@ -93,17 +89,15 @@ public class RegistrationManager implements Closeable {
|
|||
public static RegistrationManager init(
|
||||
String username, File settingsPath, ServiceEnvironment serviceEnvironment, String userAgent
|
||||
) throws IOException {
|
||||
PathConfig pathConfig = PathConfig.createDefault(settingsPath);
|
||||
var pathConfig = PathConfig.createDefault(settingsPath);
|
||||
|
||||
final ServiceEnvironmentConfig serviceConfiguration = ServiceConfig.getServiceEnvironmentConfig(
|
||||
serviceEnvironment,
|
||||
userAgent);
|
||||
final var serviceConfiguration = ServiceConfig.getServiceEnvironmentConfig(serviceEnvironment, userAgent);
|
||||
if (!SignalAccount.userExists(pathConfig.getDataPath(), username)) {
|
||||
IdentityKeyPair identityKey = KeyUtils.generateIdentityKeyPair();
|
||||
int registrationId = KeyHelper.generateRegistrationId(false);
|
||||
var identityKey = KeyUtils.generateIdentityKeyPair();
|
||||
var registrationId = KeyHelper.generateRegistrationId(false);
|
||||
|
||||
ProfileKey profileKey = KeyUtils.createProfileKey();
|
||||
SignalAccount account = SignalAccount.create(pathConfig.getDataPath(),
|
||||
var profileKey = KeyUtils.createProfileKey();
|
||||
var account = SignalAccount.create(pathConfig.getDataPath(),
|
||||
username,
|
||||
identityKey,
|
||||
registrationId,
|
||||
|
@ -113,7 +107,7 @@ public class RegistrationManager implements Closeable {
|
|||
return new RegistrationManager(account, pathConfig, serviceConfiguration, userAgent);
|
||||
}
|
||||
|
||||
SignalAccount account = SignalAccount.load(pathConfig.getDataPath(), username);
|
||||
var account = SignalAccount.load(pathConfig.getDataPath(), username);
|
||||
|
||||
return new RegistrationManager(account, pathConfig, serviceConfiguration, userAgent);
|
||||
}
|
||||
|
@ -147,12 +141,12 @@ public class RegistrationManager implements Closeable {
|
|||
throw e;
|
||||
}
|
||||
|
||||
KbsPinData registrationLockData = pinHelper.getRegistrationLockData(pin, e);
|
||||
var registrationLockData = pinHelper.getRegistrationLockData(pin, e);
|
||||
if (registrationLockData == null) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
String registrationLock = registrationLockData.getMasterKey().deriveRegistrationLock();
|
||||
var registrationLock = registrationLockData.getMasterKey().deriveRegistrationLock();
|
||||
try {
|
||||
response = verifyAccountWithCode(verificationCode, null, registrationLock);
|
||||
} catch (LockedException _e) {
|
||||
|
@ -175,7 +169,7 @@ public class RegistrationManager implements Closeable {
|
|||
account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey(),
|
||||
TrustLevel.TRUSTED_VERIFIED);
|
||||
|
||||
try (Manager m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
|
||||
try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
|
||||
|
||||
m.refreshPreKeys();
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ServiceConfig {
|
|||
try {
|
||||
TrustStore contactTrustStore = new IasTrustStore();
|
||||
|
||||
KeyStore keyStore = KeyStore.getInstance("BKS");
|
||||
var keyStore = KeyStore.getInstance("BKS");
|
||||
keyStore.load(contactTrustStore.getKeyStoreInputStream(),
|
||||
contactTrustStore.getKeyStorePassword().toCharArray());
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class ServiceConfig {
|
|||
.header("User-Agent", userAgent)
|
||||
.build());
|
||||
|
||||
final List<Interceptor> interceptors = List.of(userAgentInterceptor);
|
||||
final var interceptors = List.of(userAgentInterceptor);
|
||||
|
||||
switch (serviceEnvironment) {
|
||||
case LIVE:
|
||||
|
|
|
@ -50,7 +50,7 @@ public abstract class GroupId {
|
|||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final GroupId groupId = (GroupId) o;
|
||||
final var groupId = (GroupId) o;
|
||||
|
||||
return Arrays.equals(id, groupId.id);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public final class GroupInviteLinkUrl {
|
|||
* @throws InvalidGroupLinkException If group url, but cannot be parsed.
|
||||
*/
|
||||
public static GroupInviteLinkUrl fromUri(String urlString) throws InvalidGroupLinkException, UnknownGroupLinkVersionException {
|
||||
URI uri = getGroupUrl(urlString);
|
||||
var uri = getGroupUrl(urlString);
|
||||
|
||||
if (uri == null) {
|
||||
return null;
|
||||
|
@ -46,21 +46,21 @@ public final class GroupInviteLinkUrl {
|
|||
throw new InvalidGroupLinkException("No path was expected in uri");
|
||||
}
|
||||
|
||||
String encoding = uri.getFragment();
|
||||
var encoding = uri.getFragment();
|
||||
|
||||
if (encoding == null || encoding.length() == 0) {
|
||||
throw new InvalidGroupLinkException("No reference was in the uri");
|
||||
}
|
||||
|
||||
byte[] bytes = Base64UrlSafe.decodePaddingAgnostic(encoding);
|
||||
GroupInviteLink groupInviteLink = GroupInviteLink.parseFrom(bytes);
|
||||
var bytes = Base64UrlSafe.decodePaddingAgnostic(encoding);
|
||||
var groupInviteLink = GroupInviteLink.parseFrom(bytes);
|
||||
|
||||
switch (groupInviteLink.getContentsCase()) {
|
||||
case V1CONTENTS: {
|
||||
GroupInviteLink.GroupInviteLinkContentsV1 groupInviteLinkContentsV1 = groupInviteLink.getV1Contents();
|
||||
GroupMasterKey groupMasterKey = new GroupMasterKey(groupInviteLinkContentsV1.getGroupMasterKey()
|
||||
var groupInviteLinkContentsV1 = groupInviteLink.getV1Contents();
|
||||
var groupMasterKey = new GroupMasterKey(groupInviteLinkContentsV1.getGroupMasterKey()
|
||||
.toByteArray());
|
||||
GroupLinkPassword password = GroupLinkPassword.fromBytes(groupInviteLinkContentsV1.getInviteLinkPassword()
|
||||
var password = GroupLinkPassword.fromBytes(groupInviteLinkContentsV1.getInviteLinkPassword()
|
||||
.toByteArray());
|
||||
|
||||
return new GroupInviteLinkUrl(groupMasterKey, password);
|
||||
|
@ -78,7 +78,7 @@ public final class GroupInviteLinkUrl {
|
|||
*/
|
||||
private static URI getGroupUrl(String urlString) {
|
||||
try {
|
||||
URI url = new URI(urlString);
|
||||
var url = new URI(urlString);
|
||||
|
||||
if (!"https".equalsIgnoreCase(url.getScheme()) && !"sgnl".equalsIgnoreCase(url.getScheme())) {
|
||||
return null;
|
||||
|
@ -97,13 +97,13 @@ public final class GroupInviteLinkUrl {
|
|||
}
|
||||
|
||||
protected static String createUrl(GroupMasterKey groupMasterKey, GroupLinkPassword password) {
|
||||
GroupInviteLink groupInviteLink = GroupInviteLink.newBuilder()
|
||||
var groupInviteLink = GroupInviteLink.newBuilder()
|
||||
.setV1Contents(GroupInviteLink.GroupInviteLinkContentsV1.newBuilder()
|
||||
.setGroupMasterKey(ByteString.copyFrom(groupMasterKey.serialize()))
|
||||
.setInviteLinkPassword(ByteString.copyFrom(password.serialize())))
|
||||
.build();
|
||||
|
||||
String encoding = Base64UrlSafe.encodeBytesWithoutPadding(groupInviteLink.toByteArray());
|
||||
var encoding = Base64UrlSafe.encodeBytesWithoutPadding(groupInviteLink.toByteArray());
|
||||
|
||||
return GROUP_URL_PREFIX + encoding;
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ public class GroupUtils {
|
|||
final SignalServiceDataMessage.Builder messageBuilder, final GroupInfo groupInfo
|
||||
) {
|
||||
if (groupInfo instanceof GroupInfoV1) {
|
||||
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
|
||||
var group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
|
||||
.withId(groupInfo.getGroupId().serialize())
|
||||
.build();
|
||||
messageBuilder.asGroupMessage(group);
|
||||
} else {
|
||||
final GroupInfoV2 groupInfoV2 = (GroupInfoV2) groupInfo;
|
||||
SignalServiceGroupV2 group = SignalServiceGroupV2.newBuilder(groupInfoV2.getMasterKey())
|
||||
final var groupInfoV2 = (GroupInfoV2) groupInfo;
|
||||
var group = SignalServiceGroupV2.newBuilder(groupInfoV2.getMasterKey())
|
||||
.withRevision(groupInfoV2.getGroup() == null ? 0 : groupInfoV2.getGroup().getRevision())
|
||||
.build();
|
||||
messageBuilder.asGroupMessage(group);
|
||||
|
@ -46,13 +46,12 @@ public class GroupUtils {
|
|||
}
|
||||
|
||||
public static GroupIdV2 getGroupIdV2(GroupMasterKey groupMasterKey) {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||
return getGroupIdV2(groupSecretParams);
|
||||
}
|
||||
|
||||
public static GroupIdV2 getGroupIdV2(GroupIdV1 groupIdV1) {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(deriveV2MigrationMasterKey(
|
||||
groupIdV1));
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(deriveV2MigrationMasterKey(groupIdV1));
|
||||
return getGroupIdV2(groupSecretParams);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.asamk.signal.manager.helper;
|
|||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.asamk.signal.manager.groups.GroupIdV2;
|
||||
import org.asamk.signal.manager.groups.GroupLinkPassword;
|
||||
import org.asamk.signal.manager.groups.GroupUtils;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfoV2;
|
||||
|
@ -20,7 +19,6 @@ import org.signal.zkgroup.VerificationFailedException;
|
|||
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;
|
||||
|
@ -41,7 +39,6 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -80,7 +77,7 @@ public class GroupHelper {
|
|||
|
||||
public DecryptedGroup getDecryptedGroup(final GroupSecretParams groupSecretParams) {
|
||||
try {
|
||||
final GroupsV2AuthorizationString groupsV2AuthorizationString = groupAuthorizationProvider.getAuthorizationForToday(
|
||||
final var groupsV2AuthorizationString = groupAuthorizationProvider.getAuthorizationForToday(
|
||||
groupSecretParams);
|
||||
return groupsV2Api.getGroup(groupSecretParams, groupsV2AuthorizationString);
|
||||
} catch (IOException | VerificationFailedException | InvalidGroupStateException e) {
|
||||
|
@ -92,7 +89,7 @@ public class GroupHelper {
|
|||
public DecryptedGroupJoinInfo getDecryptedGroupJoinInfo(
|
||||
GroupMasterKey groupMasterKey, GroupLinkPassword password
|
||||
) throws IOException, GroupLinkNotActiveException {
|
||||
GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||
var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||
|
||||
return groupsV2Api.getGroupJoinInfo(groupSecretParams,
|
||||
Optional.fromNullable(password).transform(GroupLinkPassword::serialize),
|
||||
|
@ -102,13 +99,13 @@ public class GroupHelper {
|
|||
public GroupInfoV2 createGroupV2(
|
||||
String name, Collection<SignalServiceAddress> members, File avatarFile
|
||||
) throws IOException {
|
||||
final byte[] avatarBytes = readAvatarBytes(avatarFile);
|
||||
final GroupsV2Operations.NewGroup newGroup = buildNewGroupV2(name, members, avatarBytes);
|
||||
final var avatarBytes = readAvatarBytes(avatarFile);
|
||||
final var newGroup = buildNewGroupV2(name, members, avatarBytes);
|
||||
if (newGroup == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final GroupSecretParams groupSecretParams = newGroup.getGroupSecretParams();
|
||||
final var groupSecretParams = newGroup.getGroupSecretParams();
|
||||
|
||||
final GroupsV2AuthorizationString groupAuthForToday;
|
||||
final DecryptedGroup decryptedGroup;
|
||||
|
@ -125,9 +122,9 @@ public class GroupHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
final GroupIdV2 groupId = GroupUtils.getGroupIdV2(groupSecretParams);
|
||||
final GroupMasterKey masterKey = groupSecretParams.getMasterKey();
|
||||
GroupInfoV2 g = new GroupInfoV2(groupId, masterKey);
|
||||
final var groupId = GroupUtils.getGroupIdV2(groupSecretParams);
|
||||
final var masterKey = groupSecretParams.getMasterKey();
|
||||
var g = new GroupInfoV2(groupId, masterKey);
|
||||
g.setGroup(decryptedGroup);
|
||||
|
||||
return g;
|
||||
|
@ -144,8 +141,7 @@ public class GroupHelper {
|
|||
private GroupsV2Operations.NewGroup buildNewGroupV2(
|
||||
String name, Collection<SignalServiceAddress> members, byte[] avatar
|
||||
) {
|
||||
final ProfileKeyCredential profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(
|
||||
selfAddressProvider.getSelfAddress());
|
||||
final var profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(selfAddressProvider.getSelfAddress());
|
||||
if (profileKeyCredential == null) {
|
||||
logger.warn("Cannot create a V2 group as self does not have a versioned profile");
|
||||
return null;
|
||||
|
@ -153,14 +149,14 @@ public class GroupHelper {
|
|||
|
||||
if (!areMembersValid(members)) return null;
|
||||
|
||||
GroupCandidate self = new GroupCandidate(selfAddressProvider.getSelfAddress().getUuid().orNull(),
|
||||
var self = new GroupCandidate(selfAddressProvider.getSelfAddress().getUuid().orNull(),
|
||||
Optional.fromNullable(profileKeyCredential));
|
||||
Set<GroupCandidate> candidates = members.stream()
|
||||
var candidates = members.stream()
|
||||
.map(member -> new GroupCandidate(member.getUuid().get(),
|
||||
Optional.fromNullable(profileKeyCredentialProvider.getProfileKeyCredential(member))))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.generate();
|
||||
final var groupSecretParams = GroupSecretParams.generate();
|
||||
return groupsV2Operations.createNewGroup(groupSecretParams,
|
||||
name,
|
||||
Optional.fromNullable(avatar),
|
||||
|
@ -171,7 +167,7 @@ public class GroupHelper {
|
|||
}
|
||||
|
||||
private boolean areMembersValid(final Collection<SignalServiceAddress> members) {
|
||||
final Set<String> noUuidCapability = members.stream()
|
||||
final var noUuidCapability = members.stream()
|
||||
.filter(address -> !address.getUuid().isPresent())
|
||||
.map(SignalServiceAddress::getLegacyIdentifier)
|
||||
.collect(Collectors.toSet());
|
||||
|
@ -181,7 +177,7 @@ public class GroupHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
final Set<SignalProfile> noGv2Capability = members.stream()
|
||||
final var noGv2Capability = members.stream()
|
||||
.map(profileProvider::getProfile)
|
||||
.filter(profile -> profile != null && !profile.getCapabilities().gv2)
|
||||
.collect(Collectors.toSet());
|
||||
|
@ -197,22 +193,20 @@ public class GroupHelper {
|
|||
public Pair<DecryptedGroup, GroupChange> updateGroupV2(
|
||||
GroupInfoV2 groupInfoV2, String name, File avatarFile
|
||||
) throws IOException {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
|
||||
GroupChange.Actions.Builder change = name != null
|
||||
? groupOperations.createModifyGroupTitle(name)
|
||||
: GroupChange.Actions.newBuilder();
|
||||
var change = name != null ? groupOperations.createModifyGroupTitle(name) : GroupChange.Actions.newBuilder();
|
||||
|
||||
if (avatarFile != null) {
|
||||
final byte[] avatarBytes = readAvatarBytes(avatarFile);
|
||||
String avatarCdnKey = groupsV2Api.uploadAvatar(avatarBytes,
|
||||
final var avatarBytes = readAvatarBytes(avatarFile);
|
||||
var avatarCdnKey = groupsV2Api.uploadAvatar(avatarBytes,
|
||||
groupSecretParams,
|
||||
groupAuthorizationProvider.getAuthorizationForToday(groupSecretParams));
|
||||
change.setModifyAvatar(GroupChange.Actions.ModifyAvatarAction.newBuilder().setAvatar(avatarCdnKey));
|
||||
}
|
||||
|
||||
final Optional<UUID> uuid = this.selfAddressProvider.getSelfAddress().getUuid();
|
||||
final var uuid = this.selfAddressProvider.getSelfAddress().getUuid();
|
||||
if (uuid.isPresent()) {
|
||||
change.setSourceUuid(UuidUtil.toByteString(uuid.get()));
|
||||
}
|
||||
|
@ -223,22 +217,22 @@ public class GroupHelper {
|
|||
public Pair<DecryptedGroup, GroupChange> updateGroupV2(
|
||||
GroupInfoV2 groupInfoV2, Set<SignalServiceAddress> newMembers
|
||||
) throws IOException {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
|
||||
if (!areMembersValid(newMembers)) {
|
||||
throw new IOException("Failed to update group");
|
||||
}
|
||||
|
||||
Set<GroupCandidate> candidates = newMembers.stream()
|
||||
var candidates = newMembers.stream()
|
||||
.map(member -> new GroupCandidate(member.getUuid().get(),
|
||||
Optional.fromNullable(profileKeyCredentialProvider.getProfileKeyCredential(member))))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final GroupChange.Actions.Builder change = groupOperations.createModifyGroupMembershipChange(candidates,
|
||||
final var change = groupOperations.createModifyGroupMembershipChange(candidates,
|
||||
selfAddressProvider.getSelfAddress().getUuid().get());
|
||||
|
||||
final Optional<UUID> uuid = this.selfAddressProvider.getSelfAddress().getUuid();
|
||||
final var uuid = this.selfAddressProvider.getSelfAddress().getUuid();
|
||||
if (uuid.isPresent()) {
|
||||
change.setSourceUuid(UuidUtil.toByteString(uuid.get()));
|
||||
}
|
||||
|
@ -247,10 +241,9 @@ public class GroupHelper {
|
|||
}
|
||||
|
||||
public Pair<DecryptedGroup, GroupChange> leaveGroup(GroupInfoV2 groupInfoV2) throws IOException {
|
||||
List<DecryptedPendingMember> pendingMembersList = groupInfoV2.getGroup().getPendingMembersList();
|
||||
final UUID selfUuid = selfAddressProvider.getSelfAddress().getUuid().get();
|
||||
Optional<DecryptedPendingMember> selfPendingMember = DecryptedGroupUtil.findPendingByUuid(pendingMembersList,
|
||||
selfUuid);
|
||||
var pendingMembersList = groupInfoV2.getGroup().getPendingMembersList();
|
||||
final var selfUuid = selfAddressProvider.getSelfAddress().getUuid().get();
|
||||
var selfPendingMember = DecryptedGroupUtil.findPendingByUuid(pendingMembersList, selfUuid);
|
||||
|
||||
if (selfPendingMember.isPresent()) {
|
||||
return revokeInvites(groupInfoV2, Set.of(selfPendingMember.get()));
|
||||
|
@ -264,19 +257,17 @@ public class GroupHelper {
|
|||
GroupLinkPassword groupLinkPassword,
|
||||
DecryptedGroupJoinInfo decryptedGroupJoinInfo
|
||||
) throws IOException {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||
final GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||
final var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
|
||||
final SignalServiceAddress selfAddress = this.selfAddressProvider.getSelfAddress();
|
||||
final ProfileKeyCredential profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(
|
||||
selfAddress);
|
||||
final var selfAddress = this.selfAddressProvider.getSelfAddress();
|
||||
final var profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(selfAddress);
|
||||
if (profileKeyCredential == null) {
|
||||
throw new IOException("Cannot join a V2 group as self does not have a versioned profile");
|
||||
}
|
||||
|
||||
boolean requestToJoin = decryptedGroupJoinInfo.getAddFromInviteLink()
|
||||
== AccessControl.AccessRequired.ADMINISTRATOR;
|
||||
GroupChange.Actions.Builder change = requestToJoin
|
||||
var requestToJoin = decryptedGroupJoinInfo.getAddFromInviteLink() == AccessControl.AccessRequired.ADMINISTRATOR;
|
||||
var change = requestToJoin
|
||||
? groupOperations.createGroupJoinRequest(profileKeyCredential)
|
||||
: groupOperations.createGroupJoinDirect(profileKeyCredential);
|
||||
|
||||
|
@ -286,19 +277,18 @@ public class GroupHelper {
|
|||
}
|
||||
|
||||
public Pair<DecryptedGroup, GroupChange> acceptInvite(GroupInfoV2 groupInfoV2) throws IOException {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
final GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
final var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
|
||||
final SignalServiceAddress selfAddress = this.selfAddressProvider.getSelfAddress();
|
||||
final ProfileKeyCredential profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(
|
||||
selfAddress);
|
||||
final var selfAddress = this.selfAddressProvider.getSelfAddress();
|
||||
final var profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(selfAddress);
|
||||
if (profileKeyCredential == null) {
|
||||
throw new IOException("Cannot join a V2 group as self does not have a versioned profile");
|
||||
}
|
||||
|
||||
final GroupChange.Actions.Builder change = groupOperations.createAcceptInviteChange(profileKeyCredential);
|
||||
final var change = groupOperations.createAcceptInviteChange(profileKeyCredential);
|
||||
|
||||
final Optional<UUID> uuid = selfAddress.getUuid();
|
||||
final var uuid = selfAddress.getUuid();
|
||||
if (uuid.isPresent()) {
|
||||
change.setSourceUuid(UuidUtil.toByteString(uuid.get()));
|
||||
}
|
||||
|
@ -309,9 +299,9 @@ public class GroupHelper {
|
|||
public Pair<DecryptedGroup, GroupChange> revokeInvites(
|
||||
GroupInfoV2 groupInfoV2, Set<DecryptedPendingMember> pendingMembers
|
||||
) throws IOException {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
final GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final Set<UuidCiphertext> uuidCipherTexts = pendingMembers.stream().map(member -> {
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
final var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final var uuidCipherTexts = pendingMembers.stream().map(member -> {
|
||||
try {
|
||||
return new UuidCiphertext(member.getUuidCipherText().toByteArray());
|
||||
} catch (InvalidInputException e) {
|
||||
|
@ -322,19 +312,19 @@ public class GroupHelper {
|
|||
}
|
||||
|
||||
public Pair<DecryptedGroup, GroupChange> ejectMembers(GroupInfoV2 groupInfoV2, Set<UUID> uuids) throws IOException {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
final GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
final var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
return commitChange(groupInfoV2, groupOperations.createRemoveMembersChange(uuids));
|
||||
}
|
||||
|
||||
private Pair<DecryptedGroup, GroupChange> commitChange(
|
||||
GroupInfoV2 groupInfoV2, GroupChange.Actions.Builder change
|
||||
) throws IOException {
|
||||
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
final GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final DecryptedGroup previousGroupState = groupInfoV2.getGroup();
|
||||
final int nextRevision = previousGroupState.getRevision() + 1;
|
||||
final GroupChange.Actions changeActions = change.setRevision(nextRevision).build();
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
final var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
final var previousGroupState = groupInfoV2.getGroup();
|
||||
final var nextRevision = previousGroupState.getRevision() + 1;
|
||||
final var changeActions = change.setRevision(nextRevision).build();
|
||||
final DecryptedGroupChange decryptedChange;
|
||||
final DecryptedGroup decryptedGroupState;
|
||||
|
||||
|
@ -346,7 +336,7 @@ public class GroupHelper {
|
|||
throw new IOException(e);
|
||||
}
|
||||
|
||||
GroupChange signedGroupChange = groupsV2Api.patchGroup(changeActions,
|
||||
var signedGroupChange = groupsV2Api.patchGroup(changeActions,
|
||||
groupAuthorizationProvider.getAuthorizationForToday(groupSecretParams),
|
||||
Optional.absent());
|
||||
|
||||
|
@ -359,8 +349,8 @@ public class GroupHelper {
|
|||
GroupChange.Actions.Builder change,
|
||||
GroupLinkPassword password
|
||||
) throws IOException {
|
||||
final int nextRevision = currentRevision + 1;
|
||||
final GroupChange.Actions changeActions = change.setRevision(nextRevision).build();
|
||||
final var nextRevision = currentRevision + 1;
|
||||
final var changeActions = change.setRevision(nextRevision).build();
|
||||
|
||||
return groupsV2Api.patchGroup(changeActions,
|
||||
groupAuthorizationProvider.getAuthorizationForToday(groupSecretParams),
|
||||
|
@ -371,8 +361,7 @@ public class GroupHelper {
|
|||
DecryptedGroup group, byte[] signedGroupChange, GroupMasterKey groupMasterKey
|
||||
) {
|
||||
try {
|
||||
final DecryptedGroupChange decryptedGroupChange = getDecryptedGroupChange(signedGroupChange,
|
||||
groupMasterKey);
|
||||
final var decryptedGroupChange = getDecryptedGroupChange(signedGroupChange, groupMasterKey);
|
||||
if (decryptedGroupChange == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -384,8 +373,7 @@ public class GroupHelper {
|
|||
|
||||
private DecryptedGroupChange getDecryptedGroupChange(byte[] signedGroupChange, GroupMasterKey groupMasterKey) {
|
||||
if (signedGroupChange != null) {
|
||||
GroupsV2Operations.GroupOperations groupOperations = groupsV2Operations.forGroup(GroupSecretParams.deriveFromMasterKey(
|
||||
groupMasterKey));
|
||||
var groupOperations = groupsV2Operations.forGroup(GroupSecretParams.deriveFromMasterKey(groupMasterKey));
|
||||
|
||||
try {
|
||||
return groupOperations.decryptChange(GroupChange.parseFrom(signedGroupChange), true).orNull();
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.whispersystems.signalservice.api.KbsPinData;
|
|||
import org.whispersystems.signalservice.api.KeyBackupService;
|
||||
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
|
||||
import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
|
||||
import org.whispersystems.signalservice.api.kbs.HashedPin;
|
||||
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
||||
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
|
||||
import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse;
|
||||
|
@ -25,15 +24,15 @@ public class PinHelper {
|
|||
public void setRegistrationLockPin(
|
||||
String pin, MasterKey masterKey
|
||||
) throws IOException, UnauthenticatedResponseException {
|
||||
final KeyBackupService.PinChangeSession pinChangeSession = keyBackupService.newPinChangeSession();
|
||||
final HashedPin hashedPin = PinHashing.hashPin(pin, pinChangeSession);
|
||||
final var pinChangeSession = keyBackupService.newPinChangeSession();
|
||||
final var hashedPin = PinHashing.hashPin(pin, pinChangeSession);
|
||||
|
||||
pinChangeSession.setPin(hashedPin, masterKey);
|
||||
pinChangeSession.enableRegistrationLock(masterKey);
|
||||
}
|
||||
|
||||
public void removeRegistrationLockPin() throws IOException, UnauthenticatedResponseException {
|
||||
final KeyBackupService.PinChangeSession pinChangeSession = keyBackupService.newPinChangeSession();
|
||||
final var pinChangeSession = keyBackupService.newPinChangeSession();
|
||||
pinChangeSession.disableRegistrationLock();
|
||||
pinChangeSession.removePin();
|
||||
}
|
||||
|
@ -41,7 +40,7 @@ public class PinHelper {
|
|||
public KbsPinData getRegistrationLockData(
|
||||
String pin, LockedException e
|
||||
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
|
||||
String basicStorageCredentials = e.getBasicStorageCredentials();
|
||||
var basicStorageCredentials = e.getBasicStorageCredentials();
|
||||
if (basicStorageCredentials == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -52,12 +51,12 @@ public class PinHelper {
|
|||
private KbsPinData getRegistrationLockData(
|
||||
String pin, String basicStorageCredentials
|
||||
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
|
||||
TokenResponse tokenResponse = keyBackupService.getToken(basicStorageCredentials);
|
||||
var tokenResponse = keyBackupService.getToken(basicStorageCredentials);
|
||||
if (tokenResponse == null || tokenResponse.getTries() == 0) {
|
||||
throw new IOException("KBS Account locked");
|
||||
}
|
||||
|
||||
KbsPinData registrationLockData = restoreMasterKey(pin, basicStorageCredentials, tokenResponse);
|
||||
var registrationLockData = restoreMasterKey(pin, basicStorageCredentials, tokenResponse);
|
||||
if (registrationLockData == null) {
|
||||
throw new AssertionError("Failed to restore master key");
|
||||
}
|
||||
|
@ -73,12 +72,11 @@ public class PinHelper {
|
|||
throw new AssertionError("Cannot restore KBS key, no storage credentials supplied");
|
||||
}
|
||||
|
||||
KeyBackupService.RestoreSession session = keyBackupService.newRegistrationSession(basicStorageCredentials,
|
||||
tokenResponse);
|
||||
var session = keyBackupService.newRegistrationSession(basicStorageCredentials, tokenResponse);
|
||||
|
||||
try {
|
||||
HashedPin hashedPin = PinHashing.hashPin(pin, session);
|
||||
KbsPinData kbsData = session.restorePin(hashedPin);
|
||||
var hashedPin = PinHashing.hashPin(pin, session);
|
||||
var kbsData = session.restorePin(hashedPin);
|
||||
if (kbsData == null) {
|
||||
throw new AssertionError("Null not expected");
|
||||
}
|
||||
|
|
|
@ -2,10 +2,7 @@ package org.asamk.signal.manager.helper;
|
|||
|
||||
import org.signal.zkgroup.profiles.ProfileKey;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.SignalServiceMessagePipe;
|
||||
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair;
|
||||
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
|
||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
@ -63,8 +60,8 @@ public final class ProfileHelper {
|
|||
public ListenableFuture<ProfileAndCredential> retrieveProfile(
|
||||
SignalServiceAddress address, SignalServiceProfile.RequestType requestType
|
||||
) {
|
||||
Optional<UnidentifiedAccess> unidentifiedAccess = getUnidentifiedAccess(address);
|
||||
Optional<ProfileKey> profileKey = Optional.fromNullable(profileKeyProvider.getProfileKey(address));
|
||||
var unidentifiedAccess = getUnidentifiedAccess(address);
|
||||
var profileKey = Optional.fromNullable(profileKeyProvider.getProfileKey(address));
|
||||
|
||||
if (unidentifiedAccess.isPresent()) {
|
||||
return new CascadingFuture<>(Arrays.asList(() -> getPipeRetrievalFuture(address,
|
||||
|
@ -90,8 +87,8 @@ public final class ProfileHelper {
|
|||
Optional<UnidentifiedAccess> unidentifiedAccess,
|
||||
SignalServiceProfile.RequestType requestType
|
||||
) throws IOException {
|
||||
SignalServiceMessagePipe unidentifiedPipe = messagePipeProvider.getMessagePipe(true);
|
||||
SignalServiceMessagePipe pipe = unidentifiedPipe != null && unidentifiedAccess.isPresent()
|
||||
var unidentifiedPipe = messagePipeProvider.getMessagePipe(true);
|
||||
var pipe = unidentifiedPipe != null && unidentifiedAccess.isPresent()
|
||||
? unidentifiedPipe
|
||||
: messagePipeProvider.getMessagePipe(false);
|
||||
if (pipe != null) {
|
||||
|
@ -102,8 +99,7 @@ public final class ProfileHelper {
|
|||
if (!address.getNumber().isPresent()) {
|
||||
throw new NotFoundException("Can't request profile without number");
|
||||
}
|
||||
SignalServiceAddress addressWithoutUuid = new SignalServiceAddress(Optional.absent(),
|
||||
address.getNumber());
|
||||
var addressWithoutUuid = new SignalServiceAddress(Optional.absent(), address.getNumber());
|
||||
return pipe.getProfile(addressWithoutUuid, profileKey, unidentifiedAccess, requestType);
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +113,7 @@ public final class ProfileHelper {
|
|||
Optional<UnidentifiedAccess> unidentifiedAccess,
|
||||
SignalServiceProfile.RequestType requestType
|
||||
) throws NotFoundException {
|
||||
SignalServiceMessageReceiver receiver = messageReceiverProvider.getMessageReceiver();
|
||||
var receiver = messageReceiverProvider.getMessageReceiver();
|
||||
try {
|
||||
return receiver.retrieveProfile(address, profileKey, unidentifiedAccess, requestType);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
|
@ -125,13 +121,13 @@ public final class ProfileHelper {
|
|||
if (!address.getNumber().isPresent()) {
|
||||
throw new NotFoundException("Can't request profile without number");
|
||||
}
|
||||
SignalServiceAddress addressWithoutUuid = new SignalServiceAddress(Optional.absent(), address.getNumber());
|
||||
var addressWithoutUuid = new SignalServiceAddress(Optional.absent(), address.getNumber());
|
||||
return receiver.retrieveProfile(addressWithoutUuid, profileKey, unidentifiedAccess, requestType);
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<UnidentifiedAccess> getUnidentifiedAccess(SignalServiceAddress recipient) {
|
||||
Optional<UnidentifiedAccessPair> unidentifiedAccess = unidentifiedAccessProvider.getAccessFor(recipient);
|
||||
var unidentifiedAccess = unidentifiedAccessProvider.getAccessFor(recipient);
|
||||
|
||||
if (unidentifiedAccess.isPresent()) {
|
||||
return unidentifiedAccess.get().getTargetUnidentifiedAccess();
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package org.asamk.signal.manager.helper;
|
||||
|
||||
import org.asamk.signal.manager.storage.profiles.SignalProfile;
|
||||
import org.signal.libsignal.metadata.certificate.InvalidCertificateException;
|
||||
import org.signal.zkgroup.profiles.ProfileKey;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
|
||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair;
|
||||
|
@ -41,12 +39,12 @@ public class UnidentifiedAccessHelper {
|
|||
}
|
||||
|
||||
public byte[] getTargetUnidentifiedAccessKey(SignalServiceAddress recipient) {
|
||||
ProfileKey theirProfileKey = profileKeyProvider.getProfileKey(recipient);
|
||||
var theirProfileKey = profileKeyProvider.getProfileKey(recipient);
|
||||
if (theirProfileKey == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SignalProfile targetProfile = profileProvider.getProfile(recipient);
|
||||
var targetProfile = profileProvider.getProfile(recipient);
|
||||
if (targetProfile == null || targetProfile.getUnidentifiedAccess() == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -59,8 +57,8 @@ public class UnidentifiedAccessHelper {
|
|||
}
|
||||
|
||||
public Optional<UnidentifiedAccessPair> getAccessForSync() {
|
||||
byte[] selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey();
|
||||
byte[] selfUnidentifiedAccessCertificate = senderCertificateProvider.getSenderCertificate();
|
||||
var selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey();
|
||||
var selfUnidentifiedAccessCertificate = senderCertificateProvider.getSenderCertificate();
|
||||
|
||||
if (selfUnidentifiedAccessKey == null || selfUnidentifiedAccessCertificate == null) {
|
||||
return Optional.absent();
|
||||
|
@ -80,9 +78,9 @@ public class UnidentifiedAccessHelper {
|
|||
}
|
||||
|
||||
public Optional<UnidentifiedAccessPair> getAccessFor(SignalServiceAddress recipient) {
|
||||
byte[] recipientUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipient);
|
||||
byte[] selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey();
|
||||
byte[] selfUnidentifiedAccessCertificate = senderCertificateProvider.getSenderCertificate();
|
||||
var recipientUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipient);
|
||||
var selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey();
|
||||
var selfUnidentifiedAccessCertificate = senderCertificateProvider.getSenderCertificate();
|
||||
|
||||
if (recipientUnidentifiedAccessKey == null
|
||||
|| selfUnidentifiedAccessKey == null
|
||||
|
|
|
@ -8,24 +8,18 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.storage.contacts.ContactInfo;
|
||||
import org.asamk.signal.manager.storage.contacts.JsonContactsStore;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfo;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfoV1;
|
||||
import org.asamk.signal.manager.storage.groups.JsonGroupStore;
|
||||
import org.asamk.signal.manager.storage.messageCache.MessageCache;
|
||||
import org.asamk.signal.manager.storage.profiles.ProfileStore;
|
||||
import org.asamk.signal.manager.storage.protocol.IdentityInfo;
|
||||
import org.asamk.signal.manager.storage.protocol.JsonSignalProtocolStore;
|
||||
import org.asamk.signal.manager.storage.protocol.RecipientStore;
|
||||
import org.asamk.signal.manager.storage.protocol.SessionInfo;
|
||||
import org.asamk.signal.manager.storage.protocol.SignalServiceAddressResolver;
|
||||
import org.asamk.signal.manager.storage.stickers.StickerStore;
|
||||
import org.asamk.signal.manager.storage.threads.LegacyJsonThreadStore;
|
||||
import org.asamk.signal.manager.storage.threads.ThreadInfo;
|
||||
import org.asamk.signal.manager.util.IOUtils;
|
||||
import org.asamk.signal.manager.util.KeyUtils;
|
||||
import org.asamk.signal.manager.util.Utils;
|
||||
|
@ -99,10 +93,10 @@ public class SignalAccount implements Closeable {
|
|||
}
|
||||
|
||||
public static SignalAccount load(File dataPath, String username) throws IOException {
|
||||
final File fileName = getFileName(dataPath, username);
|
||||
final Pair<FileChannel, FileLock> pair = openFileChannel(fileName);
|
||||
final var fileName = getFileName(dataPath, username);
|
||||
final var pair = openFileChannel(fileName);
|
||||
try {
|
||||
SignalAccount account = new SignalAccount(pair.first(), pair.second());
|
||||
var account = new SignalAccount(pair.first(), pair.second());
|
||||
account.load(dataPath);
|
||||
account.migrateLegacyConfigs();
|
||||
|
||||
|
@ -118,13 +112,13 @@ public class SignalAccount implements Closeable {
|
|||
File dataPath, String username, IdentityKeyPair identityKey, int registrationId, ProfileKey profileKey
|
||||
) throws IOException {
|
||||
IOUtils.createPrivateDirectories(dataPath);
|
||||
File fileName = getFileName(dataPath, username);
|
||||
var fileName = getFileName(dataPath, username);
|
||||
if (!fileName.exists()) {
|
||||
IOUtils.createPrivateFile(fileName);
|
||||
}
|
||||
|
||||
final Pair<FileChannel, FileLock> pair = openFileChannel(fileName);
|
||||
SignalAccount account = new SignalAccount(pair.first(), pair.second());
|
||||
final var pair = openFileChannel(fileName);
|
||||
var account = new SignalAccount(pair.first(), pair.second());
|
||||
|
||||
account.username = username;
|
||||
account.profileKey = profileKey;
|
||||
|
@ -155,13 +149,13 @@ public class SignalAccount implements Closeable {
|
|||
ProfileKey profileKey
|
||||
) throws IOException {
|
||||
IOUtils.createPrivateDirectories(dataPath);
|
||||
File fileName = getFileName(dataPath, username);
|
||||
var fileName = getFileName(dataPath, username);
|
||||
if (!fileName.exists()) {
|
||||
IOUtils.createPrivateFile(fileName);
|
||||
}
|
||||
|
||||
final Pair<FileChannel, FileLock> pair = openFileChannel(fileName);
|
||||
SignalAccount account = new SignalAccount(pair.first(), pair.second());
|
||||
final var pair = openFileChannel(fileName);
|
||||
var account = new SignalAccount(pair.first(), pair.second());
|
||||
|
||||
account.username = username;
|
||||
account.uuid = uuid;
|
||||
|
@ -192,8 +186,8 @@ public class SignalAccount implements Closeable {
|
|||
save();
|
||||
}
|
||||
// Store profile keys only in profile store
|
||||
for (ContactInfo contact : getContactStore().getContacts()) {
|
||||
String profileKeyString = contact.profileKey;
|
||||
for (var contact : getContactStore().getContacts()) {
|
||||
var profileKeyString = contact.profileKey;
|
||||
if (profileKeyString == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -230,7 +224,7 @@ public class SignalAccount implements Closeable {
|
|||
if (username == null) {
|
||||
return false;
|
||||
}
|
||||
File f = getFileName(dataPath, username);
|
||||
var f = getFileName(dataPath, username);
|
||||
return !(!f.exists() || f.isDirectory());
|
||||
}
|
||||
|
||||
|
@ -288,7 +282,7 @@ public class SignalAccount implements Closeable {
|
|||
signalProtocolStore = jsonProcessor.convertValue(Utils.getNotNullNode(rootNode, "axolotlStore"),
|
||||
JsonSignalProtocolStore.class);
|
||||
registered = Utils.getNotNullNode(rootNode, "registered").asBoolean();
|
||||
JsonNode groupStoreNode = rootNode.get("groupStore");
|
||||
var groupStoreNode = rootNode.get("groupStore");
|
||||
if (groupStoreNode != null) {
|
||||
groupStore = jsonProcessor.convertValue(groupStoreNode, JsonGroupStore.class);
|
||||
groupStore.groupCachePath = getGroupCachePath(dataPath, username);
|
||||
|
@ -297,7 +291,7 @@ public class SignalAccount implements Closeable {
|
|||
groupStore = new JsonGroupStore(getGroupCachePath(dataPath, username));
|
||||
}
|
||||
|
||||
JsonNode contactStoreNode = rootNode.get("contactStore");
|
||||
var contactStoreNode = rootNode.get("contactStore");
|
||||
if (contactStoreNode != null) {
|
||||
contactStore = jsonProcessor.convertValue(contactStoreNode, JsonContactsStore.class);
|
||||
}
|
||||
|
@ -305,7 +299,7 @@ public class SignalAccount implements Closeable {
|
|||
contactStore = new JsonContactsStore();
|
||||
}
|
||||
|
||||
JsonNode recipientStoreNode = rootNode.get("recipientStore");
|
||||
var recipientStoreNode = rootNode.get("recipientStore");
|
||||
if (recipientStoreNode != null) {
|
||||
recipientStore = jsonProcessor.convertValue(recipientStoreNode, RecipientStore.class);
|
||||
}
|
||||
|
@ -314,29 +308,29 @@ public class SignalAccount implements Closeable {
|
|||
|
||||
recipientStore.resolveServiceAddress(getSelfAddress());
|
||||
|
||||
for (ContactInfo contact : contactStore.getContacts()) {
|
||||
for (var contact : contactStore.getContacts()) {
|
||||
recipientStore.resolveServiceAddress(contact.getAddress());
|
||||
}
|
||||
|
||||
for (GroupInfo group : groupStore.getGroups()) {
|
||||
for (var group : groupStore.getGroups()) {
|
||||
if (group instanceof GroupInfoV1) {
|
||||
GroupInfoV1 groupInfoV1 = (GroupInfoV1) group;
|
||||
var groupInfoV1 = (GroupInfoV1) group;
|
||||
groupInfoV1.members = groupInfoV1.members.stream()
|
||||
.map(m -> recipientStore.resolveServiceAddress(m))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
for (SessionInfo session : signalProtocolStore.getSessions()) {
|
||||
for (var session : signalProtocolStore.getSessions()) {
|
||||
session.address = recipientStore.resolveServiceAddress(session.address);
|
||||
}
|
||||
|
||||
for (IdentityInfo identity : signalProtocolStore.getIdentities()) {
|
||||
for (var identity : signalProtocolStore.getIdentities()) {
|
||||
identity.setAddress(recipientStore.resolveServiceAddress(identity.getAddress()));
|
||||
}
|
||||
}
|
||||
|
||||
JsonNode profileStoreNode = rootNode.get("profileStore");
|
||||
var profileStoreNode = rootNode.get("profileStore");
|
||||
if (profileStoreNode != null) {
|
||||
profileStore = jsonProcessor.convertValue(profileStoreNode, ProfileStore.class);
|
||||
}
|
||||
|
@ -344,7 +338,7 @@ public class SignalAccount implements Closeable {
|
|||
profileStore = new ProfileStore();
|
||||
}
|
||||
|
||||
JsonNode stickerStoreNode = rootNode.get("stickerStore");
|
||||
var stickerStoreNode = rootNode.get("stickerStore");
|
||||
if (stickerStoreNode != null) {
|
||||
stickerStore = jsonProcessor.convertValue(stickerStoreNode, StickerStore.class);
|
||||
}
|
||||
|
@ -354,22 +348,21 @@ public class SignalAccount implements Closeable {
|
|||
|
||||
messageCache = new MessageCache(getMessageCachePath(dataPath, username));
|
||||
|
||||
JsonNode threadStoreNode = rootNode.get("threadStore");
|
||||
var threadStoreNode = rootNode.get("threadStore");
|
||||
if (threadStoreNode != null && !threadStoreNode.isNull()) {
|
||||
LegacyJsonThreadStore threadStore = jsonProcessor.convertValue(threadStoreNode,
|
||||
LegacyJsonThreadStore.class);
|
||||
var threadStore = jsonProcessor.convertValue(threadStoreNode, LegacyJsonThreadStore.class);
|
||||
// Migrate thread info to group and contact store
|
||||
for (ThreadInfo thread : threadStore.getThreads()) {
|
||||
for (var thread : threadStore.getThreads()) {
|
||||
if (thread.id == null || thread.id.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
ContactInfo contactInfo = contactStore.getContact(new SignalServiceAddress(null, thread.id));
|
||||
var contactInfo = contactStore.getContact(new SignalServiceAddress(null, thread.id));
|
||||
if (contactInfo != null) {
|
||||
contactInfo.messageExpirationTime = thread.messageExpirationTime;
|
||||
contactStore.updateContact(contactInfo);
|
||||
} else {
|
||||
GroupInfo groupInfo = groupStore.getGroup(GroupId.fromBase64(thread.id));
|
||||
var groupInfo = groupStore.getGroup(GroupId.fromBase64(thread.id));
|
||||
if (groupInfo instanceof GroupInfoV1) {
|
||||
((GroupInfoV1) groupInfo).messageExpirationTime = thread.messageExpirationTime;
|
||||
groupStore.updateGroup(groupInfo);
|
||||
|
@ -385,7 +378,7 @@ public class SignalAccount implements Closeable {
|
|||
if (fileChannel == null) {
|
||||
return;
|
||||
}
|
||||
ObjectNode rootNode = jsonProcessor.createObjectNode();
|
||||
var rootNode = jsonProcessor.createObjectNode();
|
||||
rootNode.put("username", username)
|
||||
.put("uuid", uuid == null ? null : uuid.toString())
|
||||
.put("deviceId", deviceId)
|
||||
|
@ -407,10 +400,10 @@ public class SignalAccount implements Closeable {
|
|||
.putPOJO("profileStore", profileStore)
|
||||
.putPOJO("stickerStore", stickerStore);
|
||||
try {
|
||||
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
||||
try (var output = new ByteArrayOutputStream()) {
|
||||
// Write to memory first to prevent corrupting the file in case of serialization errors
|
||||
jsonProcessor.writeValue(output, rootNode);
|
||||
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
|
||||
var input = new ByteArrayInputStream(output.toByteArray());
|
||||
synchronized (fileChannel) {
|
||||
fileChannel.position(0);
|
||||
input.transferTo(Channels.newOutputStream(fileChannel));
|
||||
|
@ -424,8 +417,8 @@ public class SignalAccount implements Closeable {
|
|||
}
|
||||
|
||||
private static Pair<FileChannel, FileLock> openFileChannel(File fileName) throws IOException {
|
||||
FileChannel fileChannel = new RandomAccessFile(fileName, "rw").getChannel();
|
||||
FileLock lock = fileChannel.tryLock();
|
||||
var fileChannel = new RandomAccessFile(fileName, "rw").getChannel();
|
||||
var lock = fileChannel.tryLock();
|
||||
if (lock == null) {
|
||||
logger.info("Config file is in use by another instance, waiting…");
|
||||
lock = fileChannel.lock();
|
||||
|
@ -439,7 +432,7 @@ public class SignalAccount implements Closeable {
|
|||
}
|
||||
|
||||
public void addPreKeys(Collection<PreKeyRecord> records) {
|
||||
for (PreKeyRecord record : records) {
|
||||
for (var record : records) {
|
||||
signalProtocolStore.storePreKey(record.getId(), record);
|
||||
}
|
||||
preKeyIdOffset = (preKeyIdOffset + records.size()) % Medium.MAX_VALUE;
|
||||
|
|
|
@ -13,8 +13,8 @@ public class JsonContactsStore {
|
|||
private List<ContactInfo> contacts = new ArrayList<>();
|
||||
|
||||
public void updateContact(ContactInfo contact) {
|
||||
final SignalServiceAddress contactAddress = contact.getAddress();
|
||||
for (int i = 0; i < contacts.size(); i++) {
|
||||
final var contactAddress = contact.getAddress();
|
||||
for (var i = 0; i < contacts.size(); i++) {
|
||||
if (contacts.get(i).getAddress().matches(contactAddress)) {
|
||||
contacts.set(i, contact);
|
||||
return;
|
||||
|
@ -25,7 +25,7 @@ public class JsonContactsStore {
|
|||
}
|
||||
|
||||
public ContactInfo getContact(SignalServiceAddress address) {
|
||||
for (ContactInfo contact : contacts) {
|
||||
for (var contact : contacts) {
|
||||
if (contact.getAddress().matches(address)) {
|
||||
if (contact.uuid == null) {
|
||||
contact.uuid = address.getUuid().orNull();
|
||||
|
|
|
@ -57,7 +57,7 @@ public abstract class GroupInfo {
|
|||
|
||||
@JsonIgnore
|
||||
public boolean isMember(SignalServiceAddress address) {
|
||||
for (SignalServiceAddress member : getMembers()) {
|
||||
for (var member : getMembers()) {
|
||||
if (member.matches(address)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public abstract class GroupInfo {
|
|||
|
||||
@JsonIgnore
|
||||
public boolean isPendingMember(SignalServiceAddress address) {
|
||||
for (SignalServiceAddress member : getPendingMembers()) {
|
||||
for (var member : getPendingMembers()) {
|
||||
if (member.matches(address)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ public class GroupInfoV1 extends GroupInfo {
|
|||
}
|
||||
|
||||
public void addMembers(Collection<SignalServiceAddress> addresses) {
|
||||
for (SignalServiceAddress address : addresses) {
|
||||
for (var address : addresses) {
|
||||
if (this.members.contains(address)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ public class GroupInfoV1 extends GroupInfo {
|
|||
final Set<SignalServiceAddress> value, final JsonGenerator jgen, final SerializerProvider provider
|
||||
) throws IOException {
|
||||
jgen.writeStartArray(value.size());
|
||||
for (SignalServiceAddress address : value) {
|
||||
for (var address : value) {
|
||||
if (address.getUuid().isPresent()) {
|
||||
jgen.writeObject(new JsonSignalServiceAddress(address));
|
||||
} else {
|
||||
|
@ -195,13 +195,13 @@ public class GroupInfoV1 extends GroupInfo {
|
|||
public Set<SignalServiceAddress> deserialize(
|
||||
JsonParser jsonParser, DeserializationContext deserializationContext
|
||||
) throws IOException {
|
||||
Set<SignalServiceAddress> addresses = new HashSet<>();
|
||||
var addresses = new HashSet<SignalServiceAddress>();
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
for (JsonNode n : node) {
|
||||
for (var n : node) {
|
||||
if (n.isTextual()) {
|
||||
addresses.add(new SignalServiceAddress(null, n.textValue()));
|
||||
} else {
|
||||
JsonSignalServiceAddress address = jsonProcessor.treeToValue(n, JsonSignalServiceAddress.class);
|
||||
var address = jsonProcessor.treeToValue(n, JsonSignalServiceAddress.class);
|
||||
addresses.add(address.toSignalServiceAddress());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -59,10 +58,10 @@ public class JsonGroupStore {
|
|||
if (group instanceof GroupInfoV2 && ((GroupInfoV2) group).getGroup() != null) {
|
||||
try {
|
||||
IOUtils.createPrivateDirectories(groupCachePath);
|
||||
try (FileOutputStream stream = new FileOutputStream(getGroupFile(group.getGroupId()))) {
|
||||
try (var stream = new FileOutputStream(getGroupFile(group.getGroupId()))) {
|
||||
((GroupInfoV2) group).getGroup().writeTo(stream);
|
||||
}
|
||||
final File groupFileLegacy = getGroupFileLegacy(group.getGroupId());
|
||||
final var groupFileLegacy = getGroupFileLegacy(group.getGroupId());
|
||||
if (groupFileLegacy.exists()) {
|
||||
groupFileLegacy.delete();
|
||||
}
|
||||
|
@ -77,7 +76,7 @@ public class JsonGroupStore {
|
|||
}
|
||||
|
||||
public GroupInfo getGroup(GroupId groupId) {
|
||||
GroupInfo group = groups.get(groupId);
|
||||
var group = groups.get(groupId);
|
||||
if (group == null) {
|
||||
if (groupId instanceof GroupIdV1) {
|
||||
group = groups.get(GroupUtils.getGroupIdV2((GroupIdV1) groupId));
|
||||
|
@ -90,9 +89,9 @@ public class JsonGroupStore {
|
|||
}
|
||||
|
||||
private GroupInfoV1 getGroupV1ByV2Id(GroupIdV2 groupIdV2) {
|
||||
for (GroupInfo g : groups.values()) {
|
||||
for (var g : groups.values()) {
|
||||
if (g instanceof GroupInfoV1) {
|
||||
final GroupInfoV1 gv1 = (GroupInfoV1) g;
|
||||
final var gv1 = (GroupInfoV1) g;
|
||||
if (groupIdV2.equals(gv1.getExpectedV2Id())) {
|
||||
return gv1;
|
||||
}
|
||||
|
@ -103,14 +102,14 @@ public class JsonGroupStore {
|
|||
|
||||
private void loadDecryptedGroup(final GroupInfo group) {
|
||||
if (group instanceof GroupInfoV2 && ((GroupInfoV2) group).getGroup() == null) {
|
||||
File groupFile = getGroupFile(group.getGroupId());
|
||||
var groupFile = getGroupFile(group.getGroupId());
|
||||
if (!groupFile.exists()) {
|
||||
groupFile = getGroupFileLegacy(group.getGroupId());
|
||||
}
|
||||
if (!groupFile.exists()) {
|
||||
return;
|
||||
}
|
||||
try (FileInputStream stream = new FileInputStream(groupFile)) {
|
||||
try (var stream = new FileInputStream(groupFile)) {
|
||||
((GroupInfoV2) group).setGroup(DecryptedGroup.parseFrom(stream));
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ public class JsonGroupStore {
|
|||
}
|
||||
|
||||
public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) {
|
||||
GroupInfo group = getGroup(groupId);
|
||||
var group = getGroup(groupId);
|
||||
if (group instanceof GroupInfoV1) {
|
||||
return (GroupInfoV1) group;
|
||||
}
|
||||
|
@ -139,8 +138,8 @@ public class JsonGroupStore {
|
|||
}
|
||||
|
||||
public List<GroupInfo> getGroups() {
|
||||
final Collection<GroupInfo> groups = this.groups.values();
|
||||
for (GroupInfo group : groups) {
|
||||
final var groups = this.groups.values();
|
||||
for (var group : groups) {
|
||||
loadDecryptedGroup(group);
|
||||
}
|
||||
return new ArrayList<>(groups);
|
||||
|
@ -152,13 +151,13 @@ public class JsonGroupStore {
|
|||
public void serialize(
|
||||
final Map<String, GroupInfo> value, final JsonGenerator jgen, final SerializerProvider provider
|
||||
) throws IOException {
|
||||
final Collection<GroupInfo> groups = value.values();
|
||||
final var groups = value.values();
|
||||
jgen.writeStartArray(groups.size());
|
||||
for (GroupInfo group : groups) {
|
||||
for (var group : groups) {
|
||||
if (group instanceof GroupInfoV1) {
|
||||
jgen.writeObject(group);
|
||||
} else if (group instanceof GroupInfoV2) {
|
||||
final GroupInfoV2 groupV2 = (GroupInfoV2) group;
|
||||
final var groupV2 = (GroupInfoV2) group;
|
||||
jgen.writeStartObject();
|
||||
jgen.writeStringField("groupId", groupV2.getGroupId().toBase64());
|
||||
jgen.writeStringField("masterKey",
|
||||
|
@ -179,16 +178,15 @@ public class JsonGroupStore {
|
|||
public Map<GroupId, GroupInfo> deserialize(
|
||||
JsonParser jsonParser, DeserializationContext deserializationContext
|
||||
) throws IOException {
|
||||
Map<GroupId, GroupInfo> groups = new HashMap<>();
|
||||
var groups = new HashMap<GroupId, GroupInfo>();
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
for (JsonNode n : node) {
|
||||
for (var n : node) {
|
||||
GroupInfo g;
|
||||
if (n.hasNonNull("masterKey")) {
|
||||
// a v2 group
|
||||
GroupIdV2 groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
|
||||
var groupId = GroupIdV2.fromBase64(n.get("groupId").asText());
|
||||
try {
|
||||
GroupMasterKey masterKey = new GroupMasterKey(Base64.getDecoder()
|
||||
.decode(n.get("masterKey").asText()));
|
||||
var masterKey = new GroupMasterKey(Base64.getDecoder().decode(n.get("masterKey").asText()));
|
||||
g = new GroupInfoV2(groupId, masterKey);
|
||||
} catch (InvalidInputException | IllegalArgumentException e) {
|
||||
throw new AssertionError("Invalid master key for group " + groupId.toBase64());
|
||||
|
|
|
@ -36,7 +36,7 @@ public class MessageCache {
|
|||
return Stream.of(dir);
|
||||
}
|
||||
|
||||
final File[] files = Objects.requireNonNull(dir.listFiles());
|
||||
final var files = Objects.requireNonNull(dir.listFiles());
|
||||
if (files.length == 0) {
|
||||
try {
|
||||
Files.delete(dir.toPath());
|
||||
|
@ -50,11 +50,11 @@ public class MessageCache {
|
|||
}
|
||||
|
||||
public CachedMessage cacheMessage(SignalServiceEnvelope envelope) {
|
||||
final long now = new Date().getTime();
|
||||
final String source = envelope.hasSource() ? envelope.getSourceAddress().getLegacyIdentifier() : "";
|
||||
final var now = new Date().getTime();
|
||||
final var source = envelope.hasSource() ? envelope.getSourceAddress().getLegacyIdentifier() : "";
|
||||
|
||||
try {
|
||||
File cacheFile = getMessageCacheFile(source, now, envelope.getTimestamp());
|
||||
var cacheFile = getMessageCacheFile(source, now, envelope.getTimestamp());
|
||||
MessageCacheUtils.storeEnvelope(envelope, cacheFile);
|
||||
return new CachedMessage(cacheFile);
|
||||
} catch (IOException e) {
|
||||
|
@ -72,7 +72,7 @@ public class MessageCache {
|
|||
}
|
||||
|
||||
private File getMessageCacheFile(String sender, long now, long timestamp) throws IOException {
|
||||
File cachePath = getMessageCachePath(sender);
|
||||
var cachePath = getMessageCachePath(sender);
|
||||
IOUtils.createPrivateDirectories(cachePath);
|
||||
return new File(cachePath, now + "_" + timestamp);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ProfileStore {
|
||||
|
||||
|
@ -34,7 +33,7 @@ public class ProfileStore {
|
|||
private final List<SignalProfileEntry> profiles = new ArrayList<>();
|
||||
|
||||
public SignalProfileEntry getProfileEntry(SignalServiceAddress serviceAddress) {
|
||||
for (SignalProfileEntry entry : profiles) {
|
||||
for (var entry : profiles) {
|
||||
if (entry.getServiceAddress().matches(serviceAddress)) {
|
||||
return entry;
|
||||
}
|
||||
|
@ -43,7 +42,7 @@ public class ProfileStore {
|
|||
}
|
||||
|
||||
public ProfileKey getProfileKey(SignalServiceAddress serviceAddress) {
|
||||
for (SignalProfileEntry entry : profiles) {
|
||||
for (var entry : profiles) {
|
||||
if (entry.getServiceAddress().matches(serviceAddress)) {
|
||||
return entry.getProfileKey();
|
||||
}
|
||||
|
@ -58,12 +57,8 @@ public class ProfileStore {
|
|||
SignalProfile profile,
|
||||
ProfileKeyCredential profileKeyCredential
|
||||
) {
|
||||
SignalProfileEntry newEntry = new SignalProfileEntry(serviceAddress,
|
||||
profileKey,
|
||||
now,
|
||||
profile,
|
||||
profileKeyCredential);
|
||||
for (int i = 0; i < profiles.size(); i++) {
|
||||
var newEntry = new SignalProfileEntry(serviceAddress, profileKey, now, profile, profileKeyCredential);
|
||||
for (var i = 0; i < profiles.size(); i++) {
|
||||
if (profiles.get(i).getServiceAddress().matches(serviceAddress)) {
|
||||
profiles.set(i, newEntry);
|
||||
return;
|
||||
|
@ -74,8 +69,8 @@ public class ProfileStore {
|
|||
}
|
||||
|
||||
public void storeProfileKey(SignalServiceAddress serviceAddress, ProfileKey profileKey) {
|
||||
SignalProfileEntry newEntry = new SignalProfileEntry(serviceAddress, profileKey, 0, null, null);
|
||||
for (int i = 0; i < profiles.size(); i++) {
|
||||
var newEntry = new SignalProfileEntry(serviceAddress, profileKey, 0, null, null);
|
||||
for (var i = 0; i < profiles.size(); i++) {
|
||||
if (profiles.get(i).getServiceAddress().matches(serviceAddress)) {
|
||||
if (!profiles.get(i).getProfileKey().equals(profileKey)) {
|
||||
profiles.set(i, newEntry);
|
||||
|
@ -95,13 +90,13 @@ public class ProfileStore {
|
|||
) throws IOException {
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
List<SignalProfileEntry> addresses = new ArrayList<>();
|
||||
var addresses = new ArrayList<SignalProfileEntry>();
|
||||
|
||||
if (node.isArray()) {
|
||||
for (JsonNode entry : node) {
|
||||
String name = entry.hasNonNull("name") ? entry.get("name").asText() : null;
|
||||
UUID uuid = entry.hasNonNull("uuid") ? UuidUtil.parseOrNull(entry.get("uuid").asText()) : null;
|
||||
final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, name);
|
||||
for (var entry : node) {
|
||||
var name = entry.hasNonNull("name") ? entry.get("name").asText() : null;
|
||||
var uuid = entry.hasNonNull("uuid") ? UuidUtil.parseOrNull(entry.get("uuid").asText()) : null;
|
||||
final var serviceAddress = new SignalServiceAddress(uuid, name);
|
||||
ProfileKey profileKey = null;
|
||||
try {
|
||||
profileKey = new ProfileKey(Base64.getDecoder().decode(entry.get("profileKey").asText()));
|
||||
|
@ -115,8 +110,8 @@ public class ProfileStore {
|
|||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
long lastUpdateTimestamp = entry.get("lastUpdateTimestamp").asLong();
|
||||
SignalProfile profile = jsonProcessor.treeToValue(entry.get("profile"), SignalProfile.class);
|
||||
var lastUpdateTimestamp = entry.get("lastUpdateTimestamp").asLong();
|
||||
var profile = jsonProcessor.treeToValue(entry.get("profile"), SignalProfile.class);
|
||||
addresses.add(new SignalProfileEntry(serviceAddress,
|
||||
profileKey,
|
||||
lastUpdateTimestamp,
|
||||
|
@ -136,8 +131,8 @@ public class ProfileStore {
|
|||
List<SignalProfileEntry> profiles, JsonGenerator json, SerializerProvider serializerProvider
|
||||
) throws IOException {
|
||||
json.writeStartArray();
|
||||
for (SignalProfileEntry profileEntry : profiles) {
|
||||
final SignalServiceAddress address = profileEntry.getServiceAddress();
|
||||
for (var profileEntry : profiles) {
|
||||
final var address = profileEntry.getServiceAddress();
|
||||
json.writeStartObject();
|
||||
if (address.getNumber().isPresent()) {
|
||||
json.writeStringField("name", address.getNumber().get());
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.ArrayList;
|
|||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||
|
||||
|
@ -85,7 +84,7 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
|||
public boolean saveIdentity(
|
||||
SignalServiceAddress serviceAddress, IdentityKey identityKey, TrustLevel trustLevel, Date added
|
||||
) {
|
||||
for (IdentityInfo id : identities) {
|
||||
for (var id : identities) {
|
||||
if (!id.address.matches(serviceAddress) || !id.identityKey.equals(identityKey)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -111,7 +110,7 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
|||
public void setIdentityTrustLevel(
|
||||
SignalServiceAddress serviceAddress, IdentityKey identityKey, TrustLevel trustLevel
|
||||
) {
|
||||
for (IdentityInfo id : identities) {
|
||||
for (var id : identities) {
|
||||
if (!id.address.matches(serviceAddress) || !id.identityKey.equals(identityKey)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -129,10 +128,10 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
|||
@Override
|
||||
public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
|
||||
// TODO implement possibility for different handling of incoming/outgoing trust decisions
|
||||
SignalServiceAddress serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
boolean trustOnFirstUse = true;
|
||||
var serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
var trustOnFirstUse = true;
|
||||
|
||||
for (IdentityInfo id : identities) {
|
||||
for (var id : identities) {
|
||||
if (!id.address.matches(serviceAddress)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -149,20 +148,20 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
|||
|
||||
@Override
|
||||
public IdentityKey getIdentity(SignalProtocolAddress address) {
|
||||
SignalServiceAddress serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
IdentityInfo identity = getIdentity(serviceAddress);
|
||||
var serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
var identity = getIdentity(serviceAddress);
|
||||
return identity == null ? null : identity.getIdentityKey();
|
||||
}
|
||||
|
||||
public IdentityInfo getIdentity(SignalServiceAddress serviceAddress) {
|
||||
long maxDate = 0;
|
||||
IdentityInfo maxIdentity = null;
|
||||
for (IdentityInfo id : this.identities) {
|
||||
for (var id : this.identities) {
|
||||
if (!id.address.matches(serviceAddress)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final long time = id.getDateAdded().getTime();
|
||||
final var time = id.getDateAdded().getTime();
|
||||
if (maxIdentity == null || maxDate <= time) {
|
||||
maxDate = time;
|
||||
maxIdentity = id;
|
||||
|
@ -177,8 +176,8 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
|||
}
|
||||
|
||||
public List<IdentityInfo> getIdentities(SignalServiceAddress serviceAddress) {
|
||||
List<IdentityInfo> identities = new ArrayList<>();
|
||||
for (IdentityInfo identity : this.identities) {
|
||||
var identities = new ArrayList<IdentityInfo>();
|
||||
for (var identity : this.identities) {
|
||||
if (identity.address.matches(serviceAddress)) {
|
||||
identities.add(identity);
|
||||
}
|
||||
|
@ -194,34 +193,32 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
|||
) throws IOException {
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
int localRegistrationId = node.get("registrationId").asInt();
|
||||
IdentityKeyPair identityKeyPair = new IdentityKeyPair(Base64.getDecoder()
|
||||
.decode(node.get("identityKey").asText()));
|
||||
var localRegistrationId = node.get("registrationId").asInt();
|
||||
var identityKeyPair = new IdentityKeyPair(Base64.getDecoder().decode(node.get("identityKey").asText()));
|
||||
|
||||
JsonIdentityKeyStore keyStore = new JsonIdentityKeyStore(identityKeyPair, localRegistrationId);
|
||||
var keyStore = new JsonIdentityKeyStore(identityKeyPair, localRegistrationId);
|
||||
|
||||
JsonNode trustedKeysNode = node.get("trustedKeys");
|
||||
var trustedKeysNode = node.get("trustedKeys");
|
||||
if (trustedKeysNode.isArray()) {
|
||||
for (JsonNode trustedKey : trustedKeysNode) {
|
||||
String trustedKeyName = trustedKey.hasNonNull("name") ? trustedKey.get("name").asText() : null;
|
||||
for (var trustedKey : trustedKeysNode) {
|
||||
var trustedKeyName = trustedKey.hasNonNull("name") ? trustedKey.get("name").asText() : null;
|
||||
|
||||
if (UuidUtil.isUuid(trustedKeyName)) {
|
||||
// Ignore identities that were incorrectly created with UUIDs as name
|
||||
continue;
|
||||
}
|
||||
|
||||
UUID uuid = trustedKey.hasNonNull("uuid")
|
||||
var uuid = trustedKey.hasNonNull("uuid")
|
||||
? UuidUtil.parseOrNull(trustedKey.get("uuid").asText())
|
||||
: null;
|
||||
final SignalServiceAddress serviceAddress = uuid == null
|
||||
final var serviceAddress = uuid == null
|
||||
? Utils.getSignalServiceAddressFromIdentifier(trustedKeyName)
|
||||
: new SignalServiceAddress(uuid, trustedKeyName);
|
||||
try {
|
||||
IdentityKey id = new IdentityKey(Base64.getDecoder()
|
||||
.decode(trustedKey.get("identityKey").asText()), 0);
|
||||
TrustLevel trustLevel = trustedKey.hasNonNull("trustLevel") ? TrustLevel.fromInt(trustedKey.get(
|
||||
var id = new IdentityKey(Base64.getDecoder().decode(trustedKey.get("identityKey").asText()), 0);
|
||||
var trustLevel = trustedKey.hasNonNull("trustLevel") ? TrustLevel.fromInt(trustedKey.get(
|
||||
"trustLevel").asInt()) : TrustLevel.TRUSTED_UNVERIFIED;
|
||||
Date added = trustedKey.hasNonNull("addedTimestamp") ? new Date(trustedKey.get("addedTimestamp")
|
||||
var added = trustedKey.hasNonNull("addedTimestamp") ? new Date(trustedKey.get("addedTimestamp")
|
||||
.asLong()) : new Date();
|
||||
keyStore.saveIdentity(serviceAddress, id, trustLevel, added);
|
||||
} catch (InvalidKeyException e) {
|
||||
|
@ -251,7 +248,7 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
|||
Base64.getEncoder()
|
||||
.encodeToString(jsonIdentityKeyStore.getIdentityKeyPair().getPublicKey().serialize()));
|
||||
json.writeArrayFieldStart("trustedKeys");
|
||||
for (IdentityInfo trustedKey : jsonIdentityKeyStore.identities) {
|
||||
for (var trustedKey : jsonIdentityKeyStore.identities) {
|
||||
json.writeStartObject();
|
||||
if (trustedKey.getAddress().getNumber().isPresent()) {
|
||||
json.writeStringField("name", trustedKey.getAddress().getNumber().get());
|
||||
|
|
|
@ -69,16 +69,16 @@ class JsonPreKeyStore implements PreKeyStore {
|
|||
) throws IOException {
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
Map<Integer, byte[]> preKeyMap = new HashMap<>();
|
||||
var preKeyMap = new HashMap<Integer, byte[]>();
|
||||
if (node.isArray()) {
|
||||
for (JsonNode preKey : node) {
|
||||
final int preKeyId = preKey.get("id").asInt();
|
||||
final byte[] preKeyRecord = Base64.getDecoder().decode(preKey.get("record").asText());
|
||||
for (var preKey : node) {
|
||||
final var preKeyId = preKey.get("id").asInt();
|
||||
final var preKeyRecord = Base64.getDecoder().decode(preKey.get("record").asText());
|
||||
preKeyMap.put(preKeyId, preKeyRecord);
|
||||
}
|
||||
}
|
||||
|
||||
JsonPreKeyStore keyStore = new JsonPreKeyStore();
|
||||
var keyStore = new JsonPreKeyStore();
|
||||
keyStore.addPreKeys(preKeyMap);
|
||||
|
||||
return keyStore;
|
||||
|
@ -92,7 +92,7 @@ class JsonPreKeyStore implements PreKeyStore {
|
|||
JsonPreKeyStore jsonPreKeyStore, JsonGenerator json, SerializerProvider serializerProvider
|
||||
) throws IOException {
|
||||
json.writeStartArray();
|
||||
for (Map.Entry<Integer, byte[]> preKey : jsonPreKeyStore.store.entrySet()) {
|
||||
for (var preKey : jsonPreKeyStore.store.entrySet()) {
|
||||
json.writeStartObject();
|
||||
json.writeNumberField("id", preKey.getKey());
|
||||
json.writeStringField("record", Base64.getEncoder().encodeToString(preKey.getValue()));
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
|||
import java.util.Base64;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
class JsonSessionStore implements SignalServiceSessionStore {
|
||||
|
||||
|
@ -49,14 +48,14 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
|
||||
@Override
|
||||
public synchronized SessionRecord loadSession(SignalProtocolAddress address) {
|
||||
SignalServiceAddress serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
for (SessionInfo info : sessions) {
|
||||
var serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
for (var info : sessions) {
|
||||
if (info.address.matches(serviceAddress) && info.deviceId == address.getDeviceId()) {
|
||||
try {
|
||||
return new SessionRecord(info.sessionRecord);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to load session, resetting session: {}", e.getMessage());
|
||||
final SessionRecord sessionRecord = new SessionRecord();
|
||||
final var sessionRecord = new SessionRecord();
|
||||
info.sessionRecord = sessionRecord.serialize();
|
||||
return sessionRecord;
|
||||
}
|
||||
|
@ -72,10 +71,10 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
|
||||
@Override
|
||||
public synchronized List<Integer> getSubDeviceSessions(String name) {
|
||||
SignalServiceAddress serviceAddress = resolveSignalServiceAddress(name);
|
||||
var serviceAddress = resolveSignalServiceAddress(name);
|
||||
|
||||
List<Integer> deviceIds = new LinkedList<>();
|
||||
for (SessionInfo info : sessions) {
|
||||
var deviceIds = new LinkedList<Integer>();
|
||||
for (var info : sessions) {
|
||||
if (info.address.matches(serviceAddress) && info.deviceId != 1) {
|
||||
deviceIds.add(info.deviceId);
|
||||
}
|
||||
|
@ -86,8 +85,8 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
|
||||
@Override
|
||||
public synchronized void storeSession(SignalProtocolAddress address, SessionRecord record) {
|
||||
SignalServiceAddress serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
for (SessionInfo info : sessions) {
|
||||
var serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
for (var info : sessions) {
|
||||
if (info.address.matches(serviceAddress) && info.deviceId == address.getDeviceId()) {
|
||||
if (!info.address.getUuid().isPresent() || !info.address.getNumber().isPresent()) {
|
||||
info.address = serviceAddress;
|
||||
|
@ -102,8 +101,8 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
|
||||
@Override
|
||||
public synchronized boolean containsSession(SignalProtocolAddress address) {
|
||||
SignalServiceAddress serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
for (SessionInfo info : sessions) {
|
||||
var serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
for (var info : sessions) {
|
||||
if (info.address.matches(serviceAddress) && info.deviceId == address.getDeviceId()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -113,13 +112,13 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
|
||||
@Override
|
||||
public synchronized void deleteSession(SignalProtocolAddress address) {
|
||||
SignalServiceAddress serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
var serviceAddress = resolveSignalServiceAddress(address.getName());
|
||||
sessions.removeIf(info -> info.address.matches(serviceAddress) && info.deviceId == address.getDeviceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void deleteAllSessions(String name) {
|
||||
SignalServiceAddress serviceAddress = resolveSignalServiceAddress(name);
|
||||
var serviceAddress = resolveSignalServiceAddress(name);
|
||||
deleteAllSessions(serviceAddress);
|
||||
}
|
||||
|
||||
|
@ -129,7 +128,7 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
|
||||
@Override
|
||||
public void archiveSession(final SignalProtocolAddress address) {
|
||||
final SessionRecord sessionRecord = loadSession(address);
|
||||
final var sessionRecord = loadSession(address);
|
||||
if (sessionRecord == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -138,9 +137,9 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
}
|
||||
|
||||
public void archiveAllSessions() {
|
||||
for (SessionInfo info : sessions) {
|
||||
for (var info : sessions) {
|
||||
try {
|
||||
final SessionRecord sessionRecord = new SessionRecord(info.sessionRecord);
|
||||
final var sessionRecord = new SessionRecord(info.sessionRecord);
|
||||
sessionRecord.archiveCurrentState();
|
||||
info.sessionRecord = sessionRecord.serialize();
|
||||
} catch (IOException ignored) {
|
||||
|
@ -156,23 +155,23 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
) throws IOException {
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
JsonSessionStore sessionStore = new JsonSessionStore();
|
||||
var sessionStore = new JsonSessionStore();
|
||||
|
||||
if (node.isArray()) {
|
||||
for (JsonNode session : node) {
|
||||
String sessionName = session.hasNonNull("name") ? session.get("name").asText() : null;
|
||||
for (var session : node) {
|
||||
var sessionName = session.hasNonNull("name") ? session.get("name").asText() : null;
|
||||
if (UuidUtil.isUuid(sessionName)) {
|
||||
// Ignore sessions that were incorrectly created with UUIDs as name
|
||||
continue;
|
||||
}
|
||||
|
||||
UUID uuid = session.hasNonNull("uuid") ? UuidUtil.parseOrNull(session.get("uuid").asText()) : null;
|
||||
final SignalServiceAddress serviceAddress = uuid == null
|
||||
var uuid = session.hasNonNull("uuid") ? UuidUtil.parseOrNull(session.get("uuid").asText()) : null;
|
||||
final var serviceAddress = uuid == null
|
||||
? Utils.getSignalServiceAddressFromIdentifier(sessionName)
|
||||
: new SignalServiceAddress(uuid, sessionName);
|
||||
final int deviceId = session.get("deviceId").asInt();
|
||||
final byte[] record = Base64.getDecoder().decode(session.get("record").asText());
|
||||
SessionInfo sessionInfo = new SessionInfo(serviceAddress, deviceId, record);
|
||||
final var deviceId = session.get("deviceId").asInt();
|
||||
final var record = Base64.getDecoder().decode(session.get("record").asText());
|
||||
var sessionInfo = new SessionInfo(serviceAddress, deviceId, record);
|
||||
sessionStore.sessions.add(sessionInfo);
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +187,7 @@ class JsonSessionStore implements SignalServiceSessionStore {
|
|||
JsonSessionStore jsonSessionStore, JsonGenerator json, SerializerProvider serializerProvider
|
||||
) throws IOException {
|
||||
json.writeStartArray();
|
||||
for (SessionInfo sessionInfo : jsonSessionStore.sessions) {
|
||||
for (var sessionInfo : jsonSessionStore.sessions) {
|
||||
json.writeStartObject();
|
||||
if (sessionInfo.address.getNumber().isPresent()) {
|
||||
json.writeStringField("name", sessionInfo.address.getNumber().get());
|
||||
|
|
|
@ -51,9 +51,9 @@ class JsonSignedPreKeyStore implements SignedPreKeyStore {
|
|||
@Override
|
||||
public List<SignedPreKeyRecord> loadSignedPreKeys() {
|
||||
try {
|
||||
List<SignedPreKeyRecord> results = new LinkedList<>();
|
||||
var results = new LinkedList<SignedPreKeyRecord>();
|
||||
|
||||
for (byte[] serialized : store.values()) {
|
||||
for (var serialized : store.values()) {
|
||||
results.add(new SignedPreKeyRecord(serialized));
|
||||
}
|
||||
|
||||
|
@ -86,16 +86,16 @@ class JsonSignedPreKeyStore implements SignedPreKeyStore {
|
|||
) throws IOException {
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
Map<Integer, byte[]> preKeyMap = new HashMap<>();
|
||||
var preKeyMap = new HashMap<Integer, byte[]>();
|
||||
if (node.isArray()) {
|
||||
for (JsonNode preKey : node) {
|
||||
final int preKeyId = preKey.get("id").asInt();
|
||||
final byte[] preKeyRecord = Base64.getDecoder().decode(preKey.get("record").asText());
|
||||
for (var preKey : node) {
|
||||
final var preKeyId = preKey.get("id").asInt();
|
||||
final var preKeyRecord = Base64.getDecoder().decode(preKey.get("record").asText());
|
||||
preKeyMap.put(preKeyId, preKeyRecord);
|
||||
}
|
||||
}
|
||||
|
||||
JsonSignedPreKeyStore keyStore = new JsonSignedPreKeyStore();
|
||||
var keyStore = new JsonSignedPreKeyStore();
|
||||
keyStore.addSignedPreKeys(preKeyMap);
|
||||
|
||||
return keyStore;
|
||||
|
@ -109,7 +109,7 @@ class JsonSignedPreKeyStore implements SignedPreKeyStore {
|
|||
JsonSignedPreKeyStore jsonPreKeyStore, JsonGenerator json, SerializerProvider serializerProvider
|
||||
) throws IOException {
|
||||
json.writeStartArray();
|
||||
for (Map.Entry<Integer, byte[]> signedPreKey : jsonPreKeyStore.store.entrySet()) {
|
||||
for (var signedPreKey : jsonPreKeyStore.store.entrySet()) {
|
||||
json.writeStartObject();
|
||||
json.writeNumberField("id", signedPreKey.getKey());
|
||||
json.writeStringField("record", Base64.getEncoder().encodeToString(signedPreKey.getValue()));
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.whispersystems.signalservice.api.util.UuidUtil;
|
|||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RecipientStore {
|
||||
|
||||
|
@ -33,7 +32,7 @@ public class RecipientStore {
|
|||
return serviceAddress;
|
||||
}
|
||||
|
||||
for (SignalServiceAddress address : addresses) {
|
||||
for (var address : addresses) {
|
||||
if (address.matches(serviceAddress)) {
|
||||
return address;
|
||||
}
|
||||
|
@ -54,13 +53,13 @@ public class RecipientStore {
|
|||
) throws IOException {
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
Set<SignalServiceAddress> addresses = new HashSet<>();
|
||||
var addresses = new HashSet<SignalServiceAddress>();
|
||||
|
||||
if (node.isArray()) {
|
||||
for (JsonNode recipient : node) {
|
||||
String recipientName = recipient.get("name").asText();
|
||||
UUID uuid = UuidUtil.parseOrThrow(recipient.get("uuid").asText());
|
||||
final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, recipientName);
|
||||
for (var recipient : node) {
|
||||
var recipientName = recipient.get("name").asText();
|
||||
var uuid = UuidUtil.parseOrThrow(recipient.get("uuid").asText());
|
||||
final var serviceAddress = new SignalServiceAddress(uuid, recipientName);
|
||||
addresses.add(serviceAddress);
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +75,7 @@ public class RecipientStore {
|
|||
Set<SignalServiceAddress> addresses, JsonGenerator json, SerializerProvider serializerProvider
|
||||
) throws IOException {
|
||||
json.writeStartArray();
|
||||
for (SignalServiceAddress address : addresses) {
|
||||
for (var address : addresses) {
|
||||
json.writeStartObject();
|
||||
json.writeStringField("name", address.getNumber().get());
|
||||
json.writeStringField("uuid", address.getUuid().get().toString());
|
||||
|
|
|
@ -12,7 +12,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -36,9 +35,9 @@ public class StickerStore {
|
|||
public void serialize(
|
||||
final Map<byte[], Sticker> value, final JsonGenerator jgen, final SerializerProvider provider
|
||||
) throws IOException {
|
||||
final Collection<Sticker> stickers = value.values();
|
||||
final var stickers = value.values();
|
||||
jgen.writeStartArray(stickers.size());
|
||||
for (Sticker sticker : stickers) {
|
||||
for (var sticker : stickers) {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeStringField("packId", Base64.getEncoder().encodeToString(sticker.getPackId()));
|
||||
jgen.writeStringField("packKey", Base64.getEncoder().encodeToString(sticker.getPackKey()));
|
||||
|
@ -55,12 +54,12 @@ public class StickerStore {
|
|||
public Map<byte[], Sticker> deserialize(
|
||||
JsonParser jsonParser, DeserializationContext deserializationContext
|
||||
) throws IOException {
|
||||
Map<byte[], Sticker> stickers = new HashMap<>();
|
||||
var stickers = new HashMap<byte[], Sticker>();
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
for (JsonNode n : node) {
|
||||
byte[] packId = Base64.getDecoder().decode(n.get("packId").asText());
|
||||
byte[] packKey = Base64.getDecoder().decode(n.get("packKey").asText());
|
||||
boolean installed = n.get("installed").asBoolean(false);
|
||||
for (var n : node) {
|
||||
var packId = Base64.getDecoder().decode(n.get("packId").asText());
|
||||
var packKey = Base64.getDecoder().decode(n.get("packKey").asText());
|
||||
var installed = n.get("installed").asBoolean(false);
|
||||
stickers.put(packId, new Sticker(packId, packKey, installed));
|
||||
}
|
||||
|
||||
|
|
|
@ -47,10 +47,10 @@ public class LegacyJsonThreadStore {
|
|||
public Map<String, ThreadInfo> deserialize(
|
||||
JsonParser jsonParser, DeserializationContext deserializationContext
|
||||
) throws IOException {
|
||||
Map<String, ThreadInfo> threads = new HashMap<>();
|
||||
var threads = new HashMap<String, ThreadInfo>();
|
||||
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
|
||||
for (JsonNode n : node) {
|
||||
ThreadInfo t = jsonProcessor.treeToValue(n, ThreadInfo.class);
|
||||
for (var n : node) {
|
||||
var t = jsonProcessor.treeToValue(n, ThreadInfo.class);
|
||||
threads.put(t.id, t);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public class AttachmentUtils {
|
|||
List<SignalServiceAttachment> signalServiceAttachments = null;
|
||||
if (attachments != null) {
|
||||
signalServiceAttachments = new ArrayList<>(attachments.size());
|
||||
for (String attachment : attachments) {
|
||||
for (var attachment : attachments) {
|
||||
try {
|
||||
signalServiceAttachments.add(createAttachment(new File(attachment)));
|
||||
} catch (IOException e) {
|
||||
|
@ -30,7 +30,7 @@ public class AttachmentUtils {
|
|||
}
|
||||
|
||||
public static SignalServiceAttachmentStream createAttachment(File attachmentFile) throws IOException {
|
||||
final StreamDetails streamDetails = Utils.createStreamDetailsFromFile(attachmentFile);
|
||||
final var streamDetails = Utils.createStreamDetailsFromFile(attachmentFile);
|
||||
return createAttachment(streamDetails, Optional.of(attachmentFile.getName()));
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class AttachmentUtils {
|
|||
StreamDetails streamDetails, Optional<String> name
|
||||
) {
|
||||
// TODO mabybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
|
||||
final long uploadTimestamp = System.currentTimeMillis();
|
||||
final var uploadTimestamp = System.currentTimeMillis();
|
||||
Optional<byte[]> preview = Optional.absent();
|
||||
Optional<String> caption = Optional.absent();
|
||||
Optional<String> blurHash = Optional.absent();
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.util.EnumSet;
|
||||
|
@ -20,13 +19,13 @@ import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
|
|||
public class IOUtils {
|
||||
|
||||
public static File createTempFile() throws IOException {
|
||||
final File tempFile = File.createTempFile("signal-cli_tmp_", ".tmp");
|
||||
final var tempFile = File.createTempFile("signal-cli_tmp_", ".tmp");
|
||||
tempFile.deleteOnExit();
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
public static byte[] readFully(InputStream in) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
var baos = new ByteArrayOutputStream();
|
||||
IOUtils.copyStream(in, baos);
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
@ -36,7 +35,7 @@ public class IOUtils {
|
|||
return;
|
||||
}
|
||||
|
||||
final Path path = file.toPath();
|
||||
final var path = file.toPath();
|
||||
try {
|
||||
Set<PosixFilePermission> perms = EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE);
|
||||
Files.createDirectories(path, PosixFilePermissions.asFileAttribute(perms));
|
||||
|
@ -46,7 +45,7 @@ public class IOUtils {
|
|||
}
|
||||
|
||||
public static void createPrivateFile(File path) throws IOException {
|
||||
final Path file = path.toPath();
|
||||
final var file = path.toPath();
|
||||
try {
|
||||
Set<PosixFilePermission> perms = EnumSet.of(OWNER_READ, OWNER_WRITE);
|
||||
Files.createFile(file, PosixFilePermissions.asFileAttribute(perms));
|
||||
|
@ -66,7 +65,7 @@ public class IOUtils {
|
|||
}
|
||||
|
||||
public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws IOException {
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
var buffer = new byte[bufferSize];
|
||||
int read;
|
||||
|
||||
while ((read = input.read(buffer)) != -1) {
|
||||
|
|
|
@ -6,8 +6,6 @@ import org.whispersystems.libsignal.IdentityKey;
|
|||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
import org.whispersystems.libsignal.ecc.ECPrivateKey;
|
||||
import org.whispersystems.libsignal.state.PreKeyRecord;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||
import org.whispersystems.libsignal.util.Medium;
|
||||
|
@ -26,19 +24,19 @@ public class KeyUtils {
|
|||
}
|
||||
|
||||
public static IdentityKeyPair generateIdentityKeyPair() {
|
||||
ECKeyPair djbKeyPair = Curve.generateKeyPair();
|
||||
IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
|
||||
ECPrivateKey djbPrivateKey = djbKeyPair.getPrivateKey();
|
||||
var djbKeyPair = Curve.generateKeyPair();
|
||||
var djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
|
||||
var djbPrivateKey = djbKeyPair.getPrivateKey();
|
||||
|
||||
return new IdentityKeyPair(djbIdentityKey, djbPrivateKey);
|
||||
}
|
||||
|
||||
public static List<PreKeyRecord> generatePreKeyRecords(final int offset, final int batchSize) {
|
||||
List<PreKeyRecord> records = new ArrayList<>(batchSize);
|
||||
for (int i = 0; i < batchSize; i++) {
|
||||
int preKeyId = (offset + i) % Medium.MAX_VALUE;
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);
|
||||
var records = new ArrayList<PreKeyRecord>(batchSize);
|
||||
for (var i = 0; i < batchSize; i++) {
|
||||
var preKeyId = (offset + i) % Medium.MAX_VALUE;
|
||||
var keyPair = Curve.generateKeyPair();
|
||||
var record = new PreKeyRecord(preKeyId, keyPair);
|
||||
|
||||
records.add(record);
|
||||
}
|
||||
|
@ -48,7 +46,7 @@ public class KeyUtils {
|
|||
public static SignedPreKeyRecord generateSignedPreKeyRecord(
|
||||
final IdentityKeyPair identityKeyPair, final int signedPreKeyId
|
||||
) {
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
var keyPair = Curve.generateKeyPair();
|
||||
byte[] signature;
|
||||
try {
|
||||
signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
|
||||
|
@ -83,12 +81,12 @@ public class KeyUtils {
|
|||
}
|
||||
|
||||
private static String getSecret(int size) {
|
||||
byte[] secret = getSecretBytes(size);
|
||||
var secret = getSecretBytes(size);
|
||||
return Base64.getEncoder().encodeToString(secret);
|
||||
}
|
||||
|
||||
public static byte[] getSecretBytes(int size) {
|
||||
byte[] secret = new byte[size];
|
||||
var secret = new byte[size];
|
||||
secureRandom.nextBytes(secret);
|
||||
return secret;
|
||||
}
|
||||
|
|
|
@ -16,32 +16,32 @@ import java.util.UUID;
|
|||
public class MessageCacheUtils {
|
||||
|
||||
public static SignalServiceEnvelope loadEnvelope(File file) throws IOException {
|
||||
try (FileInputStream f = new FileInputStream(file)) {
|
||||
DataInputStream in = new DataInputStream(f);
|
||||
int version = in.readInt();
|
||||
try (var f = new FileInputStream(file)) {
|
||||
var in = new DataInputStream(f);
|
||||
var version = in.readInt();
|
||||
if (version > 4) {
|
||||
return null;
|
||||
}
|
||||
int type = in.readInt();
|
||||
String source = in.readUTF();
|
||||
var type = in.readInt();
|
||||
var source = in.readUTF();
|
||||
UUID sourceUuid = null;
|
||||
if (version >= 3) {
|
||||
sourceUuid = UuidUtil.parseOrNull(in.readUTF());
|
||||
}
|
||||
int sourceDevice = in.readInt();
|
||||
var sourceDevice = in.readInt();
|
||||
if (version == 1) {
|
||||
// read legacy relay field
|
||||
in.readUTF();
|
||||
}
|
||||
long timestamp = in.readLong();
|
||||
var timestamp = in.readLong();
|
||||
byte[] content = null;
|
||||
int contentLen = in.readInt();
|
||||
var contentLen = in.readInt();
|
||||
if (contentLen > 0) {
|
||||
content = new byte[contentLen];
|
||||
in.readFully(content);
|
||||
}
|
||||
byte[] legacyMessage = null;
|
||||
int legacyMessageLen = in.readInt();
|
||||
var legacyMessageLen = in.readInt();
|
||||
if (legacyMessageLen > 0) {
|
||||
legacyMessage = new byte[legacyMessageLen];
|
||||
in.readFully(legacyMessage);
|
||||
|
@ -75,8 +75,8 @@ public class MessageCacheUtils {
|
|||
}
|
||||
|
||||
public static void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException {
|
||||
try (FileOutputStream f = new FileOutputStream(file)) {
|
||||
try (DataOutputStream out = new DataOutputStream(f)) {
|
||||
try (var f = new FileOutputStream(file)) {
|
||||
try (var out = new DataOutputStream(f)) {
|
||||
out.writeInt(4); // version
|
||||
out.writeInt(envelope.getType());
|
||||
out.writeUTF(envelope.getSourceE164().isPresent() ? envelope.getSourceE164().get() : "");
|
||||
|
@ -96,7 +96,7 @@ public class MessageCacheUtils {
|
|||
out.writeInt(0);
|
||||
}
|
||||
out.writeLong(envelope.getServerReceivedTimestamp());
|
||||
String uuid = envelope.getUuid();
|
||||
var uuid = envelope.getUuid();
|
||||
out.writeUTF(uuid == null ? "" : uuid);
|
||||
out.writeLong(envelope.getServerDeliveredTimestamp());
|
||||
}
|
||||
|
|
|
@ -12,18 +12,18 @@ public final class PinHashing {
|
|||
}
|
||||
|
||||
public static HashedPin hashPin(String pin, KeyBackupService.HashSession hashSession) {
|
||||
final Argon2Parameters params = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id).withParallelism(1)
|
||||
final var params = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id).withParallelism(1)
|
||||
.withIterations(32)
|
||||
.withVersion(Argon2Parameters.ARGON2_VERSION_13)
|
||||
.withMemoryAsKB(16 * 1024)
|
||||
.withSalt(hashSession.hashSalt())
|
||||
.build();
|
||||
|
||||
final Argon2BytesGenerator generator = new Argon2BytesGenerator();
|
||||
final var generator = new Argon2BytesGenerator();
|
||||
generator.init(params);
|
||||
|
||||
return PinHasher.hashPin(PinHasher.normalize(pin), password -> {
|
||||
byte[] output = new byte[64];
|
||||
var output = new byte[64];
|
||||
generator.generateBytes(password, output);
|
||||
return output;
|
||||
});
|
||||
|
|
|
@ -13,11 +13,11 @@ public class ProfileUtils {
|
|||
public static SignalProfile decryptProfile(
|
||||
final ProfileKey profileKey, final SignalServiceProfile encryptedProfile
|
||||
) {
|
||||
ProfileCipher profileCipher = new ProfileCipher(profileKey);
|
||||
var profileCipher = new ProfileCipher(profileKey);
|
||||
try {
|
||||
String name = decryptName(encryptedProfile.getName(), profileCipher);
|
||||
String about = decryptName(encryptedProfile.getAbout(), profileCipher);
|
||||
String aboutEmoji = decryptName(encryptedProfile.getAboutEmoji(), profileCipher);
|
||||
var name = decryptName(encryptedProfile.getName(), profileCipher);
|
||||
var about = decryptName(encryptedProfile.getAbout(), profileCipher);
|
||||
var aboutEmoji = decryptName(encryptedProfile.getAboutEmoji(), profileCipher);
|
||||
String unidentifiedAccess;
|
||||
try {
|
||||
unidentifiedAccess = encryptedProfile.getUnidentifiedAccess() == null
|
||||
|
|
|
@ -13,8 +13,6 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class StickerUtils {
|
||||
|
@ -33,7 +31,7 @@ public class StickerUtils {
|
|||
throw new StickerPackInvalidException("Could not find manifest.json");
|
||||
}
|
||||
|
||||
JsonStickerPack pack = parseStickerPack(rootPath, zip);
|
||||
var pack = parseStickerPack(rootPath, zip);
|
||||
|
||||
if (pack.stickers == null) {
|
||||
throw new StickerPackInvalidException("Must set a 'stickers' field.");
|
||||
|
@ -43,8 +41,8 @@ public class StickerUtils {
|
|||
throw new StickerPackInvalidException("Must include stickers.");
|
||||
}
|
||||
|
||||
List<SignalServiceStickerManifestUpload.StickerInfo> stickers = new ArrayList<>(pack.stickers.size());
|
||||
for (JsonStickerPack.JsonSticker sticker : pack.stickers) {
|
||||
var stickers = new ArrayList<SignalServiceStickerManifestUpload.StickerInfo>(pack.stickers.size());
|
||||
for (var sticker : pack.stickers) {
|
||||
if (sticker.file == null) {
|
||||
throw new StickerPackInvalidException("Must set a 'file' field on each sticker.");
|
||||
}
|
||||
|
@ -56,9 +54,8 @@ public class StickerUtils {
|
|||
throw new StickerPackInvalidException("Could not find find " + sticker.file);
|
||||
}
|
||||
|
||||
String contentType = Utils.getFileMimeType(new File(sticker.file), null);
|
||||
SignalServiceStickerManifestUpload.StickerInfo stickerInfo = new SignalServiceStickerManifestUpload.StickerInfo(
|
||||
data.first(),
|
||||
var contentType = Utils.getFileMimeType(new File(sticker.file), null);
|
||||
var stickerInfo = new SignalServiceStickerManifestUpload.StickerInfo(data.first(),
|
||||
data.second(),
|
||||
Optional.fromNullable(sticker.emoji).or(""),
|
||||
contentType);
|
||||
|
@ -78,7 +75,7 @@ public class StickerUtils {
|
|||
throw new StickerPackInvalidException("Could not find find " + pack.cover.file);
|
||||
}
|
||||
|
||||
String contentType = Utils.getFileMimeType(new File(pack.cover.file), null);
|
||||
var contentType = Utils.getFileMimeType(new File(pack.cover.file), null);
|
||||
cover = new SignalServiceStickerManifestUpload.StickerInfo(data.first(),
|
||||
data.second(),
|
||||
Optional.fromNullable(pack.cover.emoji).or(""),
|
||||
|
@ -102,10 +99,10 @@ public class StickerUtils {
|
|||
final String rootPath, final ZipFile zip, final String subfile
|
||||
) throws IOException {
|
||||
if (zip != null) {
|
||||
final ZipEntry entry = zip.getEntry(subfile);
|
||||
final var entry = zip.getEntry(subfile);
|
||||
return new Pair<>(zip.getInputStream(entry), entry.getSize());
|
||||
} else {
|
||||
final File file = new File(rootPath, subfile);
|
||||
final var file = new File(rootPath, subfile);
|
||||
return new Pair<>(new FileInputStream(file), file.length());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.asamk.signal.manager.util;
|
|||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.fingerprint.Fingerprint;
|
||||
import org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||
|
@ -21,7 +20,7 @@ import java.nio.file.Files;
|
|||
public class Utils {
|
||||
|
||||
public static String getFileMimeType(File file, String defaultMimeType) throws IOException {
|
||||
String mime = Files.probeContentType(file.toPath());
|
||||
var mime = Files.probeContentType(file.toPath());
|
||||
if (mime == null) {
|
||||
try (InputStream bufferedStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
mime = URLConnection.guessContentTypeFromStream(bufferedStream);
|
||||
|
@ -35,8 +34,8 @@ public class Utils {
|
|||
|
||||
public static StreamDetails createStreamDetailsFromFile(File file) throws IOException {
|
||||
InputStream stream = new FileInputStream(file);
|
||||
final long size = file.length();
|
||||
final String mime = getFileMimeType(file, "application/octet-stream");
|
||||
final var size = file.length();
|
||||
final var mime = getFileMimeType(file, "application/octet-stream");
|
||||
return new StreamDetails(stream, mime, size);
|
||||
}
|
||||
|
||||
|
@ -66,7 +65,7 @@ public class Utils {
|
|||
theirId = theirAddress.getNumber().get().getBytes();
|
||||
}
|
||||
|
||||
Fingerprint fingerprint = new NumericFingerprintGenerator(5200).createFor(version,
|
||||
var fingerprint = new NumericFingerprintGenerator(5200).createFor(version,
|
||||
ownId,
|
||||
ownIdentityKey,
|
||||
theirId,
|
||||
|
@ -83,7 +82,7 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
|
||||
JsonNode node = parent.get(name);
|
||||
var node = parent.get(name);
|
||||
if (node == null || node.isNull()) {
|
||||
throw new InvalidObjectException(String.format("Incorrect file format: expected parameter %s not found ",
|
||||
name));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue