X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/4f2261e86f493a9c8954c02c52ddaa9a46490d20..0624d6a808b8b2a247aadd96450319bc94e3729f:/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java diff --git a/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java b/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java index f775cc1c..60c47d8b 100644 --- a/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java +++ b/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java @@ -4,8 +4,6 @@ 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.InvalidCiphertextException; -import org.whispersystems.signalservice.api.crypto.ProfileCipher; import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess; import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair; import org.whispersystems.signalservice.api.profiles.ProfileAndCredential; @@ -15,7 +13,6 @@ import org.whispersystems.signalservice.api.push.exceptions.NotFoundException; import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException; import org.whispersystems.signalservice.internal.util.concurrent.CascadingFuture; import org.whispersystems.signalservice.internal.util.concurrent.ListenableFuture; -import org.whispersystems.util.Base64; import java.io.IOException; import java.util.Arrays; @@ -46,8 +43,7 @@ public final class ProfileHelper { } public ProfileAndCredential retrieveProfileSync( - SignalServiceAddress recipient, - SignalServiceProfile.RequestType requestType + SignalServiceAddress recipient, SignalServiceProfile.RequestType requestType ) throws IOException { try { return retrieveProfile(recipient, requestType).get(10, TimeUnit.SECONDS); @@ -65,37 +61,29 @@ public final class ProfileHelper { } public ListenableFuture retrieveProfile( - SignalServiceAddress address, - SignalServiceProfile.RequestType requestType + SignalServiceAddress address, SignalServiceProfile.RequestType requestType ) { Optional unidentifiedAccess = getUnidentifiedAccess(address); Optional profileKey = Optional.fromNullable(profileKeyProvider.getProfileKey(address)); if (unidentifiedAccess.isPresent()) { - return new CascadingFuture<>(Arrays.asList(() -> getPipeRetrievalFuture(address, profileKey, unidentifiedAccess, requestType), + return new CascadingFuture<>(Arrays.asList(() -> getPipeRetrievalFuture(address, + profileKey, + unidentifiedAccess, + requestType), () -> getSocketRetrievalFuture(address, profileKey, unidentifiedAccess, requestType), () -> getPipeRetrievalFuture(address, profileKey, Optional.absent(), requestType), () -> getSocketRetrievalFuture(address, profileKey, Optional.absent(), requestType)), e -> !(e instanceof NotFoundException)); } else { - return new CascadingFuture<>(Arrays.asList(() -> getPipeRetrievalFuture(address, profileKey, Optional.absent(), requestType), - () -> getSocketRetrievalFuture(address, profileKey, Optional.absent(), requestType)), + return new CascadingFuture<>(Arrays.asList(() -> getPipeRetrievalFuture(address, + profileKey, + Optional.absent(), + requestType), () -> getSocketRetrievalFuture(address, profileKey, Optional.absent(), requestType)), e -> !(e instanceof NotFoundException)); } } - public String decryptName( - ProfileKey profileKey, - String encryptedName - ) throws InvalidCiphertextException, IOException { - if (encryptedName == null) { - return null; - } - - ProfileCipher profileCipher = new ProfileCipher(profileKey); - return new String(profileCipher.decryptName(Base64.decode(encryptedName))); - } - private ListenableFuture getPipeRetrievalFuture( SignalServiceAddress address, Optional profileKey, @@ -107,7 +95,17 @@ public final class ProfileHelper { ? unidentifiedPipe : messagePipeProvider.getMessagePipe(false); if (pipe != null) { - return pipe.getProfile(address, profileKey, unidentifiedAccess, requestType); + try { + return pipe.getProfile(address, profileKey, unidentifiedAccess, requestType); + } catch (NoClassDefFoundError e) { + // Native zkgroup lib not available for ProfileKey + if (!address.getNumber().isPresent()) { + throw new NotFoundException("Can't request profile without number"); + } + SignalServiceAddress addressWithoutUuid = new SignalServiceAddress(Optional.absent(), + address.getNumber()); + return pipe.getProfile(addressWithoutUuid, profileKey, unidentifiedAccess, requestType); + } } throw new IOException("No pipe available!"); @@ -118,9 +116,18 @@ public final class ProfileHelper { Optional profileKey, Optional unidentifiedAccess, SignalServiceProfile.RequestType requestType - ) { + ) throws NotFoundException { SignalServiceMessageReceiver receiver = messageReceiverProvider.getMessageReceiver(); - return receiver.retrieveProfile(address, profileKey, unidentifiedAccess, requestType); + try { + return receiver.retrieveProfile(address, profileKey, unidentifiedAccess, requestType); + } catch (NoClassDefFoundError e) { + // Native zkgroup lib not available for ProfileKey + if (!address.getNumber().isPresent()) { + throw new NotFoundException("Can't request profile without number"); + } + SignalServiceAddress addressWithoutUuid = new SignalServiceAddress(Optional.absent(), address.getNumber()); + return receiver.retrieveProfile(addressWithoutUuid, profileKey, unidentifiedAccess, requestType); + } } private Optional getUnidentifiedAccess(SignalServiceAddress recipient) {