mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Convert classes to records
This commit is contained in:
parent
0dda8b405e
commit
735766669e
10 changed files with 54 additions and 178 deletions
|
@ -11,10 +11,7 @@ import java.nio.charset.StandardCharsets;
|
|||
|
||||
import static org.whispersystems.signalservice.internal.util.Util.isEmpty;
|
||||
|
||||
public final class StickerPackUrl {
|
||||
|
||||
private final StickerPackId packId;
|
||||
private final byte[] packKey;
|
||||
public record StickerPackUrl(StickerPackId packId, byte[] packKey) {
|
||||
|
||||
/**
|
||||
* @throws InvalidStickerPackLinkException If url cannot be parsed.
|
||||
|
@ -48,11 +45,6 @@ public final class StickerPackUrl {
|
|||
return new StickerPackUrl(packId, packKey);
|
||||
}
|
||||
|
||||
public StickerPackUrl(final StickerPackId packId, final byte[] packKey) {
|
||||
this.packId = packId;
|
||||
this.packKey = packKey;
|
||||
}
|
||||
|
||||
public URI getUrl() {
|
||||
try {
|
||||
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 InvalidStickerPackLinkException(String message) {
|
||||
|
|
|
@ -1,26 +1,3 @@
|
|||
package org.asamk.signal.manager.config;
|
||||
|
||||
public class KeyBackupConfig {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
public record KeyBackupConfig(String enclaveName, byte[] serviceId, String mrenclave) {}
|
||||
|
|
|
@ -6,62 +6,12 @@ import org.whispersystems.signalservice.internal.configuration.SignalServiceConf
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ServiceEnvironmentConfig {
|
||||
|
||||
private final ServiceEnvironment type;
|
||||
private final SignalServiceConfiguration signalServiceConfiguration;
|
||||
|
||||
private final ECPublicKey unidentifiedSenderTrustRoot;
|
||||
|
||||
private final KeyBackupConfig keyBackupConfig;
|
||||
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;
|
||||
}
|
||||
}
|
||||
public record ServiceEnvironmentConfig(
|
||||
ServiceEnvironment type,
|
||||
SignalServiceConfiguration signalServiceConfiguration,
|
||||
ECPublicKey unidentifiedSenderTrustRoot,
|
||||
KeyBackupConfig keyBackupConfig,
|
||||
Collection<KeyBackupConfig> fallbackKeyBackupConfigs,
|
||||
String cdsiMrenclave,
|
||||
String svr2Mrenclave
|
||||
) {}
|
||||
|
|
|
@ -162,7 +162,7 @@ public class RecipientHelper {
|
|||
account.getRecipientStore().getServiceIdToProfileKeyMap(),
|
||||
useCompat,
|
||||
Optional.empty(),
|
||||
serviceEnvironmentConfig.getCdsiMrenclave(),
|
||||
serviceEnvironmentConfig.cdsiMrenclave(),
|
||||
null,
|
||||
token -> {
|
||||
// Not storing for partial refresh
|
||||
|
|
|
@ -902,8 +902,8 @@ public class ManagerImpl implements Manager {
|
|||
|
||||
@Override
|
||||
public void installStickerPack(StickerPackUrl url) throws IOException {
|
||||
final var packId = url.getPackId();
|
||||
final var packKey = url.getPackKey();
|
||||
final var packId = url.packId();
|
||||
final var packKey = url.packKey();
|
||||
try {
|
||||
context.getStickerHelper().retrieveStickerPack(packId, packKey);
|
||||
} catch (InvalidMessageException e) {
|
||||
|
|
|
@ -82,12 +82,12 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
|
|||
password = KeyUtils.createPassword();
|
||||
GroupsV2Operations groupsV2Operations;
|
||||
try {
|
||||
groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration()),
|
||||
groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()),
|
||||
ServiceConfig.GROUP_MAX_SIZE);
|
||||
} catch (Throwable ignored) {
|
||||
groupsV2Operations = null;
|
||||
}
|
||||
accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||
accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
new DynamicCredentialsProvider(null, null, null, password, SignalServiceAddress.DEFAULT_DEVICE_ID),
|
||||
userAgent,
|
||||
groupsV2Operations,
|
||||
|
@ -146,7 +146,7 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
|
|||
account = SignalAccount.createOrUpdateLinkedAccount(pathConfig.dataPath(),
|
||||
accountPath,
|
||||
number,
|
||||
serviceEnvironmentConfig.getType(),
|
||||
serviceEnvironmentConfig.type(),
|
||||
aci,
|
||||
pni,
|
||||
password,
|
||||
|
@ -221,7 +221,7 @@ public class ProvisioningManagerImpl implements ProvisioningManager {
|
|||
}
|
||||
if (signalAccount.isRegistered()
|
||||
&& signalAccount.getServiceEnvironment() != null
|
||||
&& signalAccount.getServiceEnvironment() != serviceEnvironmentConfig.getType()) {
|
||||
&& signalAccount.getServiceEnvironment() != serviceEnvironmentConfig.type()) {
|
||||
logger.debug("Account is registered in another environment: {}.",
|
||||
signalAccount.getServiceEnvironment());
|
||||
return false;
|
||||
|
|
|
@ -82,12 +82,12 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
|
||||
GroupsV2Operations groupsV2Operations;
|
||||
try {
|
||||
groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration()),
|
||||
groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()),
|
||||
ServiceConfig.GROUP_MAX_SIZE);
|
||||
} catch (Throwable ignored) {
|
||||
groupsV2Operations = null;
|
||||
}
|
||||
this.accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||
this.accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
new DynamicCredentialsProvider(
|
||||
// Using empty UUID, because registering doesn't work otherwise
|
||||
null, null, account.getNumber(), account.getPassword(), SignalServiceAddress.DEFAULT_DEVICE_ID),
|
||||
|
@ -95,19 +95,19 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
groupsV2Operations,
|
||||
ServiceConfig.AUTOMATIC_NETWORK_RETRY);
|
||||
final var keyBackupService = accountManager.getKeyBackupService(ServiceConfig.getIasKeyStore(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getEnclaveName(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getServiceId(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getMrenclave(),
|
||||
serviceEnvironmentConfig.keyBackupConfig().enclaveName(),
|
||||
serviceEnvironmentConfig.keyBackupConfig().serviceId(),
|
||||
serviceEnvironmentConfig.keyBackupConfig().mrenclave(),
|
||||
10);
|
||||
final var fallbackKeyBackupServices = serviceEnvironmentConfig.getFallbackKeyBackupConfigs()
|
||||
final var fallbackKeyBackupServices = serviceEnvironmentConfig.fallbackKeyBackupConfigs()
|
||||
.stream()
|
||||
.map(config -> accountManager.getKeyBackupService(ServiceConfig.getIasKeyStore(),
|
||||
config.getEnclaveName(),
|
||||
config.getServiceId(),
|
||||
config.getMrenclave(),
|
||||
config.enclaveName(),
|
||||
config.serviceId(),
|
||||
config.mrenclave(),
|
||||
10))
|
||||
.toList();
|
||||
final var secureValueRecoveryV2 = accountManager.getSecureValueRecoveryV2(serviceEnvironmentConfig.getSvr2Mrenclave());
|
||||
final var secureValueRecoveryV2 = accountManager.getSecureValueRecoveryV2(serviceEnvironmentConfig.svr2Mrenclave());
|
||||
this.pinHelper = new PinHelper(keyBackupService, fallbackKeyBackupServices, secureValueRecoveryV2);
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException {
|
||||
if (account.isRegistered()
|
||||
&& account.getServiceEnvironment() != null
|
||||
&& account.getServiceEnvironment() != serviceEnvironmentConfig.getType()) {
|
||||
&& account.getServiceEnvironment() != serviceEnvironmentConfig.type()) {
|
||||
throw new IOException("Account is registered in another environment: " + account.getServiceEnvironment());
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
|
||||
private boolean attemptReactivateAccount() {
|
||||
try {
|
||||
final var accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||
final var accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
account.getCredentialsProvider(),
|
||||
userAgent,
|
||||
null,
|
||||
|
|
|
@ -94,7 +94,7 @@ public class SignalDependencies {
|
|||
|
||||
public SignalServiceAccountManager getAccountManager() {
|
||||
return getOrCreate(() -> accountManager,
|
||||
() -> accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||
() -> accountManager = new SignalServiceAccountManager(serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
credentialsProvider,
|
||||
userAgent,
|
||||
getGroupsV2Operations(),
|
||||
|
@ -102,7 +102,7 @@ public class SignalDependencies {
|
|||
}
|
||||
|
||||
public SignalServiceAccountManager createUnauthenticatedAccountManager(String number, String password) {
|
||||
return new SignalServiceAccountManager(getServiceEnvironmentConfig().getSignalServiceConfiguration(),
|
||||
return new SignalServiceAccountManager(getServiceEnvironmentConfig().signalServiceConfiguration(),
|
||||
null,
|
||||
null,
|
||||
number,
|
||||
|
@ -119,13 +119,13 @@ public class SignalDependencies {
|
|||
|
||||
public GroupsV2Operations getGroupsV2Operations() {
|
||||
return getOrCreate(() -> groupsV2Operations,
|
||||
() -> groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration()),
|
||||
() -> groupsV2Operations = new GroupsV2Operations(ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()),
|
||||
ServiceConfig.GROUP_MAX_SIZE));
|
||||
}
|
||||
|
||||
private ClientZkOperations getClientZkOperations() {
|
||||
return getOrCreate(() -> clientZkOperations,
|
||||
() -> clientZkOperations = ClientZkOperations.create(serviceEnvironmentConfig.getSignalServiceConfiguration()));
|
||||
() -> clientZkOperations = ClientZkOperations.create(serviceEnvironmentConfig.signalServiceConfiguration()));
|
||||
}
|
||||
|
||||
private ClientZkProfileOperations getClientZkProfileOperations() {
|
||||
|
@ -141,7 +141,7 @@ public class SignalDependencies {
|
|||
@Override
|
||||
public WebSocketConnection createWebSocket() {
|
||||
return new WebSocketConnection("normal",
|
||||
serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||
serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
Optional.of(credentialsProvider),
|
||||
userAgent,
|
||||
healthMonitor,
|
||||
|
@ -151,7 +151,7 @@ public class SignalDependencies {
|
|||
@Override
|
||||
public WebSocketConnection createUnidentifiedWebSocket() {
|
||||
return new WebSocketConnection("unidentified",
|
||||
serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||
serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
Optional.empty(),
|
||||
userAgent,
|
||||
healthMonitor,
|
||||
|
@ -165,7 +165,7 @@ public class SignalDependencies {
|
|||
|
||||
public SignalServiceMessageReceiver getMessageReceiver() {
|
||||
return getOrCreate(() -> messageReceiver,
|
||||
() -> messageReceiver = new SignalServiceMessageReceiver(serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||
() -> messageReceiver = new SignalServiceMessageReceiver(serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
credentialsProvider,
|
||||
userAgent,
|
||||
getClientZkProfileOperations(),
|
||||
|
@ -174,7 +174,7 @@ public class SignalDependencies {
|
|||
|
||||
public SignalServiceMessageSender getMessageSender() {
|
||||
return getOrCreate(() -> messageSender,
|
||||
() -> messageSender = new SignalServiceMessageSender(serviceEnvironmentConfig.getSignalServiceConfiguration(),
|
||||
() -> messageSender = new SignalServiceMessageSender(serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
credentialsProvider,
|
||||
dataStore,
|
||||
sessionLock,
|
||||
|
@ -190,24 +190,24 @@ public class SignalDependencies {
|
|||
public KeyBackupService getKeyBackupService() {
|
||||
return getOrCreate(() -> keyBackupService,
|
||||
() -> keyBackupService = getAccountManager().getKeyBackupService(ServiceConfig.getIasKeyStore(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getEnclaveName(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getServiceId(),
|
||||
serviceEnvironmentConfig.getKeyBackupConfig().getMrenclave(),
|
||||
serviceEnvironmentConfig.keyBackupConfig().enclaveName(),
|
||||
serviceEnvironmentConfig.keyBackupConfig().serviceId(),
|
||||
serviceEnvironmentConfig.keyBackupConfig().mrenclave(),
|
||||
10));
|
||||
}
|
||||
|
||||
public SecureValueRecoveryV2 getSecureValueRecoveryV2() {
|
||||
return getOrCreate(() -> secureValueRecoveryV2,
|
||||
() -> secureValueRecoveryV2 = getAccountManager().getSecureValueRecoveryV2(serviceEnvironmentConfig.getSvr2Mrenclave()));
|
||||
() -> secureValueRecoveryV2 = getAccountManager().getSecureValueRecoveryV2(serviceEnvironmentConfig.svr2Mrenclave()));
|
||||
}
|
||||
|
||||
public Collection<KeyBackupService> getFallbackKeyBackupServices() {
|
||||
return serviceEnvironmentConfig.getFallbackKeyBackupConfigs()
|
||||
return serviceEnvironmentConfig.fallbackKeyBackupConfigs()
|
||||
.stream()
|
||||
.map(config -> getAccountManager().getKeyBackupService(ServiceConfig.getIasKeyStore(),
|
||||
config.getEnclaveName(),
|
||||
config.getServiceId(),
|
||||
config.getMrenclave(),
|
||||
config.enclaveName(),
|
||||
config.serviceId(),
|
||||
config.mrenclave(),
|
||||
10))
|
||||
.toList();
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ public class SignalDependencies {
|
|||
|
||||
public SignalServiceCipher getCipher() {
|
||||
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 deviceId = credentialsProvider.getDeviceId();
|
||||
cipher = new SignalServiceCipher(address, deviceId, dataStore.aci(), sessionLock, certificateValidator);
|
||||
|
|
|
@ -881,10 +881,10 @@ public class SignalAccount implements Closeable {
|
|||
var profileStoreNode = rootNode.get("profileStore");
|
||||
final var legacyProfileStore = jsonProcessor.convertValue(profileStoreNode, LegacyProfileStore.class);
|
||||
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
|
||||
getProfileStore().storeProfileKey(recipientId, profileEntry.getProfileKey());
|
||||
final var profile = profileEntry.getProfile();
|
||||
getProfileStore().storeProfileKey(recipientId, profileEntry.profileKey());
|
||||
final var profile = profileEntry.profile();
|
||||
if (profile != null) {
|
||||
final var capabilities = new HashSet<Profile.Capability>();
|
||||
if (profile.getCapabilities() != null) {
|
||||
|
@ -895,7 +895,7 @@ public class SignalAccount implements Closeable {
|
|||
capabilities.add(Profile.Capability.storage);
|
||||
}
|
||||
}
|
||||
final var newProfile = new Profile(profileEntry.getLastUpdateTimestamp(),
|
||||
final var newProfile = new Profile(profileEntry.lastUpdateTimestamp(),
|
||||
profile.getGivenName(),
|
||||
profile.getFamilyName(),
|
||||
profile.getAbout(),
|
||||
|
|
|
@ -3,41 +3,6 @@ package org.asamk.signal.manager.storage.profiles;
|
|||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||
import org.signal.libsignal.zkgroup.profiles.ProfileKey;
|
||||
|
||||
public class LegacySignalProfileEntry {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
public record LegacySignalProfileEntry(
|
||||
RecipientAddress address, ProfileKey profileKey, long lastUpdateTimestamp, LegacySignalProfile profile
|
||||
) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue