mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Handle GV2 addresses.
This commit is contained in:
committed by
Greyson Parrelli
parent
06eadd0c15
commit
e4456bb236
@@ -0,0 +1,55 @@
|
||||
package org.thoughtcrime.securesms.groups.ui.invitesandrequests.joining;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.BottomSheetUtil;
|
||||
import org.thoughtcrime.securesms.util.PlayStoreUtil;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
|
||||
public final class GroupJoinUpdateRequiredBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public static void show(@NonNull FragmentManager manager) {
|
||||
new GroupJoinUpdateRequiredBottomSheetDialogFragment().show(manager, BottomSheetUtil.STANDARD_BOTTOM_SHEET_FRAGMENT_TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
setStyle(DialogFragment.STYLE_NORMAL,
|
||||
ThemeUtil.isDarkTheme(requireContext()) ? R.style.Theme_Signal_RoundedBottomSheet
|
||||
: R.style.Theme_Signal_RoundedBottomSheet_Light);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.group_join_update_needed_bottom_sheet, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
view.findViewById(R.id.group_join_update_button)
|
||||
.setOnClickListener(v -> {
|
||||
PlayStoreUtil.openPlayStoreOrOurApkDownloadPage(requireContext());
|
||||
dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(@NonNull FragmentManager manager, @Nullable String tag) {
|
||||
BottomSheetUtil.show(manager, tag, this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package org.thoughtcrime.securesms.groups.v2;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import org.signal.storageservice.protos.groups.GroupInviteLink;
|
||||
import org.signal.zkgroup.InvalidInputException;
|
||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||
import org.thoughtcrime.securesms.util.Base64UrlSafe;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public final class GroupInviteLinkUrl {
|
||||
|
||||
private static final String GROUP_URL_HOST = "group.signal.org";
|
||||
private static final String GROUP_URL_PREFIX = "https://" + GROUP_URL_HOST + "/#";
|
||||
|
||||
private final GroupMasterKey groupMasterKey;
|
||||
private final GroupLinkPassword password;
|
||||
private final String url;
|
||||
|
||||
public static @Nullable GroupInviteLinkUrl fromUrl(@NonNull String urlString)
|
||||
throws InvalidGroupLinkException, UnknownGroupLinkVersionException
|
||||
{
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(urlString);
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!GROUP_URL_HOST.equalsIgnoreCase(url.getHost())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!"/".equals(url.getPath()) && url.getPath().length() > 0) {
|
||||
throw new InvalidGroupLinkException("No path was expected in url");
|
||||
}
|
||||
|
||||
String encoding = url.getRef();
|
||||
|
||||
if (encoding == null || encoding.length() == 0) {
|
||||
throw new InvalidGroupLinkException("No reference was in the url");
|
||||
}
|
||||
|
||||
byte[] bytes = Base64UrlSafe.decodePaddingAgnostic(encoding);
|
||||
GroupInviteLink groupInviteLink = GroupInviteLink.parseFrom(bytes);
|
||||
|
||||
//noinspection SwitchStatementWithTooFewBranches
|
||||
switch (groupInviteLink.getContentsCase()) {
|
||||
case V1CONTENTS: {
|
||||
GroupInviteLink.GroupInviteLinkContentsV1 groupInviteLinkContentsV1 = groupInviteLink.getV1Contents();
|
||||
GroupMasterKey groupMasterKey = new GroupMasterKey(groupInviteLinkContentsV1.getGroupMasterKey().toByteArray());
|
||||
GroupLinkPassword password = GroupLinkPassword.fromBytes(groupInviteLinkContentsV1.getInviteLinkPassword().toByteArray());
|
||||
|
||||
return new GroupInviteLinkUrl(groupMasterKey, password);
|
||||
}
|
||||
default: throw new UnknownGroupLinkVersionException("Url contains no known group link content");
|
||||
}
|
||||
} catch (GroupLinkPassword.InvalidLengthException | InvalidInputException | IOException e){
|
||||
throw new InvalidGroupLinkException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private GroupInviteLinkUrl(@NonNull GroupMasterKey groupMasterKey, @NonNull GroupLinkPassword password) {
|
||||
this.groupMasterKey = groupMasterKey;
|
||||
this.password = password;
|
||||
this.url = createUrl(groupMasterKey, password);
|
||||
}
|
||||
|
||||
protected static @NonNull String createUrl(@NonNull GroupMasterKey groupMasterKey, @NonNull GroupLinkPassword password) {
|
||||
GroupInviteLink groupInviteLink = GroupInviteLink.newBuilder()
|
||||
.setV1Contents(GroupInviteLink.GroupInviteLinkContentsV1.newBuilder()
|
||||
.setGroupMasterKey(ByteString.copyFrom(groupMasterKey.serialize()))
|
||||
.setInviteLinkPassword(ByteString.copyFrom(password.serialize())))
|
||||
.build();
|
||||
|
||||
String encoding = Base64UrlSafe.encodeBytesWithoutPadding(groupInviteLink.toByteArray());
|
||||
|
||||
return GROUP_URL_PREFIX + encoding;
|
||||
}
|
||||
|
||||
public @NonNull String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public @NonNull GroupMasterKey getGroupMasterKey() {
|
||||
return groupMasterKey;
|
||||
}
|
||||
|
||||
public @NonNull GroupLinkPassword getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public final static class InvalidGroupLinkException extends Exception {
|
||||
public InvalidGroupLinkException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidGroupLinkException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
public final static class UnknownGroupLinkVersionException extends Exception {
|
||||
public UnknownGroupLinkVersionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.thoughtcrime.securesms.groups.v2;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class GroupLinkPassword {
|
||||
|
||||
private static final int SIZE = 16;
|
||||
|
||||
private final byte[] bytes;
|
||||
|
||||
public static @NonNull GroupLinkPassword createNew() {
|
||||
return new GroupLinkPassword(Util.getSecretBytes(SIZE));
|
||||
}
|
||||
|
||||
public static @NonNull GroupLinkPassword fromBytes(@NonNull byte[] bytes) throws InvalidLengthException {
|
||||
if (bytes.length != SIZE) {
|
||||
throw new InvalidLengthException();
|
||||
}
|
||||
|
||||
return new GroupLinkPassword(bytes);
|
||||
}
|
||||
|
||||
private GroupLinkPassword(@NonNull byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public @NonNull byte[] serialize() {
|
||||
return bytes.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof GroupLinkPassword)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Arrays.equals(bytes, ((GroupLinkPassword) other).bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(bytes);
|
||||
}
|
||||
|
||||
public static class InvalidLengthException extends Exception {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user