Convert classes to records

This commit is contained in:
AsamK 2023-09-30 22:26:08 +02:00
parent 0dda8b405e
commit 735766669e
10 changed files with 54 additions and 178 deletions

View file

@ -11,10 +11,7 @@ import java.nio.charset.StandardCharsets;
import static org.whispersystems.signalservice.internal.util.Util.isEmpty; import static org.whispersystems.signalservice.internal.util.Util.isEmpty;
public final class StickerPackUrl { public record StickerPackUrl(StickerPackId packId, byte[] packKey) {
private final StickerPackId packId;
private final byte[] packKey;
/** /**
* @throws InvalidStickerPackLinkException If url cannot be parsed. * @throws InvalidStickerPackLinkException If url cannot be parsed.
@ -48,11 +45,6 @@ public final class StickerPackUrl {
return new StickerPackUrl(packId, packKey); return new StickerPackUrl(packId, packKey);
} }
public StickerPackUrl(final StickerPackId packId, final byte[] packKey) {
this.packId = packId;
this.packKey = packKey;
}
public URI getUrl() { public URI getUrl() {
try { try {
return new URI("https", return new URI("https",
@ -67,14 +59,6 @@ public final class StickerPackUrl {
} }
} }
public StickerPackId getPackId() {
return packId;
}
public byte[] getPackKey() {
return packKey;
}
public final static class InvalidStickerPackLinkException extends Exception { public final static class InvalidStickerPackLinkException extends Exception {
public InvalidStickerPackLinkException(String message) { public InvalidStickerPackLinkException(String message) {

View file

@ -1,26 +1,3 @@
package org.asamk.signal.manager.config; package org.asamk.signal.manager.config;
public class KeyBackupConfig { public record KeyBackupConfig(String enclaveName, byte[] serviceId, String mrenclave) {}
private final String enclaveName;
private final byte[] serviceId;
private final String mrenclave;
public KeyBackupConfig(final String enclaveName, final byte[] serviceId, final String mrenclave) {
this.enclaveName = enclaveName;
this.serviceId = serviceId;
this.mrenclave = mrenclave;
}
public String getEnclaveName() {
return enclaveName;
}
public byte[] getServiceId() {
return serviceId;
}
public String getMrenclave() {
return mrenclave;
}
}

View file

@ -6,62 +6,12 @@ import org.whispersystems.signalservice.internal.configuration.SignalServiceConf
import java.util.Collection; import java.util.Collection;
public class ServiceEnvironmentConfig { public record ServiceEnvironmentConfig(
ServiceEnvironment type,
private final ServiceEnvironment type; SignalServiceConfiguration signalServiceConfiguration,
private final SignalServiceConfiguration signalServiceConfiguration; ECPublicKey unidentifiedSenderTrustRoot,
KeyBackupConfig keyBackupConfig,
private final ECPublicKey unidentifiedSenderTrustRoot; Collection<KeyBackupConfig> fallbackKeyBackupConfigs,
String cdsiMrenclave,
private final KeyBackupConfig keyBackupConfig; String svr2Mrenclave
private final Collection<KeyBackupConfig> fallbackKeyBackupConfigs; ) {}
private final String cdsiMrenclave;
private final String svr2Mrenclave;
public ServiceEnvironmentConfig(
final ServiceEnvironment type,
final SignalServiceConfiguration signalServiceConfiguration,
final ECPublicKey unidentifiedSenderTrustRoot,
final KeyBackupConfig keyBackupConfig,
final Collection<KeyBackupConfig> fallbackKeyBackupConfigs,
final String cdsiMrenclave,
final String svr2Mrenclave
) {
this.type = type;
this.signalServiceConfiguration = signalServiceConfiguration;
this.unidentifiedSenderTrustRoot = unidentifiedSenderTrustRoot;
this.keyBackupConfig = keyBackupConfig;
this.fallbackKeyBackupConfigs = fallbackKeyBackupConfigs;
this.cdsiMrenclave = cdsiMrenclave;
this.svr2Mrenclave = svr2Mrenclave;
}
public ServiceEnvironment getType() {
return type;
}
public SignalServiceConfiguration getSignalServiceConfiguration() {
return signalServiceConfiguration;
}
public ECPublicKey getUnidentifiedSenderTrustRoot() {
return unidentifiedSenderTrustRoot;
}
public KeyBackupConfig getKeyBackupConfig() {
return keyBackupConfig;
}
public Collection<KeyBackupConfig> getFallbackKeyBackupConfigs() {
return fallbackKeyBackupConfigs;
}
public String getCdsiMrenclave() {
return cdsiMrenclave;
}
public String getSvr2Mrenclave() {
return svr2Mrenclave;
}
}

View file

@ -162,7 +162,7 @@ public class RecipientHelper {
account.getRecipientStore().getServiceIdToProfileKeyMap(), account.getRecipientStore().getServiceIdToProfileKeyMap(),
useCompat, useCompat,
Optional.empty(), Optional.empty(),
serviceEnvironmentConfig.getCdsiMrenclave(), serviceEnvironmentConfig.cdsiMrenclave(),
null, null,
token -> { token -> {
// Not storing for partial refresh // Not storing for partial refresh

View file

@ -902,8 +902,8 @@ public class ManagerImpl implements Manager {
@Override @Override
public void installStickerPack(StickerPackUrl url) throws IOException { public void installStickerPack(StickerPackUrl url) throws IOException {
final var packId = url.getPackId(); final var packId = url.packId();
final var packKey = url.getPackKey(); final var packKey = url.packKey();
try { try {
context.getStickerHelper().retrieveStickerPack(packId, packKey); context.getStickerHelper().retrieveStickerPack(packId, packKey);
} catch (InvalidMessageException e) { } catch (InvalidMessageException e) {

View file

@ -82,12 +82,12 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
password = KeyUtils.createPassword(); password = KeyUtils.createPassword();
GroupsV2Operations groupsV2Operations; GroupsV2Operations groupsV2Operations;
try { try {
groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration()), groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()),
ServiceConfig.GROUP_MAX_SIZE); ServiceConfig.GROUP_MAX_SIZE);
} catch (Throwable ignored) { } catch (Throwable ignored) {
groupsV2Operations = null; groupsV2Operations = null;
} }
accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(), accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.signalServiceConfiguration(),
new DynamicCredentialsProvider(null, null, null, password, SignalServiceAddress.DEFAULT_DEVICE_ID), new DynamicCredentialsProvider(null, null, null, password, SignalServiceAddress.DEFAULT_DEVICE_ID),
userAgent, userAgent,
groupsV2Operations, groupsV2Operations,
@ -146,7 +146,7 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
account = SignalAccount.createOrUpdateLinkedAccount(pathConfig.dataPath(), account = SignalAccount.createOrUpdateLinkedAccount(pathConfig.dataPath(),
accountPath, accountPath,
number, number,
serviceEnvironmentConfig.getType(), serviceEnvironmentConfig.type(),
aci, aci,
pni, pni,
password, password,
@ -221,7 +221,7 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
} }
if (signalAccount.isRegistered() if (signalAccount.isRegistered()
&& signalAccount.getServiceEnvironment() != null && signalAccount.getServiceEnvironment() != null
&& signalAccount.getServiceEnvironment() != serviceEnvironmentConfig.getType()) { && signalAccount.getServiceEnvironment() != serviceEnvironmentConfig.type()) {
logger.debug("Account is registered in another environment: {}.", logger.debug("Account is registered in another environment: {}.",
signalAccount.getServiceEnvironment()); signalAccount.getServiceEnvironment());
return false; return false;

View file

@ -82,12 +82,12 @@ public class RegistrationManagerImpl implements RegistrationManager {
GroupsV2Operations groupsV2Operations; GroupsV2Operations groupsV2Operations;
try { try {
groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration()), groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()),
ServiceConfig.GROUP_MAX_SIZE); ServiceConfig.GROUP_MAX_SIZE);
} catch (Throwable ignored) { } catch (Throwable ignored) {
groupsV2Operations = null; groupsV2Operations = null;
} }
this.accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(), this.accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.signalServiceConfiguration(),
new DynamicCredentialsProvider( new DynamicCredentialsProvider(
// Using empty UUID, because registering doesn't work otherwise // Using empty UUID, because registering doesn't work otherwise
null, null, account.getNumber(), account.getPassword(), SignalServiceAddress.DEFAULT_DEVICE_ID), null, null, account.getNumber(), account.getPassword(), SignalServiceAddress.DEFAULT_DEVICE_ID),
@ -95,19 +95,19 @@ public class RegistrationManagerImpl implements RegistrationManager {
groupsV2Operations, groupsV2Operations,
ServiceConfig.AUTOMATIC_NETWORK_RETRY); ServiceConfig.AUTOMATIC_NETWORK_RETRY);
final var keyBackupService = accountManager.getKeyBackupService(ServiceConfig.getIasKeyStore(), final var keyBackupService = accountManager.getKeyBackupService(ServiceConfig.getIasKeyStore(),
serviceEnvironmentConfig.getKeyBackupConfig().getEnclaveName(), serviceEnvironmentConfig.keyBackupConfig().enclaveName(),
serviceEnvironmentConfig.getKeyBackupConfig().getServiceId(), serviceEnvironmentConfig.keyBackupConfig().serviceId(),
serviceEnvironmentConfig.getKeyBackupConfig().getMrenclave(), serviceEnvironmentConfig.keyBackupConfig().mrenclave(),
10); 10);
final var fallbackKeyBackupServices = serviceEnvironmentConfig.getFallbackKeyBackupConfigs() final var fallbackKeyBackupServices = serviceEnvironmentConfig.fallbackKeyBackupConfigs()
.stream() .stream()
.map(config -> accountManager.getKeyBackupService(ServiceConfig.getIasKeyStore(), .map(config -> accountManager.getKeyBackupService(ServiceConfig.getIasKeyStore(),
config.getEnclaveName(), config.enclaveName(),
config.getServiceId(), config.serviceId(),
config.getMrenclave(), config.mrenclave(),
10)) 10))
.toList(); .toList();
final var secureValueRecoveryV2 = accountManager.getSecureValueRecoveryV2(serviceEnvironmentConfig.getSvr2Mrenclave()); final var secureValueRecoveryV2 = accountManager.getSecureValueRecoveryV2(serviceEnvironmentConfig.svr2Mrenclave());
this.pinHelper = new PinHelper(keyBackupService, fallbackKeyBackupServices, secureValueRecoveryV2); this.pinHelper = new PinHelper(keyBackupService, fallbackKeyBackupServices, secureValueRecoveryV2);
} }
@ -117,7 +117,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException { ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException {
if (account.isRegistered() if (account.isRegistered()
&& account.getServiceEnvironment() != null && account.getServiceEnvironment() != null
&& account.getServiceEnvironment() != serviceEnvironmentConfig.getType()) { && account.getServiceEnvironment() != serviceEnvironmentConfig.type()) {
throw new IOException("Account is registered in another environment: " + account.getServiceEnvironment()); throw new IOException("Account is registered in another environment: " + account.getServiceEnvironment());
} }
@ -216,7 +216,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
private boolean attemptReactivateAccount() { private boolean attemptReactivateAccount() {
try { try {
final var accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(), final var accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.signalServiceConfiguration(),
account.getCredentialsProvider(), account.getCredentialsProvider(),
userAgent, userAgent,
null, null,

View file

@ -94,7 +94,7 @@ public class SignalDependencies {
public SignalServiceAccountManager getAccountManager() { public SignalServiceAccountManager getAccountManager() {
return getOrCreate(() -> accountManager, return getOrCreate(() -> accountManager,
() -> accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(), () -> accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.signalServiceConfiguration(),
credentialsProvider, credentialsProvider,
userAgent, userAgent,
getGroupsV2Operations(), getGroupsV2Operations(),
@ -102,7 +102,7 @@ public class SignalDependencies {
} }
public SignalServiceAccountManager createUnauthenticatedAccountManager(String number, String password) { public SignalServiceAccountManager createUnauthenticatedAccountManager(String number, String password) {
return new SignalServiceAccountManager(getServiceEnvironmentConfig().getSignalServiceConfiguration(), return new SignalServiceAccountManager(getServiceEnvironmentConfig().signalServiceConfiguration(),
null, null,
null, null,
number, number,
@ -119,13 +119,13 @@ public class SignalDependencies {
public GroupsV2Operations getGroupsV2Operations() { public GroupsV2Operations getGroupsV2Operations() {
return getOrCreate(() -> groupsV2Operations, return getOrCreate(() -> groupsV2Operations,
() -> groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration()), () -> groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()),
ServiceConfig.GROUP_MAX_SIZE)); ServiceConfig.GROUP_MAX_SIZE));
} }
private ClientZkOperations getClientZkOperations() { private ClientZkOperations getClientZkOperations() {
return getOrCreate(() -> clientZkOperations, return getOrCreate(() -> clientZkOperations,
() -> clientZkOperations = ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration())); () -> clientZkOperations = ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()));
} }
private ClientZkProfileOperations getClientZkProfileOperations() { private ClientZkProfileOperations getClientZkProfileOperations() {
@ -141,7 +141,7 @@ public class SignalDependencies {
@Override @Override
public WebSocketConnection createWebSocket() { public WebSocketConnection createWebSocket() {
return new WebSocketConnection("normal", return new WebSocketConnection("normal",
serviceEnvironmentConfig.getSignalServiceConfiguration(), serviceEnvironmentConfig.signalServiceConfiguration(),
Optional.of(credentialsProvider), Optional.of(credentialsProvider),
userAgent, userAgent,
healthMonitor, healthMonitor,
@ -151,7 +151,7 @@ public class SignalDependencies {
@Override @Override
public WebSocketConnection createUnidentifiedWebSocket() { public WebSocketConnection createUnidentifiedWebSocket() {
return new WebSocketConnection("unidentified", return new WebSocketConnection("unidentified",
serviceEnvironmentConfig.getSignalServiceConfiguration(), serviceEnvironmentConfig.signalServiceConfiguration(),
Optional.empty(), Optional.empty(),
userAgent, userAgent,
healthMonitor, healthMonitor,
@ -165,7 +165,7 @@ public class SignalDependencies {
public SignalServiceMessageReceiver getMessageReceiver() { public SignalServiceMessageReceiver getMessageReceiver() {
return getOrCreate(() -> messageReceiver, return getOrCreate(() -> messageReceiver,
() -> messageReceiver = new SignalServiceMessageReceiver(serviceEnvironmentConfig.getSignalServiceConfiguration(), () -> messageReceiver = new SignalServiceMessageReceiver(serviceEnvironmentConfig.signalServiceConfiguration(),
credentialsProvider, credentialsProvider,
userAgent, userAgent,
getClientZkProfileOperations(), getClientZkProfileOperations(),
@ -174,7 +174,7 @@ public class SignalDependencies {
public SignalServiceMessageSender getMessageSender() { public SignalServiceMessageSender getMessageSender() {
return getOrCreate(() -> messageSender, return getOrCreate(() -> messageSender,
() -> messageSender = new SignalServiceMessageSender(serviceEnvironmentConfig.getSignalServiceConfiguration(), () -> messageSender = new SignalServiceMessageSender(serviceEnvironmentConfig.signalServiceConfiguration(),
credentialsProvider, credentialsProvider,
dataStore, dataStore,
sessionLock, sessionLock,
@ -190,24 +190,24 @@ public class SignalDependencies {
public KeyBackupService getKeyBackupService() { public KeyBackupService getKeyBackupService() {
return getOrCreate(() -> keyBackupService, return getOrCreate(() -> keyBackupService,
() -> keyBackupService = getAccountManager().getKeyBackupService(ServiceConfig.getIasKeyStore(), () -> keyBackupService = getAccountManager().getKeyBackupService(ServiceConfig.getIasKeyStore(),
serviceEnvironmentConfig.getKeyBackupConfig().getEnclaveName(), serviceEnvironmentConfig.keyBackupConfig().enclaveName(),
serviceEnvironmentConfig.getKeyBackupConfig().getServiceId(), serviceEnvironmentConfig.keyBackupConfig().serviceId(),
serviceEnvironmentConfig.getKeyBackupConfig().getMrenclave(), serviceEnvironmentConfig.keyBackupConfig().mrenclave(),
10)); 10));
} }
public SecureValueRecoveryV2 getSecureValueRecoveryV2() { public SecureValueRecoveryV2 getSecureValueRecoveryV2() {
return getOrCreate(() -> secureValueRecoveryV2, return getOrCreate(() -> secureValueRecoveryV2,
() -> secureValueRecoveryV2 = getAccountManager().getSecureValueRecoveryV2(serviceEnvironmentConfig.getSvr2Mrenclave())); () -> secureValueRecoveryV2 = getAccountManager().getSecureValueRecoveryV2(serviceEnvironmentConfig.svr2Mrenclave()));
} }
public Collection<KeyBackupService> getFallbackKeyBackupServices() { public Collection<KeyBackupService> getFallbackKeyBackupServices() {
return serviceEnvironmentConfig.getFallbackKeyBackupConfigs() return serviceEnvironmentConfig.fallbackKeyBackupConfigs()
.stream() .stream()
.map(config -> getAccountManager().getKeyBackupService(ServiceConfig.getIasKeyStore(), .map(config -> getAccountManager().getKeyBackupService(ServiceConfig.getIasKeyStore(),
config.getEnclaveName(), config.enclaveName(),
config.getServiceId(), config.serviceId(),
config.getMrenclave(), config.mrenclave(),
10)) 10))
.toList(); .toList();
} }
@ -221,7 +221,7 @@ public class SignalDependencies {
public SignalServiceCipher getCipher() { public SignalServiceCipher getCipher() {
return getOrCreate(() -> cipher, () -> { return getOrCreate(() -> cipher, () -> {
final var certificateValidator = new CertificateValidator(serviceEnvironmentConfig.getUnidentifiedSenderTrustRoot()); final var certificateValidator = new CertificateValidator(serviceEnvironmentConfig.unidentifiedSenderTrustRoot());
final var address = new SignalServiceAddress(credentialsProvider.getAci(), credentialsProvider.getE164()); final var address = new SignalServiceAddress(credentialsProvider.getAci(), credentialsProvider.getE164());
final var deviceId = credentialsProvider.getDeviceId(); final var deviceId = credentialsProvider.getDeviceId();
cipher = new SignalServiceCipher(address, deviceId, dataStore.aci(), sessionLock, certificateValidator); cipher = new SignalServiceCipher(address, deviceId, dataStore.aci(), sessionLock, certificateValidator);

View file

@ -881,10 +881,10 @@ public class SignalAccount implements Closeable {
var profileStoreNode = rootNode.get("profileStore"); var profileStoreNode = rootNode.get("profileStore");
final var legacyProfileStore = jsonProcessor.convertValue(profileStoreNode, LegacyProfileStore.class); final var legacyProfileStore = jsonProcessor.convertValue(profileStoreNode, LegacyProfileStore.class);
for (var profileEntry : legacyProfileStore.getProfileEntries()) { for (var profileEntry : legacyProfileStore.getProfileEntries()) {
var recipientId = getRecipientResolver().resolveRecipient(profileEntry.getAddress()); var recipientId = getRecipientResolver().resolveRecipient(profileEntry.address());
// Not migrating profile key credential here, it was changed to expiring profile key credentials // Not migrating profile key credential here, it was changed to expiring profile key credentials
getProfileStore().storeProfileKey(recipientId, profileEntry.getProfileKey()); getProfileStore().storeProfileKey(recipientId, profileEntry.profileKey());
final var profile = profileEntry.getProfile(); final var profile = profileEntry.profile();
if (profile != null) { if (profile != null) {
final var capabilities = new HashSet<Profile.Capability>(); final var capabilities = new HashSet<Profile.Capability>();
if (profile.getCapabilities() != null) { if (profile.getCapabilities() != null) {
@ -895,7 +895,7 @@ public class SignalAccount implements Closeable {
capabilities.add(Profile.Capability.storage); capabilities.add(Profile.Capability.storage);
} }
} }
final var newProfile = new Profile(profileEntry.getLastUpdateTimestamp(), final var newProfile = new Profile(profileEntry.lastUpdateTimestamp(),
profile.getGivenName(), profile.getGivenName(),
profile.getFamilyName(), profile.getFamilyName(),
profile.getAbout(), profile.getAbout(),

View file

@ -3,41 +3,6 @@ package org.asamk.signal.manager.storage.profiles;
import org.asamk.signal.manager.storage.recipients.RecipientAddress; import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.signal.libsignal.zkgroup.profiles.ProfileKey; import org.signal.libsignal.zkgroup.profiles.ProfileKey;
public class LegacySignalProfileEntry { public record LegacySignalProfileEntry(
RecipientAddress address, ProfileKey profileKey, long lastUpdateTimestamp, LegacySignalProfile profile
private final RecipientAddress address; ) {}
private final ProfileKey profileKey;
private final long lastUpdateTimestamp;
private final LegacySignalProfile profile;
public LegacySignalProfileEntry(
final RecipientAddress address,
final ProfileKey profileKey,
final long lastUpdateTimestamp,
final LegacySignalProfile profile
) {
this.address = address;
this.profileKey = profileKey;
this.lastUpdateTimestamp = lastUpdateTimestamp;
this.profile = profile;
}
public RecipientAddress getAddress() {
return address;
}
public ProfileKey getProfileKey() {
return profileKey;
}
public long getLastUpdateTimestamp() {
return lastUpdateTimestamp;
}
public LegacySignalProfile getProfile() {
return profile;
}
}