use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class ProfileKeySet method addMemberKey.
private void addMemberKey(@Nullable UUID changeSource, @NonNull ByteString memberUuidBytes, @NonNull ByteString profileKeyBytes) {
UUID memberUuid = UuidUtil.fromByteString(memberUuidBytes);
if (UuidUtil.UNKNOWN_UUID.equals(memberUuid)) {
Log.w(TAG, "Seen unknown member UUID");
return;
}
ProfileKey profileKey;
try {
profileKey = new ProfileKey(profileKeyBytes.toByteArray());
} catch (InvalidInputException e) {
Log.w(TAG, "Bad profile key in group");
return;
}
if (memberUuid.equals(changeSource)) {
authoritativeProfileKeys.put(ACI.from(memberUuid), profileKey);
profileKeys.remove(ACI.from(memberUuid));
} else {
if (!authoritativeProfileKeys.containsKey(ACI.from(memberUuid))) {
profileKeys.put(ACI.from(memberUuid), profileKey);
}
}
}
use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class SubscriptionReceiptRequestResponseJob method generateRequestContext.
private static ReceiptCredentialRequestContext generateRequestContext() {
Log.d(TAG, "Generating request credentials context for token redemption...", true);
SecureRandom secureRandom = new SecureRandom();
byte[] randomBytes = Util.getSecretBytes(ReceiptSerial.SIZE);
try {
ReceiptSerial receiptSerial = new ReceiptSerial(randomBytes);
ClientZkReceiptOperations operations = ApplicationDependencies.getClientZkReceiptOperations();
return operations.createReceiptCredentialRequestContext(secureRandom, receiptSerial);
} catch (InvalidInputException | VerificationFailedException e) {
Log.e(TAG, "Failed to create credential.", e);
throw new AssertionError(e);
}
}
use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class SignalCallManager method onSendCallMessageToGroup.
@Override
public void onSendCallMessageToGroup(@NonNull byte[] groupIdBytes, @NonNull byte[] message, @NonNull CallManager.CallMessageUrgency urgency) {
Log.i(TAG, "onSendCallMessageToGroup():");
networkExecutor.execute(() -> {
try {
GroupId groupId = GroupId.v2(new GroupIdentifier(groupIdBytes));
List<Recipient> recipients = SignalDatabase.groups().getGroupMembers(groupId, GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
recipients = RecipientUtil.getEligibleForSending((recipients.stream().map(Recipient::resolve).filter(r -> !r.isBlocked()).collect(Collectors.toList())));
OpaqueMessage opaqueMessage = new OpaqueMessage(message, getUrgencyFromCallUrgency(urgency));
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOutgoingGroupOpaque(groupId.getDecodedId(), System.currentTimeMillis(), opaqueMessage, true, null);
RecipientAccessList accessList = new RecipientAccessList(recipients);
List<SendMessageResult> results = GroupSendUtil.sendCallMessage(context, groupId.requireV2(), recipients, callMessage);
Set<RecipientId> identifyFailureRecipientIds = results.stream().filter(result -> result.getIdentityFailure() != null).map(result -> accessList.requireIdByAddress(result.getAddress())).collect(Collectors.toSet());
if (Util.hasItems(identifyFailureRecipientIds)) {
process((s, p) -> p.handleGroupMessageSentError(s, identifyFailureRecipientIds, UNTRUSTED_IDENTITY));
RetrieveProfileJob.enqueue(identifyFailureRecipientIds);
}
} catch (UntrustedIdentityException | IOException | InvalidInputException e) {
Log.w(TAG, "onSendCallMessageToGroup failed", e);
}
});
}
use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class GroupsV2Api method parseCredentialResponse.
private static HashMap<Integer, AuthCredentialResponse> parseCredentialResponse(CredentialResponse credentialResponse) throws IOException {
HashMap<Integer, AuthCredentialResponse> credentials = new HashMap<>();
for (TemporalCredential credential : credentialResponse.getCredentials()) {
AuthCredentialResponse authCredentialResponse;
try {
authCredentialResponse = new AuthCredentialResponse(credential.getCredential());
} catch (InvalidInputException e) {
throw new IOException(e);
}
credentials.put(credential.getRedemptionTime(), authCredentialResponse);
}
return credentials;
}
use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.
the class DeviceContactsInputStream method read.
public DeviceContact read() throws IOException {
int detailsLength = (int) readRawVarint32();
if (detailsLength == -1) {
return null;
}
byte[] detailsSerialized = new byte[(int) detailsLength];
Util.readFully(in, detailsSerialized);
SignalServiceProtos.ContactDetails details = SignalServiceProtos.ContactDetails.parseFrom(detailsSerialized);
if (!SignalServiceAddress.isValidAddress(details.getUuid(), details.getNumber())) {
throw new IOException("Missing contact address!");
}
SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(details.getUuid()), details.getNumber());
Optional<String> name = Optional.fromNullable(details.getName());
Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
Optional<String> color = details.hasColor() ? Optional.of(details.getColor()) : Optional.<String>absent();
Optional<VerifiedMessage> verified = Optional.absent();
Optional<ProfileKey> profileKey = Optional.absent();
boolean blocked = false;
Optional<Integer> expireTimer = Optional.absent();
Optional<Integer> inboxPosition = Optional.absent();
boolean archived = false;
if (details.hasAvatar()) {
long avatarLength = details.getAvatar().getLength();
InputStream avatarStream = new LimitedInputStream(in, avatarLength);
String avatarContentType = details.getAvatar().getContentType();
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, false, false, null, null));
}
if (details.hasVerified()) {
try {
if (!SignalServiceAddress.isValidAddress(details.getVerified().getDestinationUuid(), details.getVerified().getDestinationE164())) {
throw new InvalidMessageException("Missing Verified address!");
}
IdentityKey identityKey = new IdentityKey(details.getVerified().getIdentityKey().toByteArray(), 0);
SignalServiceAddress destination = new SignalServiceAddress(ACI.parseOrThrow(details.getVerified().getDestinationUuid()), details.getVerified().getDestinationE164());
VerifiedMessage.VerifiedState state;
switch(details.getVerified().getState()) {
case VERIFIED:
state = VerifiedMessage.VerifiedState.VERIFIED;
break;
case UNVERIFIED:
state = VerifiedMessage.VerifiedState.UNVERIFIED;
break;
case DEFAULT:
state = VerifiedMessage.VerifiedState.DEFAULT;
break;
default:
throw new InvalidMessageException("Unknown state: " + details.getVerified().getState());
}
verified = Optional.of(new VerifiedMessage(destination, identityKey, state, System.currentTimeMillis()));
} catch (InvalidKeyException | InvalidMessageException e) {
Log.w(TAG, e);
verified = Optional.absent();
}
}
if (details.hasProfileKey()) {
try {
profileKey = Optional.fromNullable(new ProfileKey(details.getProfileKey().toByteArray()));
} catch (InvalidInputException e) {
Log.w(TAG, "Invalid profile key ignored", e);
}
}
if (details.hasExpireTimer() && details.getExpireTimer() > 0) {
expireTimer = Optional.of(details.getExpireTimer());
}
if (details.hasInboxPosition()) {
inboxPosition = Optional.of(details.getInboxPosition());
}
blocked = details.getBlocked();
archived = details.getArchived();
return new DeviceContact(address, name, avatar, color, verified, profileKey, blocked, expireTimer, inboxPosition, archived);
}
Aggregations