0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-20 20:03:07 +02:00

Merge pull request #321 from signalapp/jrose/java-sealed-sender-group-id-on-success

Java: include the sealed sender groupId on sucessful decryption
This commit is contained in:
Jordan Rose 2021-06-02 10:45:56 -07:00 committed by GitHub
commit 6259292b20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -140,6 +140,7 @@ public class SealedSessionCipher {
return new DecryptionResult(content.getSenderCertificate().getSenderUuid(),
content.getSenderCertificate().getSenderE164(),
content.getSenderCertificate().getSenderDeviceId(),
content.getGroupId(),
decrypt(content));
} catch (InvalidMessageException e) {
throw new ProtocolInvalidMessageException(e, content);
@ -191,12 +192,14 @@ public class SealedSessionCipher {
private final String senderUuid;
private final Optional<String> senderE164;
private final int deviceId;
private final Optional<byte[]> groupId;
private final byte[] paddedMessage;
private DecryptionResult(String senderUuid, Optional<String> senderE164, int deviceId, byte[] paddedMessage) {
private DecryptionResult(String senderUuid, Optional<String> senderE164, int deviceId, Optional<byte[]> groupId, byte[] paddedMessage) {
this.senderUuid = senderUuid;
this.senderE164 = senderE164;
this.deviceId = deviceId;
this.groupId = groupId;
this.paddedMessage = paddedMessage;
}
@ -215,5 +218,9 @@ public class SealedSessionCipher {
public byte[] getPaddedMessage() {
return paddedMessage;
}
public Optional<byte[]> getGroupId() {
return groupId;
}
}
}

View File

@ -174,7 +174,7 @@ public class SealedSessionCipherTest extends TestCase {
CiphertextMessage ciphertextFromAlice = aliceGroupCipher.encrypt(distributionId, "smert ze smert".getBytes());
UnidentifiedSenderMessageContent usmcFromAlice = new UnidentifiedSenderMessageContent(ciphertextFromAlice, senderCertificate, UnidentifiedSenderMessageContent.CONTENT_HINT_IMPLICIT, Optional.of(new byte[]{42}));
UnidentifiedSenderMessageContent usmcFromAlice = new UnidentifiedSenderMessageContent(ciphertextFromAlice, senderCertificate, UnidentifiedSenderMessageContent.CONTENT_HINT_IMPLICIT, Optional.of(new byte[]{42, 43}));
byte[] aliceMessage = aliceCipher.multiRecipientEncrypt(Arrays.asList(bobAddress), usmcFromAlice);
byte[] bobMessage = SealedSessionCipher.multiRecipientMessageForSingleRecipient(aliceMessage);
@ -185,6 +185,7 @@ public class SealedSessionCipherTest extends TestCase {
assertEquals(plaintext.getSenderUuid(), "9d0652a3-dcc3-4d11-975f-74d61598733f");
assertEquals(plaintext.getSenderE164().get(), "+14151111111");
assertEquals(plaintext.getDeviceId(), 1);
assertTrue(Arrays.equals(plaintext.getGroupId().get(), new byte[]{42, 43}));
}
public void testProtocolException() throws UntrustedIdentityException, InvalidKeyException, InvalidCertificateException, InvalidMessageException, InvalidMetadataMessageException, LegacyMessageException, NoSessionException, ProtocolDuplicateMessageException, ProtocolUntrustedIdentityException, ProtocolLegacyMessageException, ProtocolInvalidKeyException, InvalidMetadataVersionException, ProtocolInvalidVersionException, ProtocolInvalidMessageException, ProtocolInvalidKeyIdException, ProtocolNoSessionException, SelfSendException {