Update handling of unrestricted unidentified sender access.

Fixes #843
This commit is contained in:
AsamK 2021-12-25 16:06:12 +01:00
parent 88ea61e28f
commit f03df0a8c0

View file

@ -3,6 +3,7 @@ package org.asamk.signal.manager.helper;
import org.asamk.signal.manager.SignalDependencies; import org.asamk.signal.manager.SignalDependencies;
import org.asamk.signal.manager.api.PhoneNumberSharingMode; import org.asamk.signal.manager.api.PhoneNumberSharingMode;
import org.asamk.signal.manager.storage.SignalAccount; import org.asamk.signal.manager.storage.SignalAccount;
import org.asamk.signal.manager.storage.recipients.Profile;
import org.asamk.signal.manager.storage.recipients.RecipientId; import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.signal.libsignal.metadata.certificate.InvalidCertificateException; import org.signal.libsignal.metadata.certificate.InvalidCertificateException;
import org.signal.libsignal.metadata.certificate.SenderCertificate; import org.signal.libsignal.metadata.certificate.SenderCertificate;
@ -16,12 +17,11 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.whispersystems.signalservice.internal.util.Util.getSecretBytes;
public class UnidentifiedAccessHelper { public class UnidentifiedAccessHelper {
private final static Logger logger = LoggerFactory.getLogger(UnidentifiedAccessHelper.class); private final static Logger logger = LoggerFactory.getLogger(UnidentifiedAccessHelper.class);
private final static long CERTIFICATE_EXPIRATION_BUFFER = TimeUnit.DAYS.toMillis(1); private final static long CERTIFICATE_EXPIRATION_BUFFER = TimeUnit.DAYS.toMillis(1);
private static final byte[] UNRESTRICTED_KEY = new byte[16];
private final SignalAccount account; private final SignalAccount account;
private final SignalDependencies dependencies; private final SignalDependencies dependencies;
@ -90,6 +90,11 @@ public class UnidentifiedAccessHelper {
} }
private byte[] getSelfUnidentifiedAccessKey() { private byte[] getSelfUnidentifiedAccessKey() {
var selfProfile = profileProvider.getProfile(account.getSelfRecipientId());
if (selfProfile != null
&& selfProfile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED) {
return createUnrestrictedUnidentifiedAccess();
}
return UnidentifiedAccess.deriveAccessKeyFrom(selfProfileKeyProvider.getProfileKey()); return UnidentifiedAccess.deriveAccessKeyFrom(selfProfileKeyProvider.getProfileKey());
} }
@ -156,6 +161,6 @@ public class UnidentifiedAccessHelper {
} }
private static byte[] createUnrestrictedUnidentifiedAccess() { private static byte[] createUnrestrictedUnidentifiedAccess() {
return getSecretBytes(16); return UNRESTRICTED_KEY;
} }
} }