Support sgnl://signal.group links.

This commit is contained in:
Alan Evans
2020-10-07 13:43:53 -03:00
committed by Greyson Parrelli
parent ab2235fc88
commit adf1674877
7 changed files with 65 additions and 36 deletions

View File

@@ -223,6 +223,14 @@
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sgnl"
android:host="signal.group" />
</intent-filter>
<intent-filter android:autoVerify="true"
tools:targetApi="23">
<action android:name="android.intent.action.VIEW" />

View File

@@ -195,7 +195,7 @@ public final class GroupJoinBottomSheetDialogFragment extends BottomSheetDialogF
private GroupInviteLinkUrl getGroupInviteLinkUrl() {
try {
//noinspection ConstantConditions
return GroupInviteLinkUrl.fromUrl(requireArguments().getString(ARG_GROUP_INVITE_LINK_URL));
return GroupInviteLinkUrl.fromUri(requireArguments().getString(ARG_GROUP_INVITE_LINK_URL));
} catch (GroupInviteLinkUrl.InvalidGroupLinkException | GroupInviteLinkUrl.UnknownGroupLinkVersionException e) {
throw new AssertionError();
}

View File

@@ -12,8 +12,8 @@ import org.signal.zkgroup.groups.GroupMasterKey;
import org.whispersystems.util.Base64UrlSafe;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
public final class GroupInviteLinkUrl {
@@ -38,24 +38,24 @@ public final class GroupInviteLinkUrl {
* @return null iff not a group url.
* @throws InvalidGroupLinkException If group url, but cannot be parsed.
*/
public static @Nullable GroupInviteLinkUrl fromUrl(@NonNull String urlString)
public static @Nullable GroupInviteLinkUrl fromUri(@NonNull String urlString)
throws InvalidGroupLinkException, UnknownGroupLinkVersionException
{
URL url = getGroupUrl(urlString);
URI uri = getGroupUrl(urlString);
if (url == null) {
if (uri == null) {
return null;
}
try {
if (!"/".equals(url.getPath()) && url.getPath().length() > 0) {
throw new InvalidGroupLinkException("No path was expected in url");
if (!"/".equals(uri.getPath()) && uri.getPath().length() > 0) {
throw new InvalidGroupLinkException("No path was expected in uri");
}
String encoding = url.getRef();
String encoding = uri.getFragment();
if (encoding == null || encoding.length() == 0) {
throw new InvalidGroupLinkException("No reference was in the url");
throw new InvalidGroupLinkException("No reference was in the uri");
}
byte[] bytes = Base64UrlSafe.decodePaddingAgnostic(encoding);
@@ -78,16 +78,23 @@ public final class GroupInviteLinkUrl {
}
/**
* @return {@link URL} if the host name matches.
* @return {@link URI} if the host name matches.
*/
private static URL getGroupUrl(@NonNull String urlString) {
private static URI getGroupUrl(@NonNull String urlString) {
try {
URL url = new URL(urlString);
URI url = new URI(urlString);
if (!"https".equalsIgnoreCase(url.getScheme()) &&
!"sgnl".equalsIgnoreCase(url.getScheme()))
{
return null;
}
return GROUP_URL_HOST.equalsIgnoreCase(url.getHost())
? url
: null;
} catch (MalformedURLException e) {
} catch (URISyntaxException e) {
return null;
}
}

View File

@@ -252,7 +252,7 @@ public class LinkPreviewRepository {
{
SignalExecutors.UNBOUNDED.execute(() -> {
try {
GroupInviteLinkUrl groupInviteLinkUrl = GroupInviteLinkUrl.fromUrl(groupUrl);
GroupInviteLinkUrl groupInviteLinkUrl = GroupInviteLinkUrl.fromUri(groupUrl);
if (groupInviteLinkUrl == null) {
throw new AssertionError();
}

View File

@@ -165,7 +165,7 @@ public class CommunicationActions {
*/
public static boolean handlePotentialGroupLinkUrl(@NonNull FragmentActivity activity, @NonNull String potentialGroupLinkUrl) {
try {
GroupInviteLinkUrl groupInviteLinkUrl = GroupInviteLinkUrl.fromUrl(potentialGroupLinkUrl);
GroupInviteLinkUrl groupInviteLinkUrl = GroupInviteLinkUrl.fromUri(potentialGroupLinkUrl);
if (groupInviteLinkUrl == null) {
return false;