use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class SignalServiceContent method createGroupV2Info.
private static SignalServiceGroupV2 createGroupV2Info(SignalServiceProtos.DataMessage content) throws InvalidMessageStructureException {
if (!content.hasGroupV2())
return null;
SignalServiceProtos.GroupContextV2 groupV2 = content.getGroupV2();
if (!groupV2.hasMasterKey()) {
throw new InvalidMessageStructureException("No GV2 master key on message");
}
if (!groupV2.hasRevision()) {
throw new InvalidMessageStructureException("No GV2 revision on message");
}
SignalServiceGroupV2.Builder builder;
try {
builder = SignalServiceGroupV2.newBuilder(new GroupMasterKey(groupV2.getMasterKey().toByteArray())).withRevision(groupV2.getRevision());
} catch (InvalidInputException e) {
throw new InvalidMessageStructureException("Invalid GV2 input!");
}
if (groupV2.hasGroupChange() && !groupV2.getGroupChange().isEmpty()) {
builder.withSignedGroupChange(groupV2.getGroupChange().toByteArray());
}
return builder.build();
}
use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class SignalServiceGroupV2 method fromProtobuf.
/**
* Creates a context model populated from a protobuf group V2 context.
*/
public static SignalServiceGroupV2 fromProtobuf(SignalServiceProtos.GroupContextV2 groupContextV2) {
GroupMasterKey masterKey;
try {
masterKey = new GroupMasterKey(groupContextV2.getMasterKey().toByteArray());
} catch (InvalidInputException e) {
throw new AssertionError(e);
}
Builder builder = newBuilder(masterKey);
if (groupContextV2.hasGroupChange() && !groupContextV2.getGroupChange().isEmpty()) {
builder.withSignedGroupChange(groupContextV2.getGroupChange().toByteArray());
}
return builder.withRevision(groupContextV2.getRevision()).build();
}
use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class GroupInviteLinkUrl method fromUri.
/**
* @return null iff not a group url.
* @throws InvalidGroupLinkException If group url, but cannot be parsed.
*/
@Nullable
public static GroupInviteLinkUrl fromUri(@NonNull String urlString) throws InvalidGroupLinkException, UnknownGroupLinkVersionException {
URI uri = getGroupUrl(urlString);
if (uri == null) {
return null;
}
try {
if (!"/".equals(uri.getPath()) && uri.getPath().length() > 0) {
throw new InvalidGroupLinkException("No path was expected in uri");
}
String encoding = uri.getFragment();
if (encoding == null || encoding.length() == 0) {
throw new InvalidGroupLinkException("No reference was in the uri");
}
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 (InvalidInputException | IOException e) {
throw new InvalidGroupLinkException(e);
}
}
use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class PendingMemberInvitesRepository method getInvitees.
public void getInvitees(@NonNull Consumer<InviteeResult> onInviteesLoaded) {
executor.execute(() -> {
GroupDatabase groupDatabase = SignalDatabase.groups();
GroupDatabase.V2GroupProperties v2GroupProperties = groupDatabase.getGroup(groupId).get().requireV2GroupProperties();
DecryptedGroup decryptedGroup = v2GroupProperties.getDecryptedGroup();
List<DecryptedPendingMember> pendingMembersList = decryptedGroup.getPendingMembersList();
List<SinglePendingMemberInvitedByYou> byMe = new ArrayList<>(pendingMembersList.size());
List<MultiplePendingMembersInvitedByAnother> byOthers = new ArrayList<>(pendingMembersList.size());
ByteString self = Recipient.self().requireServiceId().toByteString();
boolean selfIsAdmin = v2GroupProperties.isAdmin(Recipient.self());
Stream.of(pendingMembersList).groupBy(DecryptedPendingMember::getAddedByUuid).forEach(g -> {
ByteString inviterUuid = g.getKey();
List<DecryptedPendingMember> invitedMembers = g.getValue();
if (self.equals(inviterUuid)) {
for (DecryptedPendingMember pendingMember : invitedMembers) {
try {
Recipient invitee = GroupProtoUtil.pendingMemberToRecipient(context, pendingMember);
UuidCiphertext uuidCipherText = new UuidCiphertext(pendingMember.getUuidCipherText().toByteArray());
byMe.add(new SinglePendingMemberInvitedByYou(invitee, uuidCipherText));
} catch (InvalidInputException e) {
Log.w(TAG, e);
}
}
} else {
Recipient inviter = GroupProtoUtil.uuidByteStringToRecipient(context, inviterUuid);
ArrayList<UuidCiphertext> uuidCipherTexts = new ArrayList<>(invitedMembers.size());
for (DecryptedPendingMember pendingMember : invitedMembers) {
try {
uuidCipherTexts.add(new UuidCiphertext(pendingMember.getUuidCipherText().toByteArray()));
} catch (InvalidInputException e) {
Log.w(TAG, e);
}
}
byOthers.add(new MultiplePendingMembersInvitedByAnother(inviter, uuidCipherTexts));
}
});
onInviteesLoaded.accept(new InviteeResult(byMe, byOthers, selfIsAdmin));
});
}
Aggregations