Accept any length group link password.
parent
878b0c9275
commit
ffcb90da52
|
@ -26,7 +26,6 @@ public final class GroupInviteLinkUrl {
|
||||||
|
|
||||||
public static GroupInviteLinkUrl forGroup(@NonNull GroupMasterKey groupMasterKey,
|
public static GroupInviteLinkUrl forGroup(@NonNull GroupMasterKey groupMasterKey,
|
||||||
@NonNull DecryptedGroup group)
|
@NonNull DecryptedGroup group)
|
||||||
throws GroupLinkPassword.InvalidLengthException
|
|
||||||
{
|
{
|
||||||
return new GroupInviteLinkUrl(groupMasterKey, GroupLinkPassword.fromBytes(group.getInviteLinkPassword().toByteArray()));
|
return new GroupInviteLinkUrl(groupMasterKey, GroupLinkPassword.fromBytes(group.getInviteLinkPassword().toByteArray()));
|
||||||
}
|
}
|
||||||
|
@ -73,7 +72,7 @@ public final class GroupInviteLinkUrl {
|
||||||
}
|
}
|
||||||
default: throw new UnknownGroupLinkVersionException("Url contains no known group link content");
|
default: throw new UnknownGroupLinkVersionException("Url contains no known group link content");
|
||||||
}
|
}
|
||||||
} catch (GroupLinkPassword.InvalidLengthException | InvalidInputException | IOException e){
|
} catch (InvalidInputException | IOException e) {
|
||||||
throw new InvalidGroupLinkException(e);
|
throw new InvalidGroupLinkException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,7 @@ public final class GroupLinkPassword {
|
||||||
return new GroupLinkPassword(Util.getSecretBytes(SIZE));
|
return new GroupLinkPassword(Util.getSecretBytes(SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NonNull GroupLinkPassword fromBytes(@NonNull byte[] bytes) throws InvalidLengthException {
|
public static @NonNull GroupLinkPassword fromBytes(@NonNull byte[] bytes) {
|
||||||
if (bytes.length != SIZE) {
|
|
||||||
throw new InvalidLengthException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new GroupLinkPassword(bytes);
|
return new GroupLinkPassword(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +41,4 @@ public final class GroupLinkPassword {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Arrays.hashCode(bytes);
|
return Arrays.hashCode(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class InvalidLengthException extends Exception {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,11 @@ public final class GroupInviteLinkUrlTest {
|
||||||
|
|
||||||
givenGroup().withMasterKey("00f7e0c2a71ab064cc3ced4c04f08d7b7ef4b84b2c2206f69833be6cfe34df80")
|
givenGroup().withMasterKey("00f7e0c2a71ab064cc3ced4c04f08d7b7ef4b84b2c2206f69833be6cfe34df80")
|
||||||
.andPassword("9bc324eec437cfda6ae5b8aefbf47ee8")
|
.andPassword("9bc324eec437cfda6ae5b8aefbf47ee8")
|
||||||
.expectUrl("https://signal.group/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o")
|
.expectUrl("https://signal.group/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o"),
|
||||||
|
|
||||||
|
givenGroup().withMasterKey("00f7e0c2a71ab064cc3ced4c04f08d7b7ef4b84b2c2206f69833be6cfe34df80")
|
||||||
|
.andPassword("9b")
|
||||||
|
.expectUrl("https://signal.group/#CiUKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEgGb")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +95,7 @@ public final class GroupInviteLinkUrlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] expectUrl(String url) {
|
public Object[] expectUrl(String url) {
|
||||||
try {
|
return new Object[]{ groupMasterKey, GroupLinkPassword.fromBytes(passwordBytes), url };
|
||||||
return new Object[]{ groupMasterKey, GroupLinkPassword.fromBytes(passwordBytes), url };
|
|
||||||
} catch (GroupLinkPassword.InvalidLengthException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -92,20 +92,6 @@ public final class GroupInviteLinkUrl_InvalidGroupLinkException_Test {
|
||||||
.hasCauseExactlyInstanceOf(InvalidInputException.class);
|
.hasCauseExactlyInstanceOf(InvalidInputException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void bad_password_length() throws InvalidInputException {
|
|
||||||
GroupMasterKey groupMasterKey = new GroupMasterKey(Util.getSecretBytes(32));
|
|
||||||
byte[] passwordBytes = Util.getSecretBytes(15);
|
|
||||||
|
|
||||||
String encoding = createEncodedProtobuf(groupMasterKey.serialize(), passwordBytes);
|
|
||||||
|
|
||||||
String url = "https://signal.group/#" + encoding;
|
|
||||||
|
|
||||||
assertThatThrownBy(() -> GroupInviteLinkUrl.fromUrl(url))
|
|
||||||
.isInstanceOf(GroupInviteLinkUrl.InvalidGroupLinkException.class)
|
|
||||||
.hasCauseExactlyInstanceOf(GroupLinkPassword.InvalidLengthException.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String createEncodedProtobuf(@NonNull byte[] groupMasterKey,
|
private static String createEncodedProtobuf(@NonNull byte[] groupMasterKey,
|
||||||
@NonNull byte[] passwordBytes)
|
@NonNull byte[] passwordBytes)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue