0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-19 19:42:19 +02:00

java: Mark all bridge_fns that return Result as throws Exception

Then, use FilterExceptions to filter out any exceptions that aren't
declared in the calling method's exception spec. Note that this isn't
perfect: Java's checks for typed exceptions prevents an *extra*
exception from being thrown this way, but it's still possible to
forget to *allow* an exception using FilterExceptions.

This is 99% a mechanical change; the interesting bit is in
gen_java_decl.py and one unusual pattern in NativeErrorsTest.java. No
exception specs were changed here.
This commit is contained in:
Jordan Rose 2024-02-06 18:06:33 -08:00
parent 8cd6f8c68c
commit 4f4d21a8ca
102 changed files with 1362 additions and 738 deletions

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.cds2;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.attest.AttestationDataException;
import org.signal.libsignal.internal.Native;
@ -21,6 +23,11 @@ import org.signal.libsignal.sgxsession.SgxClient;
public class Cds2Client extends SgxClient {
public Cds2Client(byte[] mrenclave, byte[] attestationMsg, Instant currentInstant)
throws AttestationDataException {
super(Native.Cds2ClientState_New(mrenclave, attestationMsg, currentInstant.toEpochMilli()));
super(
filterExceptions(
AttestationDataException.class,
() ->
Native.Cds2ClientState_New(
mrenclave, attestationMsg, currentInstant.toEpochMilli())));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.crypto;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidKeyException;
@ -13,7 +15,9 @@ public class Aes256Ctr32 implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public Aes256Ctr32(byte[] key, byte[] nonce, int initialCtr) throws InvalidKeyException {
this.unsafeHandle = Native.Aes256Ctr32_New(key, nonce, initialCtr);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class, () -> Native.Aes256Ctr32_New(key, nonce, initialCtr));
}
@Override

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.crypto;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidKeyException;
@ -16,7 +18,10 @@ public class Aes256GcmDecryption implements NativeHandleGuard.Owner {
public Aes256GcmDecryption(byte[] key, byte[] nonce, byte[] associatedData)
throws InvalidKeyException {
this.unsafeHandle = Native.Aes256GcmDecryption_New(key, nonce, associatedData);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class,
() -> Native.Aes256GcmDecryption_New(key, nonce, associatedData));
}
@Override
@ -43,7 +48,8 @@ public class Aes256GcmDecryption implements NativeHandleGuard.Owner {
public boolean verifyTag(byte[] tag) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
boolean tagOk = Native.Aes256GcmDecryption_VerifyTag(guard.nativeHandle(), tag);
boolean tagOk =
filterExceptions(() -> Native.Aes256GcmDecryption_VerifyTag(guard.nativeHandle(), tag));
Native.Aes256GcmDecryption_Destroy(guard.nativeHandle());
this.unsafeHandle = 0;
return tagOk;

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.crypto;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidKeyException;
@ -14,7 +16,10 @@ public class Aes256GcmEncryption implements NativeHandleGuard.Owner {
public Aes256GcmEncryption(byte[] key, byte[] nonce, byte[] associatedData)
throws InvalidKeyException {
this.unsafeHandle = Native.Aes256GcmEncryption_New(key, nonce, associatedData);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class,
() -> Native.Aes256GcmEncryption_New(key, nonce, associatedData));
}
@Override

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.crypto;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidKeyException;
@ -14,7 +16,8 @@ class Aes256GcmSiv implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public Aes256GcmSiv(byte[] key) throws InvalidKeyException {
this.unsafeHandle = Native.Aes256GcmSiv_New(key);
this.unsafeHandle =
filterExceptions(InvalidKeyException.class, () -> Native.Aes256GcmSiv_New(key));
}
@Override
@ -29,14 +32,20 @@ class Aes256GcmSiv implements NativeHandleGuard.Owner {
byte[] encrypt(byte[] plaintext, byte[] nonce, byte[] associated_data) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.Aes256GcmSiv_Encrypt(guard.nativeHandle(), plaintext, nonce, associated_data);
return filterExceptions(
() ->
Native.Aes256GcmSiv_Encrypt(guard.nativeHandle(), plaintext, nonce, associated_data));
}
}
byte[] decrypt(byte[] ciphertext, byte[] nonce, byte[] associated_data)
throws InvalidMessageException {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.Aes256GcmSiv_Decrypt(guard.nativeHandle(), ciphertext, nonce, associated_data);
return filterExceptions(
InvalidMessageException.class,
() ->
Native.Aes256GcmSiv_Decrypt(
guard.nativeHandle(), ciphertext, nonce, associated_data));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.crypto;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -12,7 +14,7 @@ public class CryptographicHash implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public CryptographicHash(String algo) {
this.unsafeHandle = Native.CryptographicHash_New(algo);
this.unsafeHandle = filterExceptions(() -> Native.CryptographicHash_New(algo));
}
public long unsafeNativeHandleWithoutGuard() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.crypto;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -12,7 +14,7 @@ public class CryptographicMac implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public CryptographicMac(String algo, byte[] key) {
this.unsafeHandle = Native.CryptographicMac_New(algo, key);
this.unsafeHandle = filterExceptions(() -> Native.CryptographicMac_New(algo, key));
}
@Override

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.devicetransfer;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
public class DeviceTransferKey {
@ -19,6 +21,7 @@ public class DeviceTransferKey {
}
public byte[] generateCertificate(String name, int daysTilExpires) {
return Native.DeviceTransfer_GenerateCertificate(this.keyMaterial, name, daysTilExpires);
return filterExceptions(
() -> Native.DeviceTransfer_GenerateCertificate(this.keyMaterial, name, daysTilExpires));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.hsmenclave;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
@ -43,7 +45,8 @@ public class HsmEnclaveClient implements NativeHandleGuard.Owner {
throw new AssertionError("writing to ByteArrayOutputStream failed", e);
}
}
this.unsafeHandle = Native.HsmEnclaveClient_New(public_key, concatHashes.toByteArray());
this.unsafeHandle =
filterExceptions(() -> Native.HsmEnclaveClient_New(public_key, concatHashes.toByteArray()));
}
@Override
@ -59,7 +62,7 @@ public class HsmEnclaveClient implements NativeHandleGuard.Owner {
/** Initial request to send to HSM enclave, to begin handshake. */
public byte[] initialRequest() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.HsmEnclaveClient_InitialRequest(guard.nativeHandle());
return filterExceptions(() -> Native.HsmEnclaveClient_InitialRequest(guard.nativeHandle()));
}
}
@ -67,7 +70,10 @@ public class HsmEnclaveClient implements NativeHandleGuard.Owner {
public void completeHandshake(byte[] handshakeResponse)
throws EnclaveCommunicationFailureException, TrustedCodeMismatchException {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
Native.HsmEnclaveClient_CompleteHandshake(guard.nativeHandle(), handshakeResponse);
filterExceptions(
EnclaveCommunicationFailureException.class,
TrustedCodeMismatchException.class,
() -> Native.HsmEnclaveClient_CompleteHandshake(guard.nativeHandle(), handshakeResponse));
}
}
@ -75,7 +81,9 @@ public class HsmEnclaveClient implements NativeHandleGuard.Owner {
public byte[] establishedSend(byte[] plaintextToSend)
throws EnclaveCommunicationFailureException {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.HsmEnclaveClient_EstablishedSend(guard.nativeHandle(), plaintextToSend);
return filterExceptions(
EnclaveCommunicationFailureException.class,
() -> Native.HsmEnclaveClient_EstablishedSend(guard.nativeHandle(), plaintextToSend));
}
}
@ -83,7 +91,9 @@ public class HsmEnclaveClient implements NativeHandleGuard.Owner {
public byte[] establishedRecv(byte[] receivedCiphertext)
throws EnclaveCommunicationFailureException {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.HsmEnclaveClient_EstablishedRecv(guard.nativeHandle(), receivedCiphertext);
return filterExceptions(
EnclaveCommunicationFailureException.class,
() -> Native.HsmEnclaveClient_EstablishedRecv(guard.nativeHandle(), receivedCiphertext));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.media;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.io.IOException;
import java.io.InputStream;
import org.signal.libsignal.internal.Native;
@ -58,7 +60,10 @@ public class Mp4Sanitizer {
public static SanitizedMetadata sanitize(InputStream input, long length)
throws IOException, ParseException {
long sanitizedMetadataHandle =
Native.Mp4Sanitizer_Sanitize(TrustedSkipInputStream.makeTrusted(input), length);
filterExceptions(
IOException.class,
ParseException.class,
() -> Native.Mp4Sanitizer_Sanitize(TrustedSkipInputStream.makeTrusted(input), length));
try {
byte[] sanitizedMetadata = Native.SanitizedMetadata_GetMetadata(sanitizedMetadataHandle);
if (sanitizedMetadata.length == 0) {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.media;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.io.IOException;
import java.io.InputStream;
import org.signal.libsignal.internal.Native;
@ -28,7 +30,10 @@ public class WebpSanitizer {
* @throws ParseException If the input could not be parsed.
*/
public static void sanitize(InputStream input) throws IOException, ParseException {
Native.WebpSanitizer_Sanitize(TrustedSkipInputStream.makeTrusted(input));
filterExceptions(
IOException.class,
ParseException.class,
() -> Native.WebpSanitizer_Sanitize(TrustedSkipInputStream.makeTrusted(input)));
}
/**

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.messagebackup;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.io.IOException;
import java.io.InputStream;
import java.util.function.Supplier;
@ -40,8 +42,11 @@ public class MessageBackup {
try (NativeHandleGuard keyGuard = new NativeHandleGuard(key)) {
Object output =
Native.MessageBackupValidator_Validate(
keyGuard.nativeHandle(), first, second, streamLength);
filterExceptions(
IOException.class,
() ->
Native.MessageBackupValidator_Validate(
keyGuard.nativeHandle(), first, second, streamLength));
// Rust conversion code is generating an instance of this class.
@SuppressWarnings("unchecked")

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.metadata;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
@ -61,12 +63,16 @@ public class SealedSessionCipher {
throws InvalidKeyException, UntrustedIdentityException {
try (NativeHandleGuard addressGuard = new NativeHandleGuard(destinationAddress)) {
CiphertextMessage message =
Native.SessionCipher_EncryptMessage(
paddedPlaintext,
addressGuard.nativeHandle(),
this.signalProtocolStore,
this.signalProtocolStore,
Instant.now().toEpochMilli());
filterExceptions(
InvalidKeyException.class,
UntrustedIdentityException.class,
() ->
Native.SessionCipher_EncryptMessage(
paddedPlaintext,
addressGuard.nativeHandle(),
this.signalProtocolStore,
this.signalProtocolStore,
Instant.now().toEpochMilli()));
UnidentifiedSenderMessageContent content =
new UnidentifiedSenderMessageContent(
message,
@ -82,8 +88,14 @@ public class SealedSessionCipher {
throws InvalidKeyException, UntrustedIdentityException {
try (NativeHandleGuard addressGuard = new NativeHandleGuard(destinationAddress);
NativeHandleGuard contentGuard = new NativeHandleGuard(content)) {
return Native.SealedSessionCipher_Encrypt(
addressGuard.nativeHandle(), contentGuard.nativeHandle(), this.signalProtocolStore);
return filterExceptions(
InvalidKeyException.class,
UntrustedIdentityException.class,
() ->
Native.SealedSessionCipher_Encrypt(
addressGuard.nativeHandle(),
contentGuard.nativeHandle(),
this.signalProtocolStore));
}
}
@ -150,12 +162,18 @@ public class SealedSessionCipher {
try (NativeHandleGuard contentGuard = new NativeHandleGuard(content)) {
byte[] result =
Native.SealedSessionCipher_MultiRecipientEncrypt(
recipientHandles,
recipientSessionHandles,
ServiceId.toConcatenatedFixedWidthBinary(excludedRecipients),
contentGuard.nativeHandle(),
this.signalProtocolStore);
filterExceptions(
InvalidKeyException.class,
InvalidRegistrationIdException.class,
NoSessionException.class,
UntrustedIdentityException.class,
() ->
Native.SealedSessionCipher_MultiRecipientEncrypt(
recipientHandles,
recipientSessionHandles,
ServiceId.toConcatenatedFixedWidthBinary(excludedRecipients),
contentGuard.nativeHandle(),
this.signalProtocolStore));
// Manually keep the lists of recipients and sessions from being garbage collected
// while we're using their native handles.
Native.keepAlive(recipients);
@ -166,18 +184,8 @@ public class SealedSessionCipher {
// For testing only.
static byte[] multiRecipientMessageForSingleRecipient(byte[] message) {
try {
return Native.SealedSessionCipher_MultiRecipientMessageForSingleRecipient(message);
} catch (Exception e) {
// Indirect with 'instanceof' because we haven't annotated our JNI methods as throwing.
// The compiler could theoretically optimize this away, so don't use this pattern anywhere but
// in a testing method.
if (e instanceof InvalidVersionException) {
throw new AssertionError(e);
} else {
throw e;
}
}
return filterExceptions(
() -> Native.SealedSessionCipher_MultiRecipientMessageForSingleRecipient(message));
}
public DecryptionResult decrypt(CertificateValidator validator, byte[] ciphertext, long timestamp)
@ -271,7 +279,10 @@ public class SealedSessionCipher {
case CiphertextMessage.SENDERKEY_TYPE:
return new GroupCipher(signalProtocolStore, sender).decrypt(message.getContent());
case CiphertextMessage.PLAINTEXT_CONTENT_TYPE:
return Native.PlaintextContent_DeserializeAndGetContent(message.getContent());
return filterExceptions(
InvalidMessageException.class,
InvalidVersionException.class,
() -> Native.PlaintextContent_DeserializeAndGetContent(message.getContent()));
default:
throw new InvalidMessageException("Unknown type: " + message.getType());
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.metadata.protocol;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Optional;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -51,46 +53,54 @@ public class UnidentifiedSenderMessageContent implements NativeHandleGuard.Owner
Optional<byte[]> groupId) {
try (NativeHandleGuard certificateGuard = new NativeHandleGuard(senderCertificate)) {
this.unsafeHandle =
Native.UnidentifiedSenderMessageContent_New(
message, certificateGuard.nativeHandle(), contentHint, groupId.orElse(null));
filterExceptions(
() ->
Native.UnidentifiedSenderMessageContent_New(
message, certificateGuard.nativeHandle(), contentHint, groupId.orElse(null)));
}
}
public int getType() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.UnidentifiedSenderMessageContent_GetMsgType(guard.nativeHandle());
return filterExceptions(
() -> Native.UnidentifiedSenderMessageContent_GetMsgType(guard.nativeHandle()));
}
}
public SenderCertificate getSenderCertificate() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new SenderCertificate(
Native.UnidentifiedSenderMessageContent_GetSenderCert(guard.nativeHandle()));
filterExceptions(
() -> Native.UnidentifiedSenderMessageContent_GetSenderCert(guard.nativeHandle())));
}
}
public byte[] getContent() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.UnidentifiedSenderMessageContent_GetContents(guard.nativeHandle());
return filterExceptions(
() -> Native.UnidentifiedSenderMessageContent_GetContents(guard.nativeHandle()));
}
}
public byte[] getSerialized() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.UnidentifiedSenderMessageContent_GetSerialized(guard.nativeHandle());
return filterExceptions(
() -> Native.UnidentifiedSenderMessageContent_GetSerialized(guard.nativeHandle()));
}
}
public int getContentHint() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.UnidentifiedSenderMessageContent_GetContentHint(guard.nativeHandle());
return filterExceptions(
() -> Native.UnidentifiedSenderMessageContent_GetContentHint(guard.nativeHandle()));
}
}
public Optional<byte[]> getGroupId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Optional.ofNullable(
Native.UnidentifiedSenderMessageContent_GetGroupId(guard.nativeHandle()));
filterExceptions(
() -> Native.UnidentifiedSenderMessageContent_GetGroupId(guard.nativeHandle())));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.net;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
@ -70,12 +72,15 @@ public class CdsiLookupRequest {
Native.LookupRequest_addE164(this.nativeHandle, e164);
}
for (Map.Entry<ServiceId, ProfileKey> entry : serviceIds.entrySet()) {
Native.LookupRequest_addAciAndAccessKey(
this.nativeHandle,
entry.getKey().toServiceIdFixedWidthBinary(),
entry.getValue().deriveAccessKey());
}
filterExceptions(
() -> {
for (Map.Entry<ServiceId, ProfileKey> entry : serviceIds.entrySet()) {
Native.LookupRequest_addAciAndAccessKey(
this.nativeHandle,
entry.getKey().toServiceIdFixedWidthBinary(),
entry.getValue().deriveAccessKey());
}
});
Native.LookupRequest_setReturnAcisWithoutUaks(this.nativeHandle, requireAcis);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.sgxsession;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -47,7 +49,7 @@ public class SgxClient implements NativeHandleGuard.Owner {
/** Initial request to send to SGX service, which begins post-attestation handshake. */
public byte[] initialRequest() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SgxClientState_InitialRequest(guard.nativeHandle());
return filterExceptions(() -> Native.SgxClientState_InitialRequest(guard.nativeHandle()));
}
}
@ -57,21 +59,27 @@ public class SgxClient implements NativeHandleGuard.Owner {
*/
public void completeHandshake(byte[] handshakeResponse) throws SgxCommunicationFailureException {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
Native.SgxClientState_CompleteHandshake(guard.nativeHandle(), handshakeResponse);
filterExceptions(
SgxCommunicationFailureException.class,
() -> Native.SgxClientState_CompleteHandshake(guard.nativeHandle(), handshakeResponse));
}
}
/** Called by client after completeHandshake has succeeded, to encrypt a message to send. */
public byte[] establishedSend(byte[] plaintextToSend) throws SgxCommunicationFailureException {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SgxClientState_EstablishedSend(guard.nativeHandle(), plaintextToSend);
return filterExceptions(
SgxCommunicationFailureException.class,
() -> Native.SgxClientState_EstablishedSend(guard.nativeHandle(), plaintextToSend));
}
}
/** Called by client after completeHandshake has succeeded, to decrypt a received message. */
public byte[] establishedRecv(byte[] receivedCiphertext) throws SgxCommunicationFailureException {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SgxClientState_EstablishedRecv(guard.nativeHandle(), receivedCiphertext);
return filterExceptions(
SgxCommunicationFailureException.class,
() -> Native.SgxClientState_EstablishedRecv(guard.nativeHandle(), receivedCiphertext));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.svr2;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
/**
@ -32,7 +34,7 @@ public class Pin {
* @return A hashed pin string that can be verified later
*/
public static String localHash(final byte[] pin) {
return Native.Pin_LocalHash(pin);
return filterExceptions(() -> Native.Pin_LocalHash(pin));
}
/**
@ -43,6 +45,6 @@ public class Pin {
* @return true if the pin matches the hash, false otherwise
*/
public static boolean verifyLocalHash(final String encodedHash, final byte[] pin) {
return Native.Pin_VerifyLocalHash(encodedHash, pin);
return filterExceptions(() -> Native.Pin_VerifyLocalHash(encodedHash, pin));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.svr2;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -37,7 +39,7 @@ public class PinHash implements NativeHandleGuard.Owner {
* @return A {@link PinHash}
*/
public static PinHash svr1(final byte[] normalizedPin, final byte[] salt) {
return new PinHash(Native.PinHash_FromSalt(normalizedPin, salt));
return new PinHash(filterExceptions(() -> Native.PinHash_FromSalt(normalizedPin, salt)));
}
/**
@ -52,7 +54,9 @@ public class PinHash implements NativeHandleGuard.Owner {
*/
public static PinHash svr2(
final byte[] normalizedPin, final String username, final byte[] mrenclave) {
return new PinHash(Native.PinHash_FromUsernameMrenclave(normalizedPin, username, mrenclave));
return new PinHash(
filterExceptions(
() -> Native.PinHash_FromUsernameMrenclave(normalizedPin, username, mrenclave)));
}
/**

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.svr2;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.attest.AttestationDataException;
import org.signal.libsignal.internal.Native;
@ -20,6 +22,9 @@ import org.signal.libsignal.sgxsession.SgxClient;
public class Svr2Client extends SgxClient {
public Svr2Client(byte[] mrenclave, byte[] attestationMsg, Instant currentInstant)
throws AttestationDataException {
super(Native.Svr2Client_New(mrenclave, attestationMsg, currentInstant.toEpochMilli()));
super(
filterExceptions(
AttestationDataException.class,
() -> Native.Svr2Client_New(mrenclave, attestationMsg, currentInstant.toEpochMilli())));
}
}

View File

@ -21,6 +21,12 @@ public final class NativeErrorsTest extends TestCase {
Native.GroupSecretParams_DecryptServiceId(params, uuidCiphertext);
failed = true;
} catch (AssertionError e) {
// expected
} catch (Exception e) {
// Normally callers would use filterExceptions to handle this,
// which turns surprise exceptions into AssertionErrors,
// but in this case we're *expecting* an AssertionError.
throw new AssertionError("Unexpected exception", e);
}
if (failed) {
throw new AssertionError(

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.cds2;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Map;
import org.signal.libsignal.attest.AttestationDataException;
import org.signal.libsignal.internal.Native;
@ -23,7 +25,9 @@ public final class Cds2Metrics {
public static Map<String, Long> extract(final byte[] attestationMessage)
throws AttestationDataException {
@SuppressWarnings("unchecked")
Map<String, Long> result = Native.Cds2Metrics_extract(attestationMessage);
Map<String, Long> result =
filterExceptions(
AttestationDataException.class, () -> Native.Cds2Metrics_extract(attestationMessage));
return result;
}
}

View File

@ -87,77 +87,77 @@ public final class Native {
public static native void keepAlive(Object obj);
public static native void Aes256Ctr32_Destroy(long handle);
public static native long Aes256Ctr32_New(byte[] key, byte[] nonce, int initialCtr);
public static native long Aes256Ctr32_New(byte[] key, byte[] nonce, int initialCtr) throws Exception;
public static native void Aes256Ctr32_Process(long ctr, byte[] data, int offset, int length);
public static native void Aes256GcmDecryption_Destroy(long handle);
public static native long Aes256GcmDecryption_New(byte[] key, byte[] nonce, byte[] associatedData);
public static native long Aes256GcmDecryption_New(byte[] key, byte[] nonce, byte[] associatedData) throws Exception;
public static native void Aes256GcmDecryption_Update(long gcm, byte[] data, int offset, int length);
public static native boolean Aes256GcmDecryption_VerifyTag(long gcm, byte[] tag);
public static native boolean Aes256GcmDecryption_VerifyTag(long gcm, byte[] tag) throws Exception;
public static native byte[] Aes256GcmEncryption_ComputeTag(long gcm);
public static native void Aes256GcmEncryption_Destroy(long handle);
public static native long Aes256GcmEncryption_New(byte[] key, byte[] nonce, byte[] associatedData);
public static native long Aes256GcmEncryption_New(byte[] key, byte[] nonce, byte[] associatedData) throws Exception;
public static native void Aes256GcmEncryption_Update(long gcm, byte[] data, int offset, int length);
public static native byte[] Aes256GcmSiv_Decrypt(long aesGcmSiv, byte[] ctext, byte[] nonce, byte[] associatedData);
public static native byte[] Aes256GcmSiv_Decrypt(long aesGcmSiv, byte[] ctext, byte[] nonce, byte[] associatedData) throws Exception;
public static native void Aes256GcmSiv_Destroy(long handle);
public static native byte[] Aes256GcmSiv_Encrypt(long aesGcmSivObj, byte[] ptext, byte[] nonce, byte[] associatedData);
public static native long Aes256GcmSiv_New(byte[] key);
public static native byte[] Aes256GcmSiv_Encrypt(long aesGcmSivObj, byte[] ptext, byte[] nonce, byte[] associatedData) throws Exception;
public static native long Aes256GcmSiv_New(byte[] key) throws Exception;
public static native void AuthCredentialPresentation_CheckValidContents(byte[] presentationBytes);
public static native void AuthCredentialPresentation_CheckValidContents(byte[] presentationBytes) throws Exception;
public static native byte[] AuthCredentialPresentation_GetPniCiphertext(byte[] presentationBytes);
public static native long AuthCredentialPresentation_GetRedemptionTime(byte[] presentationBytes);
public static native byte[] AuthCredentialPresentation_GetUuidCiphertext(byte[] presentationBytes);
public static native void AuthCredentialResponse_CheckValidContents(byte[] buffer);
public static native void AuthCredentialResponse_CheckValidContents(byte[] buffer) throws Exception;
public static native void AuthCredentialWithPniResponse_CheckValidContents(byte[] buffer);
public static native void AuthCredentialWithPniResponse_CheckValidContents(byte[] buffer) throws Exception;
public static native void AuthCredentialWithPni_CheckValidContents(byte[] buffer);
public static native void AuthCredentialWithPni_CheckValidContents(byte[] buffer) throws Exception;
public static native void AuthCredential_CheckValidContents(byte[] buffer);
public static native void AuthCredential_CheckValidContents(byte[] buffer) throws Exception;
public static native void BackupAuthCredentialPresentation_CheckValidContents(byte[] presentationBytes);
public static native void BackupAuthCredentialPresentation_CheckValidContents(byte[] presentationBytes) throws Exception;
public static native byte[] BackupAuthCredentialPresentation_GetBackupId(byte[] presentationBytes);
public static native long BackupAuthCredentialPresentation_GetReceiptLevel(byte[] presentationBytes);
public static native void BackupAuthCredentialPresentation_Verify(byte[] presentationBytes, long now, byte[] serverParamsBytes);
public static native void BackupAuthCredentialPresentation_Verify(byte[] presentationBytes, long now, byte[] serverParamsBytes) throws Exception;
public static native void BackupAuthCredentialRequestContext_CheckValidContents(byte[] contextBytes);
public static native void BackupAuthCredentialRequestContext_CheckValidContents(byte[] contextBytes) throws Exception;
public static native byte[] BackupAuthCredentialRequestContext_GetRequest(byte[] contextBytes);
public static native byte[] BackupAuthCredentialRequestContext_New(byte[] backupKey, UUID uuid);
public static native byte[] BackupAuthCredentialRequestContext_ReceiveResponse(byte[] contextBytes, byte[] responseBytes, byte[] paramsBytes, long expectedReceiptLevel);
public static native byte[] BackupAuthCredentialRequestContext_ReceiveResponse(byte[] contextBytes, byte[] responseBytes, byte[] paramsBytes, long expectedReceiptLevel) throws Exception;
public static native void BackupAuthCredentialRequest_CheckValidContents(byte[] requestBytes);
public static native void BackupAuthCredentialRequest_CheckValidContents(byte[] requestBytes) throws Exception;
public static native byte[] BackupAuthCredentialRequest_IssueDeterministic(byte[] requestBytes, long redemptionTime, long receiptLevel, byte[] paramsBytes, byte[] randomness);
public static native void BackupAuthCredentialResponse_CheckValidContents(byte[] responseBytes);
public static native void BackupAuthCredentialResponse_CheckValidContents(byte[] responseBytes) throws Exception;
public static native void BackupAuthCredential_CheckValidContents(byte[] paramsBytes);
public static native void BackupAuthCredential_CheckValidContents(byte[] paramsBytes) throws Exception;
public static native byte[] BackupAuthCredential_GetBackupId(byte[] credentialBytes);
public static native byte[] BackupAuthCredential_PresentDeterministic(byte[] credentialBytes, byte[] serverParamsBytes, byte[] randomness);
public static native byte[] BackupAuthCredential_PresentDeterministic(byte[] credentialBytes, byte[] serverParamsBytes, byte[] randomness) throws Exception;
public static native void CallLinkAuthCredentialPresentation_CheckValidContents(byte[] presentationBytes);
public static native void CallLinkAuthCredentialPresentation_CheckValidContents(byte[] presentationBytes) throws Exception;
public static native byte[] CallLinkAuthCredentialPresentation_GetUserId(byte[] presentationBytes);
public static native void CallLinkAuthCredentialPresentation_Verify(byte[] presentationBytes, long now, byte[] serverParamsBytes, byte[] callLinkParamsBytes);
public static native void CallLinkAuthCredentialPresentation_Verify(byte[] presentationBytes, long now, byte[] serverParamsBytes, byte[] callLinkParamsBytes) throws Exception;
public static native void CallLinkAuthCredentialResponse_CheckValidContents(byte[] responseBytes);
public static native void CallLinkAuthCredentialResponse_CheckValidContents(byte[] responseBytes) throws Exception;
public static native byte[] CallLinkAuthCredentialResponse_IssueDeterministic(byte[] userId, long redemptionTime, byte[] paramsBytes, byte[] randomness);
public static native byte[] CallLinkAuthCredentialResponse_Receive(byte[] responseBytes, byte[] userId, long redemptionTime, byte[] paramsBytes);
public static native byte[] CallLinkAuthCredentialResponse_Receive(byte[] responseBytes, byte[] userId, long redemptionTime, byte[] paramsBytes) throws Exception;
public static native void CallLinkAuthCredential_CheckValidContents(byte[] credentialBytes);
public static native byte[] CallLinkAuthCredential_PresentDeterministic(byte[] credentialBytes, byte[] userId, long redemptionTime, byte[] serverParamsBytes, byte[] callLinkParamsBytes, byte[] randomness);
public static native void CallLinkAuthCredential_CheckValidContents(byte[] credentialBytes) throws Exception;
public static native byte[] CallLinkAuthCredential_PresentDeterministic(byte[] credentialBytes, byte[] userId, long redemptionTime, byte[] serverParamsBytes, byte[] callLinkParamsBytes, byte[] randomness) throws Exception;
public static native void CallLinkPublicParams_CheckValidContents(byte[] paramsBytes);
public static native void CallLinkPublicParams_CheckValidContents(byte[] paramsBytes) throws Exception;
public static native void CallLinkSecretParams_CheckValidContents(byte[] paramsBytes);
public static native byte[] CallLinkSecretParams_DecryptUserId(byte[] paramsBytes, byte[] userId);
public static native void CallLinkSecretParams_CheckValidContents(byte[] paramsBytes) throws Exception;
public static native byte[] CallLinkSecretParams_DecryptUserId(byte[] paramsBytes, byte[] userId) throws Exception;
public static native byte[] CallLinkSecretParams_DeriveFromRootKey(byte[] rootKey);
public static native byte[] CallLinkSecretParams_GetPublicParams(byte[] paramsBytes);
public static native long Cds2ClientState_New(byte[] mrenclave, byte[] attestationMsg, long currentTimestamp);
public static native long Cds2ClientState_New(byte[] mrenclave, byte[] attestationMsg, long currentTimestamp) throws Exception;
public static native Map Cds2Metrics_extract(byte[] attestationMsg);
public static native Map Cds2Metrics_extract(byte[] attestationMsg) throws Exception;
public static native void CdsiLookup_Destroy(long handle);
public static native CompletableFuture<Object> CdsiLookup_complete(long asyncRuntime, long lookup);
@ -167,21 +167,21 @@ public final class Native {
public static native void ConnectionManager_Destroy(long handle);
public static native long ConnectionManager_new(int environment);
public static native void CreateCallLinkCredentialPresentation_CheckValidContents(byte[] presentationBytes);
public static native void CreateCallLinkCredentialPresentation_Verify(byte[] presentationBytes, byte[] roomId, long now, byte[] serverParamsBytes, byte[] callLinkParamsBytes);
public static native void CreateCallLinkCredentialPresentation_CheckValidContents(byte[] presentationBytes) throws Exception;
public static native void CreateCallLinkCredentialPresentation_Verify(byte[] presentationBytes, byte[] roomId, long now, byte[] serverParamsBytes, byte[] callLinkParamsBytes) throws Exception;
public static native void CreateCallLinkCredentialRequestContext_CheckValidContents(byte[] contextBytes);
public static native void CreateCallLinkCredentialRequestContext_CheckValidContents(byte[] contextBytes) throws Exception;
public static native byte[] CreateCallLinkCredentialRequestContext_GetRequest(byte[] contextBytes);
public static native byte[] CreateCallLinkCredentialRequestContext_NewDeterministic(byte[] roomId, byte[] randomness);
public static native byte[] CreateCallLinkCredentialRequestContext_ReceiveResponse(byte[] contextBytes, byte[] responseBytes, byte[] userId, byte[] paramsBytes);
public static native byte[] CreateCallLinkCredentialRequestContext_ReceiveResponse(byte[] contextBytes, byte[] responseBytes, byte[] userId, byte[] paramsBytes) throws Exception;
public static native void CreateCallLinkCredentialRequest_CheckValidContents(byte[] requestBytes);
public static native void CreateCallLinkCredentialRequest_CheckValidContents(byte[] requestBytes) throws Exception;
public static native byte[] CreateCallLinkCredentialRequest_IssueDeterministic(byte[] requestBytes, byte[] userId, long timestamp, byte[] paramsBytes, byte[] randomness);
public static native void CreateCallLinkCredentialResponse_CheckValidContents(byte[] responseBytes);
public static native void CreateCallLinkCredentialResponse_CheckValidContents(byte[] responseBytes) throws Exception;
public static native void CreateCallLinkCredential_CheckValidContents(byte[] paramsBytes);
public static native byte[] CreateCallLinkCredential_PresentDeterministic(byte[] credentialBytes, byte[] roomId, byte[] userId, byte[] serverParamsBytes, byte[] callLinkParamsBytes, byte[] randomness);
public static native void CreateCallLinkCredential_CheckValidContents(byte[] paramsBytes) throws Exception;
public static native byte[] CreateCallLinkCredential_PresentDeterministic(byte[] credentialBytes, byte[] roomId, byte[] userId, byte[] serverParamsBytes, byte[] callLinkParamsBytes, byte[] randomness) throws Exception;
public static native String CreateOTP(String username, byte[] secret);
@ -189,67 +189,67 @@ public final class Native {
public static native void CryptographicHash_Destroy(long handle);
public static native byte[] CryptographicHash_Finalize(long hash);
public static native long CryptographicHash_New(String algo);
public static native long CryptographicHash_New(String algo) throws Exception;
public static native void CryptographicHash_Update(long hash, byte[] input);
public static native void CryptographicHash_UpdateWithOffset(long hash, byte[] input, int offset, int len);
public static native void CryptographicMac_Destroy(long handle);
public static native byte[] CryptographicMac_Finalize(long mac);
public static native long CryptographicMac_New(String algo, byte[] key);
public static native long CryptographicMac_New(String algo, byte[] key) throws Exception;
public static native void CryptographicMac_Update(long mac, byte[] input);
public static native void CryptographicMac_UpdateWithOffset(long mac, byte[] input, int offset, int len);
public static native long DecryptionErrorMessage_Deserialize(byte[] data);
public static native long DecryptionErrorMessage_Deserialize(byte[] data) throws Exception;
public static native void DecryptionErrorMessage_Destroy(long handle);
public static native long DecryptionErrorMessage_ExtractFromSerializedContent(byte[] bytes);
public static native long DecryptionErrorMessage_ForOriginalMessage(byte[] originalBytes, int originalType, long originalTimestamp, int originalSenderDeviceId);
public static native int DecryptionErrorMessage_GetDeviceId(long obj);
public static native long DecryptionErrorMessage_ExtractFromSerializedContent(byte[] bytes) throws Exception;
public static native long DecryptionErrorMessage_ForOriginalMessage(byte[] originalBytes, int originalType, long originalTimestamp, int originalSenderDeviceId) throws Exception;
public static native int DecryptionErrorMessage_GetDeviceId(long obj) throws Exception;
public static native long DecryptionErrorMessage_GetRatchetKey(long m);
public static native byte[] DecryptionErrorMessage_GetSerialized(long obj);
public static native long DecryptionErrorMessage_GetTimestamp(long obj);
public static native byte[] DecryptionErrorMessage_GetSerialized(long obj) throws Exception;
public static native long DecryptionErrorMessage_GetTimestamp(long obj) throws Exception;
public static native byte[] DeviceTransfer_GenerateCertificate(byte[] privateKey, String name, int daysToExpire);
public static native byte[] DeviceTransfer_GenerateCertificate(byte[] privateKey, String name, int daysToExpire) throws Exception;
public static native byte[] DeviceTransfer_GeneratePrivateKey();
public static native byte[] ECPrivateKey_Agree(long privateKey, long publicKey);
public static native long ECPrivateKey_Deserialize(byte[] data);
public static native byte[] ECPrivateKey_Agree(long privateKey, long publicKey) throws Exception;
public static native long ECPrivateKey_Deserialize(byte[] data) throws Exception;
public static native void ECPrivateKey_Destroy(long handle);
public static native long ECPrivateKey_Generate();
public static native long ECPrivateKey_GetPublicKey(long k);
public static native byte[] ECPrivateKey_Serialize(long obj);
public static native byte[] ECPrivateKey_Sign(long key, byte[] message);
public static native long ECPrivateKey_GetPublicKey(long k) throws Exception;
public static native byte[] ECPrivateKey_Serialize(long obj) throws Exception;
public static native byte[] ECPrivateKey_Sign(long key, byte[] message) throws Exception;
public static native int ECPublicKey_Compare(long key1, long key2);
public static native long ECPublicKey_Deserialize(byte[] data, int offset);
public static native long ECPublicKey_Deserialize(byte[] data, int offset) throws Exception;
public static native void ECPublicKey_Destroy(long handle);
public static native boolean ECPublicKey_Equals(long lhs, long rhs);
public static native byte[] ECPublicKey_GetPublicKeyBytes(long obj);
public static native byte[] ECPublicKey_Serialize(long obj);
public static native boolean ECPublicKey_Verify(long key, byte[] message, byte[] signature);
public static native byte[] ECPublicKey_GetPublicKeyBytes(long obj) throws Exception;
public static native byte[] ECPublicKey_Serialize(long obj) throws Exception;
public static native boolean ECPublicKey_Verify(long key, byte[] message, byte[] signature) throws Exception;
public static native void ExpiringProfileKeyCredentialResponse_CheckValidContents(byte[] buffer);
public static native void ExpiringProfileKeyCredentialResponse_CheckValidContents(byte[] buffer) throws Exception;
public static native void ExpiringProfileKeyCredential_CheckValidContents(byte[] buffer);
public static native void ExpiringProfileKeyCredential_CheckValidContents(byte[] buffer) throws Exception;
public static native long ExpiringProfileKeyCredential_GetExpirationTime(byte[] credential);
public static native void GenericServerPublicParams_CheckValidContents(byte[] paramsBytes);
public static native void GenericServerPublicParams_CheckValidContents(byte[] paramsBytes) throws Exception;
public static native void GenericServerSecretParams_CheckValidContents(byte[] paramsBytes);
public static native void GenericServerSecretParams_CheckValidContents(byte[] paramsBytes) throws Exception;
public static native byte[] GenericServerSecretParams_GenerateDeterministic(byte[] randomness);
public static native byte[] GenericServerSecretParams_GetPublicParams(byte[] paramsBytes);
public static native byte[] GroupCipher_DecryptMessage(long sender, byte[] message, SenderKeyStore store);
public static native CiphertextMessage GroupCipher_EncryptMessage(long sender, UUID distributionId, byte[] message, SenderKeyStore store);
public static native byte[] GroupCipher_DecryptMessage(long sender, byte[] message, SenderKeyStore store) throws Exception;
public static native CiphertextMessage GroupCipher_EncryptMessage(long sender, UUID distributionId, byte[] message, SenderKeyStore store) throws Exception;
public static native void GroupMasterKey_CheckValidContents(byte[] buffer);
public static native void GroupMasterKey_CheckValidContents(byte[] buffer) throws Exception;
public static native void GroupPublicParams_CheckValidContents(byte[] buffer);
public static native void GroupPublicParams_CheckValidContents(byte[] buffer) throws Exception;
public static native byte[] GroupPublicParams_GetGroupIdentifier(byte[] groupPublicParams);
public static native void GroupSecretParams_CheckValidContents(byte[] buffer);
public static native byte[] GroupSecretParams_DecryptBlobWithPadding(byte[] params, byte[] ciphertext);
public static native byte[] GroupSecretParams_DecryptProfileKey(byte[] params, byte[] profileKey, byte[] userId);
public static native byte[] GroupSecretParams_DecryptServiceId(byte[] params, byte[] ciphertext);
public static native void GroupSecretParams_CheckValidContents(byte[] buffer) throws Exception;
public static native byte[] GroupSecretParams_DecryptBlobWithPadding(byte[] params, byte[] ciphertext) throws Exception;
public static native byte[] GroupSecretParams_DecryptProfileKey(byte[] params, byte[] profileKey, byte[] userId) throws Exception;
public static native byte[] GroupSecretParams_DecryptServiceId(byte[] params, byte[] ciphertext) throws Exception;
public static native byte[] GroupSecretParams_DeriveFromMasterKey(byte[] masterKey);
public static native byte[] GroupSecretParams_EncryptBlobWithPaddingDeterministic(byte[] params, byte[] randomness, byte[] plaintext, int paddingLen);
public static native byte[] GroupSecretParams_EncryptProfileKey(byte[] params, byte[] profileKey, byte[] userId);
@ -258,35 +258,35 @@ public final class Native {
public static native byte[] GroupSecretParams_GetMasterKey(byte[] params);
public static native byte[] GroupSecretParams_GetPublicParams(byte[] params);
public static native void GroupSendCredentialPresentation_CheckValidContents(byte[] presentationBytes);
public static native void GroupSendCredentialPresentation_Verify(byte[] presentationBytes, byte[] groupMembers, long now, byte[] serverParams);
public static native void GroupSendCredentialPresentation_CheckValidContents(byte[] presentationBytes) throws Exception;
public static native void GroupSendCredentialPresentation_Verify(byte[] presentationBytes, byte[] groupMembers, long now, byte[] serverParams) throws Exception;
public static native void GroupSendCredentialResponse_CheckValidContents(byte[] responseBytes);
public static native void GroupSendCredentialResponse_CheckValidContents(byte[] responseBytes) throws Exception;
public static native long GroupSendCredentialResponse_DefaultExpirationBasedOnCurrentTime();
public static native byte[] GroupSendCredentialResponse_IssueDeterministic(byte[] concatenatedGroupMemberCiphertexts, byte[] requester, long expiration, byte[] serverParams, byte[] randomness);
public static native byte[] GroupSendCredentialResponse_Receive(byte[] responseBytes, byte[] groupMembers, byte[] localAci, long now, byte[] serverParams, byte[] groupParams);
public static native byte[] GroupSendCredentialResponse_ReceiveWithCiphertexts(byte[] responseBytes, byte[] concatenatedGroupMemberCiphertexts, byte[] requester, long now, byte[] serverParams, byte[] groupParams);
public static native byte[] GroupSendCredentialResponse_IssueDeterministic(byte[] concatenatedGroupMemberCiphertexts, byte[] requester, long expiration, byte[] serverParams, byte[] randomness) throws Exception;
public static native byte[] GroupSendCredentialResponse_Receive(byte[] responseBytes, byte[] groupMembers, byte[] localAci, long now, byte[] serverParams, byte[] groupParams) throws Exception;
public static native byte[] GroupSendCredentialResponse_ReceiveWithCiphertexts(byte[] responseBytes, byte[] concatenatedGroupMemberCiphertexts, byte[] requester, long now, byte[] serverParams, byte[] groupParams) throws Exception;
public static native void GroupSendCredential_CheckValidContents(byte[] paramsBytes);
public static native byte[] GroupSendCredential_PresentDeterministic(byte[] credentialBytes, byte[] serverParams, byte[] randomness);
public static native void GroupSendCredential_CheckValidContents(byte[] paramsBytes) throws Exception;
public static native byte[] GroupSendCredential_PresentDeterministic(byte[] credentialBytes, byte[] serverParams, byte[] randomness) throws Exception;
public static native long GroupSessionBuilder_CreateSenderKeyDistributionMessage(long sender, UUID distributionId, SenderKeyStore store);
public static native void GroupSessionBuilder_ProcessSenderKeyDistributionMessage(long sender, long senderKeyDistributionMessage, SenderKeyStore store);
public static native long GroupSessionBuilder_CreateSenderKeyDistributionMessage(long sender, UUID distributionId, SenderKeyStore store) throws Exception;
public static native void GroupSessionBuilder_ProcessSenderKeyDistributionMessage(long sender, long senderKeyDistributionMessage, SenderKeyStore store) throws Exception;
public static native byte[] HKDF_DeriveSecrets(int outputLength, byte[] ikm, byte[] label, byte[] salt);
public static native byte[] HKDF_DeriveSecrets(int outputLength, byte[] ikm, byte[] label, byte[] salt) throws Exception;
public static native void HsmEnclaveClient_CompleteHandshake(long cli, byte[] handshakeReceived);
public static native void HsmEnclaveClient_CompleteHandshake(long cli, byte[] handshakeReceived) throws Exception;
public static native void HsmEnclaveClient_Destroy(long handle);
public static native byte[] HsmEnclaveClient_EstablishedRecv(long cli, byte[] receivedCiphertext);
public static native byte[] HsmEnclaveClient_EstablishedSend(long cli, byte[] plaintextToSend);
public static native byte[] HsmEnclaveClient_InitialRequest(long obj);
public static native long HsmEnclaveClient_New(byte[] trustedPublicKey, byte[] trustedCodeHashes);
public static native byte[] HsmEnclaveClient_EstablishedRecv(long cli, byte[] receivedCiphertext) throws Exception;
public static native byte[] HsmEnclaveClient_EstablishedSend(long cli, byte[] plaintextToSend) throws Exception;
public static native byte[] HsmEnclaveClient_InitialRequest(long obj) throws Exception;
public static native long HsmEnclaveClient_New(byte[] trustedPublicKey, byte[] trustedCodeHashes) throws Exception;
public static native long[] IdentityKeyPair_Deserialize(byte[] data);
public static native byte[] IdentityKeyPair_Serialize(long publicKey, long privateKey);
public static native byte[] IdentityKeyPair_SignAlternateIdentity(long publicKey, long privateKey, long otherIdentity);
public static native byte[] IdentityKeyPair_SignAlternateIdentity(long publicKey, long privateKey, long otherIdentity) throws Exception;
public static native boolean IdentityKey_VerifyAlternateIdentity(long publicKey, long otherIdentity, byte[] signature);
public static native boolean IdentityKey_VerifyAlternateIdentity(long publicKey, long otherIdentity, byte[] signature) throws Exception;
public static native int IncrementalMac_CalculateChunkSize(int dataSize);
public static native void IncrementalMac_Destroy(long handle);
@ -299,31 +299,31 @@ public final class Native {
public static native long KyberKeyPair_GetPublicKey(long keyPair);
public static native long KyberKeyPair_GetSecretKey(long keyPair);
public static native long KyberPreKeyRecord_Deserialize(byte[] data);
public static native long KyberPreKeyRecord_Deserialize(byte[] data) throws Exception;
public static native void KyberPreKeyRecord_Destroy(long handle);
public static native int KyberPreKeyRecord_GetId(long obj);
public static native long KyberPreKeyRecord_GetKeyPair(long obj);
public static native long KyberPreKeyRecord_GetPublicKey(long obj);
public static native long KyberPreKeyRecord_GetSecretKey(long obj);
public static native byte[] KyberPreKeyRecord_GetSerialized(long obj);
public static native byte[] KyberPreKeyRecord_GetSignature(long obj);
public static native long KyberPreKeyRecord_GetTimestamp(long obj);
public static native int KyberPreKeyRecord_GetId(long obj) throws Exception;
public static native long KyberPreKeyRecord_GetKeyPair(long obj) throws Exception;
public static native long KyberPreKeyRecord_GetPublicKey(long obj) throws Exception;
public static native long KyberPreKeyRecord_GetSecretKey(long obj) throws Exception;
public static native byte[] KyberPreKeyRecord_GetSerialized(long obj) throws Exception;
public static native byte[] KyberPreKeyRecord_GetSignature(long obj) throws Exception;
public static native long KyberPreKeyRecord_GetTimestamp(long obj) throws Exception;
public static native long KyberPreKeyRecord_New(int id, long timestamp, long keyPair, byte[] signature);
public static native long KyberPublicKey_DeserializeWithOffset(byte[] data, int offset);
public static native long KyberPublicKey_DeserializeWithOffset(byte[] data, int offset) throws Exception;
public static native void KyberPublicKey_Destroy(long handle);
public static native boolean KyberPublicKey_Equals(long lhs, long rhs);
public static native byte[] KyberPublicKey_Serialize(long obj);
public static native byte[] KyberPublicKey_Serialize(long obj) throws Exception;
public static native long KyberSecretKey_Deserialize(byte[] data);
public static native long KyberSecretKey_Deserialize(byte[] data) throws Exception;
public static native void KyberSecretKey_Destroy(long handle);
public static native byte[] KyberSecretKey_Serialize(long obj);
public static native byte[] KyberSecretKey_Serialize(long obj) throws Exception;
public static native void Logger_Initialize(int maxLevel, Class loggerClass);
public static native void Logger_SetMaxLevel(int maxLevel);
public static native void LookupRequest_Destroy(long handle);
public static native void LookupRequest_addAciAndAccessKey(long request, byte[] aci, byte[] accessKey);
public static native void LookupRequest_addAciAndAccessKey(long request, byte[] aci, byte[] accessKey) throws Exception;
public static native void LookupRequest_addE164(long request, String e164);
public static native void LookupRequest_addPreviousE164(long request, String e164);
public static native long LookupRequest_new();
@ -333,82 +333,82 @@ public final class Native {
public static native void MessageBackupKey_Destroy(long handle);
public static native long MessageBackupKey_New(byte[] masterKey, byte[] aci);
public static native Object MessageBackupValidator_Validate(long key, InputStream firstStream, InputStream secondStream, long len);
public static native Object MessageBackupValidator_Validate(long key, InputStream firstStream, InputStream secondStream, long len) throws Exception;
public static native long Mp4Sanitizer_Sanitize(InputStream input, long len);
public static native long Mp4Sanitizer_Sanitize(InputStream input, long len) throws Exception;
public static native void NumericFingerprintGenerator_Destroy(long handle);
public static native String NumericFingerprintGenerator_GetDisplayString(long obj);
public static native byte[] NumericFingerprintGenerator_GetScannableEncoding(long obj);
public static native long NumericFingerprintGenerator_New(int iterations, int version, byte[] localIdentifier, byte[] localKey, byte[] remoteIdentifier, byte[] remoteKey);
public static native String NumericFingerprintGenerator_GetDisplayString(long obj) throws Exception;
public static native byte[] NumericFingerprintGenerator_GetScannableEncoding(long obj) throws Exception;
public static native long NumericFingerprintGenerator_New(int iterations, int version, byte[] localIdentifier, byte[] localKey, byte[] remoteIdentifier, byte[] remoteKey) throws Exception;
public static native void OtherTestingHandleType_Destroy(long handle);
public static native byte[] PinHash_AccessKey(long ph);
public static native void PinHash_Destroy(long handle);
public static native byte[] PinHash_EncryptionKey(long ph);
public static native long PinHash_FromSalt(byte[] pin, byte[] salt);
public static native long PinHash_FromUsernameMrenclave(byte[] pin, String username, byte[] mrenclave);
public static native long PinHash_FromSalt(byte[] pin, byte[] salt) throws Exception;
public static native long PinHash_FromUsernameMrenclave(byte[] pin, String username, byte[] mrenclave) throws Exception;
public static native String Pin_LocalHash(byte[] pin);
public static native boolean Pin_VerifyLocalHash(String encodedHash, byte[] pin);
public static native String Pin_LocalHash(byte[] pin) throws Exception;
public static native boolean Pin_VerifyLocalHash(String encodedHash, byte[] pin) throws Exception;
public static native long PlaintextContent_Deserialize(byte[] data);
public static native byte[] PlaintextContent_DeserializeAndGetContent(byte[] bytes);
public static native long PlaintextContent_Deserialize(byte[] data) throws Exception;
public static native byte[] PlaintextContent_DeserializeAndGetContent(byte[] bytes) throws Exception;
public static native void PlaintextContent_Destroy(long handle);
public static native long PlaintextContent_FromDecryptionErrorMessage(long m);
public static native byte[] PlaintextContent_GetBody(long obj);
public static native byte[] PlaintextContent_GetSerialized(long obj);
public static native byte[] PlaintextContent_GetBody(long obj) throws Exception;
public static native byte[] PlaintextContent_GetSerialized(long obj) throws Exception;
public static native void PreKeyBundle_Destroy(long handle);
public static native int PreKeyBundle_GetDeviceId(long obj);
public static native long PreKeyBundle_GetIdentityKey(long p);
public static native int PreKeyBundle_GetKyberPreKeyId(long obj);
public static native long PreKeyBundle_GetKyberPreKeyPublic(long bundle);
public static native byte[] PreKeyBundle_GetKyberPreKeySignature(long bundle);
public static native int PreKeyBundle_GetPreKeyId(long obj);
public static native long PreKeyBundle_GetPreKeyPublic(long obj);
public static native int PreKeyBundle_GetRegistrationId(long obj);
public static native int PreKeyBundle_GetSignedPreKeyId(long obj);
public static native long PreKeyBundle_GetSignedPreKeyPublic(long obj);
public static native byte[] PreKeyBundle_GetSignedPreKeySignature(long obj);
public static native long PreKeyBundle_New(int registrationId, int deviceId, int prekeyId, long prekey, int signedPrekeyId, long signedPrekey, byte[] signedPrekeySignature, long identityKey, int kyberPrekeyId, long kyberPrekey, byte[] kyberPrekeySignature);
public static native int PreKeyBundle_GetDeviceId(long obj) throws Exception;
public static native long PreKeyBundle_GetIdentityKey(long p) throws Exception;
public static native int PreKeyBundle_GetKyberPreKeyId(long obj) throws Exception;
public static native long PreKeyBundle_GetKyberPreKeyPublic(long bundle) throws Exception;
public static native byte[] PreKeyBundle_GetKyberPreKeySignature(long bundle) throws Exception;
public static native int PreKeyBundle_GetPreKeyId(long obj) throws Exception;
public static native long PreKeyBundle_GetPreKeyPublic(long obj) throws Exception;
public static native int PreKeyBundle_GetRegistrationId(long obj) throws Exception;
public static native int PreKeyBundle_GetSignedPreKeyId(long obj) throws Exception;
public static native long PreKeyBundle_GetSignedPreKeyPublic(long obj) throws Exception;
public static native byte[] PreKeyBundle_GetSignedPreKeySignature(long obj) throws Exception;
public static native long PreKeyBundle_New(int registrationId, int deviceId, int prekeyId, long prekey, int signedPrekeyId, long signedPrekey, byte[] signedPrekeySignature, long identityKey, int kyberPrekeyId, long kyberPrekey, byte[] kyberPrekeySignature) throws Exception;
public static native long PreKeyRecord_Deserialize(byte[] data);
public static native long PreKeyRecord_Deserialize(byte[] data) throws Exception;
public static native void PreKeyRecord_Destroy(long handle);
public static native int PreKeyRecord_GetId(long obj);
public static native long PreKeyRecord_GetPrivateKey(long obj);
public static native long PreKeyRecord_GetPublicKey(long obj);
public static native byte[] PreKeyRecord_GetSerialized(long obj);
public static native int PreKeyRecord_GetId(long obj) throws Exception;
public static native long PreKeyRecord_GetPrivateKey(long obj) throws Exception;
public static native long PreKeyRecord_GetPublicKey(long obj) throws Exception;
public static native byte[] PreKeyRecord_GetSerialized(long obj) throws Exception;
public static native long PreKeyRecord_New(int id, long pubKey, long privKey);
public static native long PreKeySignalMessage_Deserialize(byte[] data);
public static native long PreKeySignalMessage_Deserialize(byte[] data) throws Exception;
public static native void PreKeySignalMessage_Destroy(long handle);
public static native long PreKeySignalMessage_GetBaseKey(long m);
public static native long PreKeySignalMessage_GetIdentityKey(long m);
public static native int PreKeySignalMessage_GetPreKeyId(long obj);
public static native int PreKeySignalMessage_GetRegistrationId(long obj);
public static native byte[] PreKeySignalMessage_GetSerialized(long obj);
public static native int PreKeySignalMessage_GetPreKeyId(long obj) throws Exception;
public static native int PreKeySignalMessage_GetRegistrationId(long obj) throws Exception;
public static native byte[] PreKeySignalMessage_GetSerialized(long obj) throws Exception;
public static native long PreKeySignalMessage_GetSignalMessage(long m);
public static native int PreKeySignalMessage_GetSignedPreKeyId(long obj);
public static native int PreKeySignalMessage_GetVersion(long obj);
public static native long PreKeySignalMessage_New(int messageVersion, int registrationId, int preKeyId, int signedPreKeyId, long baseKey, long identityKey, long signalMessage);
public static native int PreKeySignalMessage_GetSignedPreKeyId(long obj) throws Exception;
public static native int PreKeySignalMessage_GetVersion(long obj) throws Exception;
public static native long PreKeySignalMessage_New(int messageVersion, int registrationId, int preKeyId, int signedPreKeyId, long baseKey, long identityKey, long signalMessage) throws Exception;
public static native void ProfileKeyCiphertext_CheckValidContents(byte[] buffer);
public static native void ProfileKeyCiphertext_CheckValidContents(byte[] buffer) throws Exception;
public static native void ProfileKeyCommitment_CheckValidContents(byte[] buffer);
public static native void ProfileKeyCommitment_CheckValidContents(byte[] buffer) throws Exception;
public static native void ProfileKeyCredentialPresentation_CheckValidContents(byte[] presentationBytes);
public static native void ProfileKeyCredentialPresentation_CheckValidContents(byte[] presentationBytes) throws Exception;
public static native byte[] ProfileKeyCredentialPresentation_GetProfileKeyCiphertext(byte[] presentationBytes);
public static native byte[] ProfileKeyCredentialPresentation_GetStructurallyValidV1PresentationBytes(byte[] presentationBytes);
public static native byte[] ProfileKeyCredentialPresentation_GetUuidCiphertext(byte[] presentationBytes);
public static native void ProfileKeyCredentialRequestContext_CheckValidContents(byte[] buffer);
public static native void ProfileKeyCredentialRequestContext_CheckValidContents(byte[] buffer) throws Exception;
public static native byte[] ProfileKeyCredentialRequestContext_GetRequest(byte[] context);
public static native void ProfileKeyCredentialRequest_CheckValidContents(byte[] buffer);
public static native void ProfileKeyCredentialRequest_CheckValidContents(byte[] buffer) throws Exception;
public static native void ProfileKey_CheckValidContents(byte[] buffer);
public static native void ProfileKey_CheckValidContents(byte[] buffer) throws Exception;
public static native byte[] ProfileKey_DeriveAccessKey(byte[] profileKey);
public static native byte[] ProfileKey_GetCommitment(byte[] profileKey, byte[] userId);
public static native byte[] ProfileKey_GetProfileKeyVersion(byte[] profileKey, byte[] userId);
@ -418,19 +418,19 @@ public final class Native {
public static native String ProtocolAddress_Name(long obj);
public static native long ProtocolAddress_New(String name, int deviceId);
public static native void ReceiptCredentialPresentation_CheckValidContents(byte[] buffer);
public static native void ReceiptCredentialPresentation_CheckValidContents(byte[] buffer) throws Exception;
public static native long ReceiptCredentialPresentation_GetReceiptExpirationTime(byte[] presentation);
public static native long ReceiptCredentialPresentation_GetReceiptLevel(byte[] presentation);
public static native byte[] ReceiptCredentialPresentation_GetReceiptSerial(byte[] presentation);
public static native void ReceiptCredentialRequestContext_CheckValidContents(byte[] buffer);
public static native void ReceiptCredentialRequestContext_CheckValidContents(byte[] buffer) throws Exception;
public static native byte[] ReceiptCredentialRequestContext_GetRequest(byte[] requestContext);
public static native void ReceiptCredentialRequest_CheckValidContents(byte[] buffer);
public static native void ReceiptCredentialRequest_CheckValidContents(byte[] buffer) throws Exception;
public static native void ReceiptCredentialResponse_CheckValidContents(byte[] buffer);
public static native void ReceiptCredentialResponse_CheckValidContents(byte[] buffer) throws Exception;
public static native void ReceiptCredential_CheckValidContents(byte[] buffer);
public static native void ReceiptCredential_CheckValidContents(byte[] buffer) throws Exception;
public static native long ReceiptCredential_GetReceiptExpirationTime(byte[] receiptCredential);
public static native long ReceiptCredential_GetReceiptLevel(byte[] receiptCredential);
@ -439,154 +439,154 @@ public final class Native {
public static native long SanitizedMetadata_GetDataOffset(long sanitized);
public static native byte[] SanitizedMetadata_GetMetadata(long sanitized);
public static native boolean ScannableFingerprint_Compare(byte[] fprint1, byte[] fprint2);
public static native boolean ScannableFingerprint_Compare(byte[] fprint1, byte[] fprint2) throws Exception;
public static native Object SealedSender_MultiRecipientParseSentMessage(byte[] data);
public static native long SealedSessionCipher_DecryptToUsmc(byte[] ctext, IdentityKeyStore identityStore);
public static native byte[] SealedSessionCipher_Encrypt(long destination, long content, IdentityKeyStore identityKeyStore);
public static native byte[] SealedSessionCipher_MultiRecipientEncrypt(long[] recipients, long[] recipientSessions, byte[] excludedRecipients, long content, IdentityKeyStore identityKeyStore);
public static native byte[] SealedSessionCipher_MultiRecipientMessageForSingleRecipient(byte[] encodedMultiRecipientMessage);
public static native long SealedSessionCipher_DecryptToUsmc(byte[] ctext, IdentityKeyStore identityStore) throws Exception;
public static native byte[] SealedSessionCipher_Encrypt(long destination, long content, IdentityKeyStore identityKeyStore) throws Exception;
public static native byte[] SealedSessionCipher_MultiRecipientEncrypt(long[] recipients, long[] recipientSessions, byte[] excludedRecipients, long content, IdentityKeyStore identityKeyStore) throws Exception;
public static native byte[] SealedSessionCipher_MultiRecipientMessageForSingleRecipient(byte[] encodedMultiRecipientMessage) throws Exception;
public static native long SenderCertificate_Deserialize(byte[] data);
public static native long SenderCertificate_Deserialize(byte[] data) throws Exception;
public static native void SenderCertificate_Destroy(long handle);
public static native byte[] SenderCertificate_GetCertificate(long obj);
public static native int SenderCertificate_GetDeviceId(long obj);
public static native long SenderCertificate_GetExpiration(long obj);
public static native long SenderCertificate_GetKey(long obj);
public static native String SenderCertificate_GetSenderE164(long obj);
public static native String SenderCertificate_GetSenderUuid(long obj);
public static native byte[] SenderCertificate_GetSerialized(long obj);
public static native long SenderCertificate_GetServerCertificate(long cert);
public static native byte[] SenderCertificate_GetSignature(long obj);
public static native long SenderCertificate_New(String senderUuid, String senderE164, int senderDeviceId, long senderKey, long expiration, long signerCert, long signerKey);
public static native boolean SenderCertificate_Validate(long cert, long key, long time);
public static native byte[] SenderCertificate_GetCertificate(long obj) throws Exception;
public static native int SenderCertificate_GetDeviceId(long obj) throws Exception;
public static native long SenderCertificate_GetExpiration(long obj) throws Exception;
public static native long SenderCertificate_GetKey(long obj) throws Exception;
public static native String SenderCertificate_GetSenderE164(long obj) throws Exception;
public static native String SenderCertificate_GetSenderUuid(long obj) throws Exception;
public static native byte[] SenderCertificate_GetSerialized(long obj) throws Exception;
public static native long SenderCertificate_GetServerCertificate(long cert) throws Exception;
public static native byte[] SenderCertificate_GetSignature(long obj) throws Exception;
public static native long SenderCertificate_New(String senderUuid, String senderE164, int senderDeviceId, long senderKey, long expiration, long signerCert, long signerKey) throws Exception;
public static native boolean SenderCertificate_Validate(long cert, long key, long time) throws Exception;
public static native long SenderKeyDistributionMessage_Deserialize(byte[] data);
public static native long SenderKeyDistributionMessage_Deserialize(byte[] data) throws Exception;
public static native void SenderKeyDistributionMessage_Destroy(long handle);
public static native int SenderKeyDistributionMessage_GetChainId(long obj);
public static native byte[] SenderKeyDistributionMessage_GetChainKey(long obj);
public static native UUID SenderKeyDistributionMessage_GetDistributionId(long obj);
public static native int SenderKeyDistributionMessage_GetIteration(long obj);
public static native byte[] SenderKeyDistributionMessage_GetSerialized(long obj);
public static native long SenderKeyDistributionMessage_GetSignatureKey(long m);
public static native long SenderKeyDistributionMessage_New(int messageVersion, UUID distributionId, int chainId, int iteration, byte[] chainkey, long pk);
public static native int SenderKeyDistributionMessage_GetChainId(long obj) throws Exception;
public static native byte[] SenderKeyDistributionMessage_GetChainKey(long obj) throws Exception;
public static native UUID SenderKeyDistributionMessage_GetDistributionId(long obj) throws Exception;
public static native int SenderKeyDistributionMessage_GetIteration(long obj) throws Exception;
public static native byte[] SenderKeyDistributionMessage_GetSerialized(long obj) throws Exception;
public static native long SenderKeyDistributionMessage_GetSignatureKey(long m) throws Exception;
public static native long SenderKeyDistributionMessage_New(int messageVersion, UUID distributionId, int chainId, int iteration, byte[] chainkey, long pk) throws Exception;
public static native long SenderKeyMessage_Deserialize(byte[] data);
public static native long SenderKeyMessage_Deserialize(byte[] data) throws Exception;
public static native void SenderKeyMessage_Destroy(long handle);
public static native int SenderKeyMessage_GetChainId(long obj);
public static native byte[] SenderKeyMessage_GetCipherText(long obj);
public static native UUID SenderKeyMessage_GetDistributionId(long obj);
public static native int SenderKeyMessage_GetIteration(long obj);
public static native byte[] SenderKeyMessage_GetSerialized(long obj);
public static native long SenderKeyMessage_New(int messageVersion, UUID distributionId, int chainId, int iteration, byte[] ciphertext, long pk);
public static native boolean SenderKeyMessage_VerifySignature(long skm, long pubkey);
public static native int SenderKeyMessage_GetChainId(long obj) throws Exception;
public static native byte[] SenderKeyMessage_GetCipherText(long obj) throws Exception;
public static native UUID SenderKeyMessage_GetDistributionId(long obj) throws Exception;
public static native int SenderKeyMessage_GetIteration(long obj) throws Exception;
public static native byte[] SenderKeyMessage_GetSerialized(long obj) throws Exception;
public static native long SenderKeyMessage_New(int messageVersion, UUID distributionId, int chainId, int iteration, byte[] ciphertext, long pk) throws Exception;
public static native boolean SenderKeyMessage_VerifySignature(long skm, long pubkey) throws Exception;
public static native long SenderKeyRecord_Deserialize(byte[] data);
public static native long SenderKeyRecord_Deserialize(byte[] data) throws Exception;
public static native void SenderKeyRecord_Destroy(long handle);
public static native byte[] SenderKeyRecord_GetSerialized(long obj);
public static native byte[] SenderKeyRecord_GetSerialized(long obj) throws Exception;
public static native long ServerCertificate_Deserialize(byte[] data);
public static native long ServerCertificate_Deserialize(byte[] data) throws Exception;
public static native void ServerCertificate_Destroy(long handle);
public static native byte[] ServerCertificate_GetCertificate(long obj);
public static native long ServerCertificate_GetKey(long obj);
public static native int ServerCertificate_GetKeyId(long obj);
public static native byte[] ServerCertificate_GetSerialized(long obj);
public static native byte[] ServerCertificate_GetSignature(long obj);
public static native long ServerCertificate_New(int keyId, long serverKey, long trustRoot);
public static native byte[] ServerCertificate_GetCertificate(long obj) throws Exception;
public static native long ServerCertificate_GetKey(long obj) throws Exception;
public static native int ServerCertificate_GetKeyId(long obj) throws Exception;
public static native byte[] ServerCertificate_GetSerialized(long obj) throws Exception;
public static native byte[] ServerCertificate_GetSignature(long obj) throws Exception;
public static native long ServerCertificate_New(int keyId, long serverKey, long trustRoot) throws Exception;
public static native void ServerPublicParams_CheckValidContents(byte[] buffer);
public static native void ServerPublicParams_CheckValidContents(byte[] buffer) throws Exception;
public static native byte[] ServerPublicParams_CreateAuthCredentialPresentationDeterministic(byte[] serverPublicParams, byte[] randomness, byte[] groupSecretParams, byte[] authCredential);
public static native byte[] ServerPublicParams_CreateAuthCredentialWithPniPresentationDeterministic(byte[] serverPublicParams, byte[] randomness, byte[] groupSecretParams, byte[] authCredential);
public static native byte[] ServerPublicParams_CreateExpiringProfileKeyCredentialPresentationDeterministic(byte[] serverPublicParams, byte[] randomness, byte[] groupSecretParams, byte[] profileKeyCredential);
public static native byte[] ServerPublicParams_CreateProfileKeyCredentialRequestContextDeterministic(byte[] serverPublicParams, byte[] randomness, byte[] userId, byte[] profileKey);
public static native byte[] ServerPublicParams_CreateReceiptCredentialPresentationDeterministic(byte[] serverPublicParams, byte[] randomness, byte[] receiptCredential);
public static native byte[] ServerPublicParams_CreateReceiptCredentialRequestContextDeterministic(byte[] serverPublicParams, byte[] randomness, byte[] receiptSerial);
public static native byte[] ServerPublicParams_ReceiveAuthCredential(byte[] params, byte[] aci, int redemptionTime, byte[] response);
public static native byte[] ServerPublicParams_ReceiveAuthCredentialWithPniAsAci(byte[] params, byte[] aci, byte[] pni, long redemptionTime, byte[] response);
public static native byte[] ServerPublicParams_ReceiveAuthCredentialWithPniAsServiceId(byte[] params, byte[] aci, byte[] pni, long redemptionTime, byte[] response);
public static native byte[] ServerPublicParams_ReceiveExpiringProfileKeyCredential(byte[] serverPublicParams, byte[] requestContext, byte[] response, long currentTimeInSeconds);
public static native byte[] ServerPublicParams_ReceiveReceiptCredential(byte[] serverPublicParams, byte[] requestContext, byte[] response);
public static native void ServerPublicParams_VerifySignature(byte[] serverPublicParams, byte[] message, byte[] notarySignature);
public static native byte[] ServerPublicParams_ReceiveAuthCredential(byte[] params, byte[] aci, int redemptionTime, byte[] response) throws Exception;
public static native byte[] ServerPublicParams_ReceiveAuthCredentialWithPniAsAci(byte[] params, byte[] aci, byte[] pni, long redemptionTime, byte[] response) throws Exception;
public static native byte[] ServerPublicParams_ReceiveAuthCredentialWithPniAsServiceId(byte[] params, byte[] aci, byte[] pni, long redemptionTime, byte[] response) throws Exception;
public static native byte[] ServerPublicParams_ReceiveExpiringProfileKeyCredential(byte[] serverPublicParams, byte[] requestContext, byte[] response, long currentTimeInSeconds) throws Exception;
public static native byte[] ServerPublicParams_ReceiveReceiptCredential(byte[] serverPublicParams, byte[] requestContext, byte[] response) throws Exception;
public static native void ServerPublicParams_VerifySignature(byte[] serverPublicParams, byte[] message, byte[] notarySignature) throws Exception;
public static native void ServerSecretParams_CheckValidContents(byte[] buffer);
public static native void ServerSecretParams_CheckValidContents(byte[] buffer) throws Exception;
public static native byte[] ServerSecretParams_GenerateDeterministic(byte[] randomness);
public static native byte[] ServerSecretParams_GetPublicParams(byte[] params);
public static native byte[] ServerSecretParams_IssueAuthCredentialDeterministic(byte[] serverSecretParams, byte[] randomness, byte[] aci, int redemptionTime);
public static native byte[] ServerSecretParams_IssueAuthCredentialWithPniAsAciDeterministic(byte[] serverSecretParams, byte[] randomness, byte[] aci, byte[] pni, long redemptionTime);
public static native byte[] ServerSecretParams_IssueAuthCredentialWithPniAsServiceIdDeterministic(byte[] serverSecretParams, byte[] randomness, byte[] aci, byte[] pni, long redemptionTime);
public static native byte[] ServerSecretParams_IssueExpiringProfileKeyCredentialDeterministic(byte[] serverSecretParams, byte[] randomness, byte[] request, byte[] userId, byte[] commitment, long expirationInSeconds);
public static native byte[] ServerSecretParams_IssueExpiringProfileKeyCredentialDeterministic(byte[] serverSecretParams, byte[] randomness, byte[] request, byte[] userId, byte[] commitment, long expirationInSeconds) throws Exception;
public static native byte[] ServerSecretParams_IssueReceiptCredentialDeterministic(byte[] serverSecretParams, byte[] randomness, byte[] request, long receiptExpirationTime, long receiptLevel);
public static native byte[] ServerSecretParams_SignDeterministic(byte[] params, byte[] randomness, byte[] message);
public static native void ServerSecretParams_VerifyAuthCredentialPresentation(byte[] serverSecretParams, byte[] groupPublicParams, byte[] presentationBytes, long currentTimeInSeconds);
public static native void ServerSecretParams_VerifyProfileKeyCredentialPresentation(byte[] serverSecretParams, byte[] groupPublicParams, byte[] presentationBytes, long currentTimeInSeconds);
public static native void ServerSecretParams_VerifyReceiptCredentialPresentation(byte[] serverSecretParams, byte[] presentation);
public static native void ServerSecretParams_VerifyAuthCredentialPresentation(byte[] serverSecretParams, byte[] groupPublicParams, byte[] presentationBytes, long currentTimeInSeconds) throws Exception;
public static native void ServerSecretParams_VerifyProfileKeyCredentialPresentation(byte[] serverSecretParams, byte[] groupPublicParams, byte[] presentationBytes, long currentTimeInSeconds) throws Exception;
public static native void ServerSecretParams_VerifyReceiptCredentialPresentation(byte[] serverSecretParams, byte[] presentation) throws Exception;
public static native byte[] ServiceId_ParseFromServiceIdBinary(byte[] input);
public static native byte[] ServiceId_ParseFromServiceIdString(String input);
public static native byte[] ServiceId_ParseFromServiceIdBinary(byte[] input) throws Exception;
public static native byte[] ServiceId_ParseFromServiceIdString(String input) throws Exception;
public static native byte[] ServiceId_ServiceIdBinary(byte[] value);
public static native String ServiceId_ServiceIdLog(byte[] value);
public static native String ServiceId_ServiceIdString(byte[] value);
public static native void SessionBuilder_ProcessPreKeyBundle(long bundle, long protocolAddress, SessionStore sessionStore, IdentityKeyStore identityKeyStore, long now);
public static native void SessionBuilder_ProcessPreKeyBundle(long bundle, long protocolAddress, SessionStore sessionStore, IdentityKeyStore identityKeyStore, long now) throws Exception;
public static native byte[] SessionCipher_DecryptPreKeySignalMessage(long message, long protocolAddress, SessionStore sessionStore, IdentityKeyStore identityKeyStore, PreKeyStore prekeyStore, SignedPreKeyStore signedPrekeyStore, KyberPreKeyStore kyberPrekeyStore);
public static native byte[] SessionCipher_DecryptSignalMessage(long message, long protocolAddress, SessionStore sessionStore, IdentityKeyStore identityKeyStore);
public static native CiphertextMessage SessionCipher_EncryptMessage(byte[] ptext, long protocolAddress, SessionStore sessionStore, IdentityKeyStore identityKeyStore, long now);
public static native byte[] SessionCipher_DecryptPreKeySignalMessage(long message, long protocolAddress, SessionStore sessionStore, IdentityKeyStore identityKeyStore, PreKeyStore prekeyStore, SignedPreKeyStore signedPrekeyStore, KyberPreKeyStore kyberPrekeyStore) throws Exception;
public static native byte[] SessionCipher_DecryptSignalMessage(long message, long protocolAddress, SessionStore sessionStore, IdentityKeyStore identityKeyStore) throws Exception;
public static native CiphertextMessage SessionCipher_EncryptMessage(byte[] ptext, long protocolAddress, SessionStore sessionStore, IdentityKeyStore identityKeyStore, long now) throws Exception;
public static native void SessionRecord_ArchiveCurrentState(long sessionRecord);
public static native boolean SessionRecord_CurrentRatchetKeyMatches(long s, long key);
public static native long SessionRecord_Deserialize(byte[] data);
public static native void SessionRecord_ArchiveCurrentState(long sessionRecord) throws Exception;
public static native boolean SessionRecord_CurrentRatchetKeyMatches(long s, long key) throws Exception;
public static native long SessionRecord_Deserialize(byte[] data) throws Exception;
public static native void SessionRecord_Destroy(long handle);
public static native byte[] SessionRecord_GetAliceBaseKey(long obj);
public static native byte[] SessionRecord_GetLocalIdentityKeyPublic(long obj);
public static native int SessionRecord_GetLocalRegistrationId(long obj);
public static native byte[] SessionRecord_GetReceiverChainKeyValue(long sessionState, long key);
public static native byte[] SessionRecord_GetRemoteIdentityKeyPublic(long obj);
public static native int SessionRecord_GetRemoteRegistrationId(long obj);
public static native byte[] SessionRecord_GetSenderChainKeyValue(long obj);
public static native int SessionRecord_GetSessionVersion(long s);
public static native boolean SessionRecord_HasUsableSenderChain(long s, long now);
public static native long SessionRecord_InitializeAliceSession(long identityKeyPrivate, long identityKeyPublic, long basePrivate, long basePublic, long theirIdentityKey, long theirSignedPrekey, long theirRatchetKey);
public static native long SessionRecord_InitializeBobSession(long identityKeyPrivate, long identityKeyPublic, long signedPrekeyPrivate, long signedPrekeyPublic, long ephPrivate, long ephPublic, long theirIdentityKey, long theirBaseKey);
public static native byte[] SessionRecord_GetAliceBaseKey(long obj) throws Exception;
public static native byte[] SessionRecord_GetLocalIdentityKeyPublic(long obj) throws Exception;
public static native int SessionRecord_GetLocalRegistrationId(long obj) throws Exception;
public static native byte[] SessionRecord_GetReceiverChainKeyValue(long sessionState, long key) throws Exception;
public static native byte[] SessionRecord_GetRemoteIdentityKeyPublic(long obj) throws Exception;
public static native int SessionRecord_GetRemoteRegistrationId(long obj) throws Exception;
public static native byte[] SessionRecord_GetSenderChainKeyValue(long obj) throws Exception;
public static native int SessionRecord_GetSessionVersion(long s) throws Exception;
public static native boolean SessionRecord_HasUsableSenderChain(long s, long now) throws Exception;
public static native long SessionRecord_InitializeAliceSession(long identityKeyPrivate, long identityKeyPublic, long basePrivate, long basePublic, long theirIdentityKey, long theirSignedPrekey, long theirRatchetKey) throws Exception;
public static native long SessionRecord_InitializeBobSession(long identityKeyPrivate, long identityKeyPublic, long signedPrekeyPrivate, long signedPrekeyPublic, long ephPrivate, long ephPublic, long theirIdentityKey, long theirBaseKey) throws Exception;
public static native long SessionRecord_NewFresh();
public static native byte[] SessionRecord_Serialize(long obj);
public static native byte[] SessionRecord_Serialize(long obj) throws Exception;
public static native void SgxClientState_CompleteHandshake(long cli, byte[] handshakeReceived);
public static native void SgxClientState_CompleteHandshake(long cli, byte[] handshakeReceived) throws Exception;
public static native void SgxClientState_Destroy(long handle);
public static native byte[] SgxClientState_EstablishedRecv(long cli, byte[] receivedCiphertext);
public static native byte[] SgxClientState_EstablishedSend(long cli, byte[] plaintextToSend);
public static native byte[] SgxClientState_InitialRequest(long obj);
public static native byte[] SgxClientState_EstablishedRecv(long cli, byte[] receivedCiphertext) throws Exception;
public static native byte[] SgxClientState_EstablishedSend(long cli, byte[] plaintextToSend) throws Exception;
public static native byte[] SgxClientState_InitialRequest(long obj) throws Exception;
public static native void SignalMedia_CheckAvailable();
public static native long SignalMessage_Deserialize(byte[] data);
public static native long SignalMessage_Deserialize(byte[] data) throws Exception;
public static native void SignalMessage_Destroy(long handle);
public static native byte[] SignalMessage_GetBody(long obj);
public static native int SignalMessage_GetCounter(long obj);
public static native int SignalMessage_GetMessageVersion(long obj);
public static native byte[] SignalMessage_GetBody(long obj) throws Exception;
public static native int SignalMessage_GetCounter(long obj) throws Exception;
public static native int SignalMessage_GetMessageVersion(long obj) throws Exception;
public static native long SignalMessage_GetSenderRatchetKey(long m);
public static native byte[] SignalMessage_GetSerialized(long obj);
public static native long SignalMessage_New(int messageVersion, byte[] macKey, long senderRatchetKey, int counter, int previousCounter, byte[] ciphertext, long senderIdentityKey, long receiverIdentityKey);
public static native boolean SignalMessage_VerifyMac(long msg, long senderIdentityKey, long receiverIdentityKey, byte[] macKey);
public static native byte[] SignalMessage_GetSerialized(long obj) throws Exception;
public static native long SignalMessage_New(int messageVersion, byte[] macKey, long senderRatchetKey, int counter, int previousCounter, byte[] ciphertext, long senderIdentityKey, long receiverIdentityKey) throws Exception;
public static native boolean SignalMessage_VerifyMac(long msg, long senderIdentityKey, long receiverIdentityKey, byte[] macKey) throws Exception;
public static native long SignedPreKeyRecord_Deserialize(byte[] data);
public static native long SignedPreKeyRecord_Deserialize(byte[] data) throws Exception;
public static native void SignedPreKeyRecord_Destroy(long handle);
public static native int SignedPreKeyRecord_GetId(long obj);
public static native long SignedPreKeyRecord_GetPrivateKey(long obj);
public static native long SignedPreKeyRecord_GetPublicKey(long obj);
public static native byte[] SignedPreKeyRecord_GetSerialized(long obj);
public static native byte[] SignedPreKeyRecord_GetSignature(long obj);
public static native long SignedPreKeyRecord_GetTimestamp(long obj);
public static native int SignedPreKeyRecord_GetId(long obj) throws Exception;
public static native long SignedPreKeyRecord_GetPrivateKey(long obj) throws Exception;
public static native long SignedPreKeyRecord_GetPublicKey(long obj) throws Exception;
public static native byte[] SignedPreKeyRecord_GetSerialized(long obj) throws Exception;
public static native byte[] SignedPreKeyRecord_GetSignature(long obj) throws Exception;
public static native long SignedPreKeyRecord_GetTimestamp(long obj) throws Exception;
public static native long SignedPreKeyRecord_New(int id, long timestamp, long pubKey, long privKey, byte[] signature);
public static native long Svr2Client_New(byte[] mrenclave, byte[] attestationMsg, long currentTimestamp);
public static native long Svr2Client_New(byte[] mrenclave, byte[] attestationMsg, long currentTimestamp) throws Exception;
public static native CompletableFuture<byte[]> Svr3Backup(long asyncRuntime, long connectionManager, byte[] secret, String password, int maxTries, String username, String enclavePassword, int opTimeoutMs);
public static native CompletableFuture<byte[]> Svr3Restore(long asyncRuntime, long connectionManager, String password, byte[] shareSet, String username, String enclavePassword, int opTimeoutMs);
public static native void TESTING_CdsiLookupErrorConvert();
public static native void TESTING_CdsiLookupErrorConvert() throws Exception;
public static native CompletableFuture<Object> TESTING_CdsiLookupResponseConvert(long asyncRuntime);
public static native void TESTING_ErrorOnBorrowAsync(Object input);
public static native CompletableFuture TESTING_ErrorOnBorrowIo(long asyncRuntime, Object input);
@ -598,7 +598,7 @@ public final class Native {
public static native CompletableFuture<Long> TESTING_FutureProducesOtherPointerType(long asyncRuntime, String input);
public static native CompletableFuture<Long> TESTING_FutureProducesPointerType(long asyncRuntime, int input);
public static native CompletableFuture<Integer> TESTING_FutureSuccess(long asyncRuntime, int input);
public static native CompletableFuture TESTING_FutureThrowsCustomErrorType(long asyncRuntime);
public static native CompletableFuture<Void> TESTING_FutureThrowsCustomErrorType(long asyncRuntime);
public static native void TESTING_NonSuspendingBackgroundThreadRuntime_Destroy(long handle);
public static native String TESTING_OtherTestingHandleType_getValue(long handle);
public static native void TESTING_PanicInBodyAsync(Object input);
@ -621,33 +621,33 @@ public final class Native {
public static native void TokioAsyncContext_Destroy(long handle);
public static native long TokioAsyncContext_new();
public static native long UnidentifiedSenderMessageContent_Deserialize(byte[] data);
public static native long UnidentifiedSenderMessageContent_Deserialize(byte[] data) throws Exception;
public static native void UnidentifiedSenderMessageContent_Destroy(long handle);
public static native int UnidentifiedSenderMessageContent_GetContentHint(long m);
public static native byte[] UnidentifiedSenderMessageContent_GetContents(long obj);
public static native byte[] UnidentifiedSenderMessageContent_GetGroupId(long obj);
public static native int UnidentifiedSenderMessageContent_GetMsgType(long m);
public static native long UnidentifiedSenderMessageContent_GetSenderCert(long m);
public static native byte[] UnidentifiedSenderMessageContent_GetSerialized(long obj);
public static native long UnidentifiedSenderMessageContent_New(CiphertextMessage message, long sender, int contentHint, byte[] groupId);
public static native int UnidentifiedSenderMessageContent_GetContentHint(long m) throws Exception;
public static native byte[] UnidentifiedSenderMessageContent_GetContents(long obj) throws Exception;
public static native byte[] UnidentifiedSenderMessageContent_GetGroupId(long obj) throws Exception;
public static native int UnidentifiedSenderMessageContent_GetMsgType(long m) throws Exception;
public static native long UnidentifiedSenderMessageContent_GetSenderCert(long m) throws Exception;
public static native byte[] UnidentifiedSenderMessageContent_GetSerialized(long obj) throws Exception;
public static native long UnidentifiedSenderMessageContent_New(CiphertextMessage message, long sender, int contentHint, byte[] groupId) throws Exception;
public static native byte[] UsernameLink_Create(String username, byte[] entropy);
public static native String UsernameLink_DecryptUsername(byte[] entropy, byte[] encryptedUsername);
public static native byte[] UsernameLink_Create(String username, byte[] entropy) throws Exception;
public static native String UsernameLink_DecryptUsername(byte[] entropy, byte[] encryptedUsername) throws Exception;
public static native Object[] Username_CandidatesFrom(String nickname, int minLen, int maxLen);
public static native byte[] Username_Hash(String username);
public static native byte[] Username_HashFromParts(String nickname, String discriminator, int minLen, int maxLen);
public static native byte[] Username_Proof(String username, byte[] randomness);
public static native void Username_Verify(byte[] proof, byte[] hash);
public static native Object[] Username_CandidatesFrom(String nickname, int minLen, int maxLen) throws Exception;
public static native byte[] Username_Hash(String username) throws Exception;
public static native byte[] Username_HashFromParts(String nickname, String discriminator, int minLen, int maxLen) throws Exception;
public static native byte[] Username_Proof(String username, byte[] randomness) throws Exception;
public static native void Username_Verify(byte[] proof, byte[] hash) throws Exception;
public static native void UuidCiphertext_CheckValidContents(byte[] buffer);
public static native void UuidCiphertext_CheckValidContents(byte[] buffer) throws Exception;
public static native void ValidatingMac_Destroy(long handle);
public static native int ValidatingMac_Finalize(long mac);
public static native long ValidatingMac_Initialize(byte[] key, int chunkSize, byte[] digests);
public static native int ValidatingMac_Update(long mac, byte[] bytes, int offset, int length);
public static native void WebpSanitizer_Sanitize(InputStream input);
public static native void WebpSanitizer_Sanitize(InputStream input) throws Exception;
public static native void preloadClasses();
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.ecc.Curve;
@ -51,8 +53,10 @@ public class IdentityKey {
public boolean verifyAlternateIdentity(IdentityKey other, byte[] signature) {
try (NativeHandleGuard guard = new NativeHandleGuard(this.publicKey);
NativeHandleGuard otherGuard = new NativeHandleGuard(other.publicKey); ) {
return Native.IdentityKey_VerifyAlternateIdentity(
guard.nativeHandle(), otherGuard.nativeHandle(), signature);
return filterExceptions(
() ->
Native.IdentityKey_VerifyAlternateIdentity(
guard.nativeHandle(), otherGuard.nativeHandle(), signature));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.ecc.Curve;
@ -61,8 +63,10 @@ public class IdentityKeyPair {
try (NativeHandleGuard publicKey = new NativeHandleGuard(this.publicKey.getPublicKey());
NativeHandleGuard privateKey = new NativeHandleGuard(this.privateKey);
NativeHandleGuard otherPublic = new NativeHandleGuard(other.getPublicKey()); ) {
return Native.IdentityKeyPair_SignAlternateIdentity(
publicKey.nativeHandle(), privateKey.nativeHandle(), otherPublic.nativeHandle());
return filterExceptions(
() ->
Native.IdentityKeyPair_SignAlternateIdentity(
publicKey.nativeHandle(), privateKey.nativeHandle(), otherPublic.nativeHandle()));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
@ -85,7 +87,7 @@ public abstract class ServiceId {
}
byte[] storage;
try {
storage = Native.ServiceId_ParseFromServiceIdString(serviceIdString);
storage = filterExceptions(() -> Native.ServiceId_ParseFromServiceIdString(serviceIdString));
} catch (IllegalArgumentException ex) {
throw new InvalidServiceIdException();
}
@ -98,7 +100,7 @@ public abstract class ServiceId {
}
byte[] storage;
try {
storage = Native.ServiceId_ParseFromServiceIdBinary(serviceIdBinary);
storage = filterExceptions(() -> Native.ServiceId_ParseFromServiceIdBinary(serviceIdBinary));
} catch (IllegalArgumentException ex) {
throw new InvalidServiceIdException();
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -110,12 +112,16 @@ public class SessionBuilder {
throws InvalidKeyException, UntrustedIdentityException {
try (NativeHandleGuard preKeyGuard = new NativeHandleGuard(preKey);
NativeHandleGuard remoteAddressGuard = new NativeHandleGuard(this.remoteAddress)) {
Native.SessionBuilder_ProcessPreKeyBundle(
preKeyGuard.nativeHandle(),
remoteAddressGuard.nativeHandle(),
sessionStore,
identityKeyStore,
now.toEpochMilli());
filterExceptions(
InvalidKeyException.class,
UntrustedIdentityException.class,
() ->
Native.SessionBuilder_ProcessPreKeyBundle(
preKeyGuard.nativeHandle(),
remoteAddressGuard.nativeHandle(),
sessionStore,
identityKeyStore,
now.toEpochMilli()));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -94,12 +96,16 @@ public class SessionCipher {
public CiphertextMessage encrypt(byte[] paddedMessage, Instant now)
throws NoSessionException, UntrustedIdentityException {
try (NativeHandleGuard remoteAddress = new NativeHandleGuard(this.remoteAddress)) {
return Native.SessionCipher_EncryptMessage(
paddedMessage,
remoteAddress.nativeHandle(),
sessionStore,
identityKeyStore,
now.toEpochMilli());
return filterExceptions(
NoSessionException.class,
UntrustedIdentityException.class,
() ->
Native.SessionCipher_EncryptMessage(
paddedMessage,
remoteAddress.nativeHandle(),
sessionStore,
identityKeyStore,
now.toEpochMilli()));
}
}
@ -124,14 +130,21 @@ public class SessionCipher {
UntrustedIdentityException {
try (NativeHandleGuard ciphertextGuard = new NativeHandleGuard(ciphertext);
NativeHandleGuard remoteAddressGuard = new NativeHandleGuard(this.remoteAddress); ) {
return Native.SessionCipher_DecryptPreKeySignalMessage(
ciphertextGuard.nativeHandle(),
remoteAddressGuard.nativeHandle(),
sessionStore,
identityKeyStore,
preKeyStore,
signedPreKeyStore,
kyberPreKeyStore);
return filterExceptions(
DuplicateMessageException.class,
InvalidMessageException.class,
InvalidKeyIdException.class,
InvalidKeyException.class,
UntrustedIdentityException.class,
() ->
Native.SessionCipher_DecryptPreKeySignalMessage(
ciphertextGuard.nativeHandle(),
remoteAddressGuard.nativeHandle(),
sessionStore,
identityKeyStore,
preKeyStore,
signedPreKeyStore,
kyberPreKeyStore));
}
}
@ -153,11 +166,18 @@ public class SessionCipher {
UntrustedIdentityException {
try (NativeHandleGuard ciphertextGuard = new NativeHandleGuard(ciphertext);
NativeHandleGuard remoteAddressGuard = new NativeHandleGuard(this.remoteAddress); ) {
return Native.SessionCipher_DecryptSignalMessage(
ciphertextGuard.nativeHandle(),
remoteAddressGuard.nativeHandle(),
sessionStore,
identityKeyStore);
return filterExceptions(
InvalidMessageException.class,
InvalidVersionException.class,
DuplicateMessageException.class,
NoSessionException.class,
UntrustedIdentityException.class,
() ->
Native.SessionCipher_DecryptSignalMessage(
ciphertextGuard.nativeHandle(),
remoteAddressGuard.nativeHandle(),
sessionStore,
identityKeyStore));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.ecc;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidKeyException;
@ -17,7 +19,9 @@ public class ECPrivateKey implements NativeHandleGuard.Owner {
}
ECPrivateKey(byte[] privateKey) throws InvalidKeyException {
this.unsafeHandle = Native.ECPrivateKey_Deserialize(privateKey);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class, () -> Native.ECPrivateKey_Deserialize(privateKey));
}
public ECPrivateKey(long nativeHandle) {
@ -35,20 +39,21 @@ public class ECPrivateKey implements NativeHandleGuard.Owner {
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ECPrivateKey_Serialize(guard.nativeHandle());
return filterExceptions(() -> Native.ECPrivateKey_Serialize(guard.nativeHandle()));
}
}
public byte[] calculateSignature(byte[] message) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ECPrivateKey_Sign(guard.nativeHandle(), message);
return filterExceptions(() -> Native.ECPrivateKey_Sign(guard.nativeHandle(), message));
}
}
public byte[] calculateAgreement(ECPublicKey other) {
try (NativeHandleGuard privateKey = new NativeHandleGuard(this);
NativeHandleGuard publicKey = new NativeHandleGuard(other); ) {
return Native.ECPrivateKey_Agree(privateKey.nativeHandle(), publicKey.nativeHandle());
return filterExceptions(
() -> Native.ECPrivateKey_Agree(privateKey.nativeHandle(), publicKey.nativeHandle()));
}
}
@ -58,7 +63,8 @@ public class ECPrivateKey implements NativeHandleGuard.Owner {
public ECPublicKey publicKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new ECPublicKey(Native.ECPrivateKey_GetPublicKey(guard.nativeHandle()));
return new ECPublicKey(
filterExceptions(() -> Native.ECPrivateKey_GetPublicKey(guard.nativeHandle())));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.ecc;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Arrays;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -17,18 +19,22 @@ public class ECPublicKey implements Comparable<ECPublicKey>, NativeHandleGuard.O
private final long unsafeHandle;
public ECPublicKey(byte[] serialized, int offset) throws InvalidKeyException {
this.unsafeHandle = Native.ECPublicKey_Deserialize(serialized, offset);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class, () -> Native.ECPublicKey_Deserialize(serialized, offset));
}
public ECPublicKey(byte[] serialized) throws InvalidKeyException {
this.unsafeHandle = Native.ECPublicKey_Deserialize(serialized, 0);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class, () -> Native.ECPublicKey_Deserialize(serialized, 0));
}
public static ECPublicKey fromPublicKeyBytes(byte[] key) {
byte[] with_type = new byte[33];
with_type[0] = 0x05;
System.arraycopy(key, 0, with_type, 1, 32);
return new ECPublicKey(Native.ECPublicKey_Deserialize(with_type, 0));
return new ECPublicKey(filterExceptions(() -> Native.ECPublicKey_Deserialize(with_type, 0)));
}
public ECPublicKey(long nativeHandle) {
@ -46,19 +52,20 @@ public class ECPublicKey implements Comparable<ECPublicKey>, NativeHandleGuard.O
public boolean verifySignature(byte[] message, byte[] signature) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ECPublicKey_Verify(guard.nativeHandle(), message, signature);
return filterExceptions(
() -> Native.ECPublicKey_Verify(guard.nativeHandle(), message, signature));
}
}
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ECPublicKey_Serialize(guard.nativeHandle());
return filterExceptions(() -> Native.ECPublicKey_Serialize(guard.nativeHandle()));
}
}
public byte[] getPublicKeyBytes() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ECPublicKey_GetPublicKeyBytes(guard.nativeHandle());
return filterExceptions(() -> Native.ECPublicKey_GetPublicKeyBytes(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.fingerprint;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.protocol.IdentityKey;
@ -45,23 +47,28 @@ public class NumericFingerprintGenerator implements FingerprintGenerator {
byte[] remoteStableIdentifier,
final IdentityKey remoteIdentityKey) {
long handle =
Native.NumericFingerprintGenerator_New(
this.iterations,
version,
localStableIdentifier,
localIdentityKey.serialize(),
remoteStableIdentifier,
remoteIdentityKey.serialize());
return filterExceptions(
() -> {
long handle =
Native.NumericFingerprintGenerator_New(
this.iterations,
version,
localStableIdentifier,
localIdentityKey.serialize(),
remoteStableIdentifier,
remoteIdentityKey.serialize());
DisplayableFingerprint displayableFingerprint =
new DisplayableFingerprint(Native.NumericFingerprintGenerator_GetDisplayString(handle));
DisplayableFingerprint displayableFingerprint =
new DisplayableFingerprint(
Native.NumericFingerprintGenerator_GetDisplayString(handle));
ScannableFingerprint scannableFingerprint =
new ScannableFingerprint(Native.NumericFingerprintGenerator_GetScannableEncoding(handle));
ScannableFingerprint scannableFingerprint =
new ScannableFingerprint(
Native.NumericFingerprintGenerator_GetScannableEncoding(handle));
Native.NumericFingerprintGenerator_Destroy(handle);
Native.NumericFingerprintGenerator_Destroy(handle);
return new Fingerprint(displayableFingerprint, scannableFingerprint);
return new Fingerprint(displayableFingerprint, scannableFingerprint);
});
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.fingerprint;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
public class ScannableFingerprint {
@ -30,6 +32,9 @@ public class ScannableFingerprint {
*/
public boolean compareTo(byte[] scannedFingerprintData)
throws FingerprintVersionMismatchException, FingerprintParsingException {
return Native.ScannableFingerprint_Compare(this.encodedFingerprint, scannedFingerprintData);
return filterExceptions(
FingerprintVersionMismatchException.class,
FingerprintParsingException.class,
() -> Native.ScannableFingerprint_Compare(this.encodedFingerprint, scannedFingerprintData));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.groups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.UUID;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -49,8 +51,11 @@ public class GroupCipher {
public CiphertextMessage encrypt(UUID distributionId, byte[] paddedPlaintext)
throws NoSessionException {
try (NativeHandleGuard sender = new NativeHandleGuard(this.sender)) {
return Native.GroupCipher_EncryptMessage(
sender.nativeHandle(), distributionId, paddedPlaintext, this.senderKeyStore);
return filterExceptions(
NoSessionException.class,
() ->
Native.GroupCipher_EncryptMessage(
sender.nativeHandle(), distributionId, paddedPlaintext, this.senderKeyStore));
}
}
@ -69,8 +74,14 @@ public class GroupCipher {
InvalidMessageException,
NoSessionException {
try (NativeHandleGuard sender = new NativeHandleGuard(this.sender)) {
return Native.GroupCipher_DecryptMessage(
sender.nativeHandle(), senderKeyMessageBytes, this.senderKeyStore);
return filterExceptions(
LegacyMessageException.class,
DuplicateMessageException.class,
InvalidMessageException.class,
NoSessionException.class,
() ->
Native.GroupCipher_DecryptMessage(
sender.nativeHandle(), senderKeyMessageBytes, this.senderKeyStore));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.groups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.UUID;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -46,8 +48,10 @@ public class GroupSessionBuilder {
SignalProtocolAddress sender, SenderKeyDistributionMessage senderKeyDistributionMessage) {
try (NativeHandleGuard senderGuard = new NativeHandleGuard(sender);
NativeHandleGuard skdmGuard = new NativeHandleGuard(senderKeyDistributionMessage); ) {
Native.GroupSessionBuilder_ProcessSenderKeyDistributionMessage(
senderGuard.nativeHandle(), skdmGuard.nativeHandle(), senderKeyStore);
filterExceptions(
() ->
Native.GroupSessionBuilder_ProcessSenderKeyDistributionMessage(
senderGuard.nativeHandle(), skdmGuard.nativeHandle(), senderKeyStore));
}
}
@ -63,8 +67,10 @@ public class GroupSessionBuilder {
public SenderKeyDistributionMessage create(SignalProtocolAddress sender, UUID distributionId) {
try (NativeHandleGuard senderGuard = new NativeHandleGuard(sender)) {
return new SenderKeyDistributionMessage(
Native.GroupSessionBuilder_CreateSenderKeyDistributionMessage(
senderGuard.nativeHandle(), distributionId, senderKeyStore));
filterExceptions(
() ->
Native.GroupSessionBuilder_CreateSenderKeyDistributionMessage(
senderGuard.nativeHandle(), distributionId, senderKeyStore)));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.groups.state;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidMessageException;
@ -30,12 +32,14 @@ public class SenderKeyRecord implements NativeHandleGuard.Owner {
// FIXME: This shouldn't be considered a "message".
public SenderKeyRecord(byte[] serialized) throws InvalidMessageException {
this.unsafeHandle = Native.SenderKeyRecord_Deserialize(serialized);
this.unsafeHandle =
filterExceptions(
InvalidMessageException.class, () -> Native.SenderKeyRecord_Deserialize(serialized));
}
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyRecord_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.SenderKeyRecord_GetSerialized(guard.nativeHandle()));
}
}

View File

@ -5,15 +5,19 @@
package org.signal.libsignal.protocol.kdf;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
public abstract class HKDF {
public static byte[] deriveSecrets(byte[] inputKeyMaterial, byte[] info, int outputLength) {
return Native.HKDF_DeriveSecrets(outputLength, inputKeyMaterial, info, null);
return filterExceptions(
() -> Native.HKDF_DeriveSecrets(outputLength, inputKeyMaterial, info, null));
}
public static byte[] deriveSecrets(
byte[] inputKeyMaterial, byte[] salt, byte[] info, int outputLength) {
return Native.HKDF_DeriveSecrets(outputLength, inputKeyMaterial, info, salt);
return filterExceptions(
() -> Native.HKDF_DeriveSecrets(outputLength, inputKeyMaterial, info, salt));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.kem;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Arrays;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -15,11 +17,17 @@ public class KEMPublicKey implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public KEMPublicKey(byte[] serialized, int offset) throws InvalidKeyException {
this.unsafeHandle = Native.KyberPublicKey_DeserializeWithOffset(serialized, offset);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class,
() -> Native.KyberPublicKey_DeserializeWithOffset(serialized, offset));
}
public KEMPublicKey(byte[] serialized) throws InvalidKeyException {
this.unsafeHandle = Native.KyberPublicKey_DeserializeWithOffset(serialized, 0);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class,
() -> Native.KyberPublicKey_DeserializeWithOffset(serialized, 0));
}
public KEMPublicKey(long nativeHandle) {
@ -37,7 +45,7 @@ public class KEMPublicKey implements NativeHandleGuard.Owner {
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.KyberPublicKey_Serialize(guard.nativeHandle());
return filterExceptions(() -> Native.KyberPublicKey_Serialize(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.kem;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidKeyException;
@ -13,7 +15,9 @@ public class KEMSecretKey implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public KEMSecretKey(byte[] privateKey) throws InvalidKeyException {
this.unsafeHandle = Native.KyberSecretKey_Deserialize(privateKey);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class, () -> Native.KyberSecretKey_Deserialize(privateKey));
}
public KEMSecretKey(long nativeHandle) {
@ -31,7 +35,7 @@ public class KEMSecretKey implements NativeHandleGuard.Owner {
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.KyberSecretKey_Serialize(guard.nativeHandle());
return filterExceptions(() -> Native.KyberSecretKey_Serialize(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.message;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Optional;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -32,19 +34,26 @@ public final class DecryptionErrorMessage implements NativeHandleGuard.Owner {
public DecryptionErrorMessage(byte[] serialized)
throws InvalidKeyException, InvalidMessageException {
this.unsafeHandle = Native.DecryptionErrorMessage_Deserialize(serialized);
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class,
InvalidMessageException.class,
() -> Native.DecryptionErrorMessage_Deserialize(serialized));
}
public static DecryptionErrorMessage forOriginalMessage(
byte[] originalBytes, int messageType, long timestamp, int originalSenderDeviceId) {
return new DecryptionErrorMessage(
Native.DecryptionErrorMessage_ForOriginalMessage(
originalBytes, messageType, timestamp, originalSenderDeviceId));
filterExceptions(
() ->
Native.DecryptionErrorMessage_ForOriginalMessage(
originalBytes, messageType, timestamp, originalSenderDeviceId)));
}
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.DecryptionErrorMessage_GetSerialized(guard.nativeHandle());
return filterExceptions(
() -> Native.DecryptionErrorMessage_GetSerialized(guard.nativeHandle()));
}
}
@ -61,13 +70,15 @@ public final class DecryptionErrorMessage implements NativeHandleGuard.Owner {
public long getTimestamp() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.DecryptionErrorMessage_GetTimestamp(guard.nativeHandle());
return filterExceptions(
() -> Native.DecryptionErrorMessage_GetTimestamp(guard.nativeHandle()));
}
}
public int getDeviceId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.DecryptionErrorMessage_GetDeviceId(guard.nativeHandle());
return filterExceptions(
() -> Native.DecryptionErrorMessage_GetDeviceId(guard.nativeHandle()));
}
}
@ -75,6 +86,10 @@ public final class DecryptionErrorMessage implements NativeHandleGuard.Owner {
public static DecryptionErrorMessage extractFromSerializedContent(byte[] serializedContentBytes)
throws InvalidMessageException {
return new DecryptionErrorMessage(
Native.DecryptionErrorMessage_ExtractFromSerializedContent(serializedContentBytes));
filterExceptions(
InvalidMessageException.class,
() ->
Native.DecryptionErrorMessage_ExtractFromSerializedContent(
serializedContentBytes)));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.message;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidMessageException;
@ -39,13 +41,17 @@ public final class PlaintextContent implements CiphertextMessage, NativeHandleGu
public PlaintextContent(byte[] serialized)
throws InvalidMessageException, InvalidVersionException {
unsafeHandle = Native.PlaintextContent_Deserialize(serialized);
unsafeHandle =
filterExceptions(
InvalidMessageException.class,
InvalidVersionException.class,
() -> Native.PlaintextContent_Deserialize(serialized));
}
@Override
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PlaintextContent_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.PlaintextContent_GetSerialized(guard.nativeHandle()));
}
}
@ -56,7 +62,7 @@ public final class PlaintextContent implements CiphertextMessage, NativeHandleGu
public byte[] getBody() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PlaintextContent_GetBody(guard.nativeHandle());
return filterExceptions(() -> Native.PlaintextContent_GetBody(guard.nativeHandle()));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.message;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Optional;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -30,7 +32,13 @@ public class PreKeySignalMessage implements CiphertextMessage, NativeHandleGuard
InvalidVersionException,
LegacyMessageException,
InvalidKeyException {
this.unsafeHandle = Native.PreKeySignalMessage_Deserialize(serialized);
this.unsafeHandle =
filterExceptions(
InvalidMessageException.class,
InvalidVersionException.class,
LegacyMessageException.class,
InvalidKeyException.class,
() -> Native.PreKeySignalMessage_Deserialize(serialized));
}
public PreKeySignalMessage(long unsafeHandle) {
@ -39,25 +47,28 @@ public class PreKeySignalMessage implements CiphertextMessage, NativeHandleGuard
public int getMessageVersion() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeySignalMessage_GetVersion(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeySignalMessage_GetVersion(guard.nativeHandle()));
}
}
public IdentityKey getIdentityKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new IdentityKey(Native.PreKeySignalMessage_GetIdentityKey(guard.nativeHandle()));
return new IdentityKey(
filterExceptions(() -> Native.PreKeySignalMessage_GetIdentityKey(guard.nativeHandle())));
}
}
public int getRegistrationId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeySignalMessage_GetRegistrationId(guard.nativeHandle());
return filterExceptions(
() -> Native.PreKeySignalMessage_GetRegistrationId(guard.nativeHandle()));
}
}
public Optional<Integer> getPreKeyId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
int pre_key = Native.PreKeySignalMessage_GetPreKeyId(guard.nativeHandle());
int pre_key =
filterExceptions(() -> Native.PreKeySignalMessage_GetPreKeyId(guard.nativeHandle()));
if (pre_key < 0) {
return Optional.empty();
} else {
@ -68,7 +79,8 @@ public class PreKeySignalMessage implements CiphertextMessage, NativeHandleGuard
public int getSignedPreKeyId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeySignalMessage_GetSignedPreKeyId(guard.nativeHandle());
return filterExceptions(
() -> Native.PreKeySignalMessage_GetSignedPreKeyId(guard.nativeHandle()));
}
}
@ -87,7 +99,7 @@ public class PreKeySignalMessage implements CiphertextMessage, NativeHandleGuard
@Override
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeySignalMessage_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeySignalMessage_GetSerialized(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.message;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.UUID;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -33,43 +35,55 @@ public class SenderKeyDistributionMessage implements NativeHandleGuard.Owner {
InvalidVersionException,
LegacyMessageException,
InvalidKeyException {
unsafeHandle = Native.SenderKeyDistributionMessage_Deserialize(serialized);
unsafeHandle =
filterExceptions(
InvalidMessageException.class,
InvalidVersionException.class,
LegacyMessageException.class,
InvalidKeyException.class,
() -> Native.SenderKeyDistributionMessage_Deserialize(serialized));
}
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyDistributionMessage_GetSerialized(guard.nativeHandle());
return filterExceptions(
() -> Native.SenderKeyDistributionMessage_GetSerialized(guard.nativeHandle()));
}
}
public UUID getDistributionId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyDistributionMessage_GetDistributionId(guard.nativeHandle());
return filterExceptions(
() -> Native.SenderKeyDistributionMessage_GetDistributionId(guard.nativeHandle()));
}
}
public int getIteration() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyDistributionMessage_GetIteration(guard.nativeHandle());
return filterExceptions(
() -> Native.SenderKeyDistributionMessage_GetIteration(guard.nativeHandle()));
}
}
public byte[] getChainKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyDistributionMessage_GetChainKey(guard.nativeHandle());
return filterExceptions(
() -> Native.SenderKeyDistributionMessage_GetChainKey(guard.nativeHandle()));
}
}
public ECPublicKey getSignatureKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new ECPublicKey(
Native.SenderKeyDistributionMessage_GetSignatureKey(guard.nativeHandle()));
filterExceptions(
() -> Native.SenderKeyDistributionMessage_GetSignatureKey(guard.nativeHandle())));
}
}
public int getChainId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyDistributionMessage_GetChainId(guard.nativeHandle());
return filterExceptions(
() -> Native.SenderKeyDistributionMessage_GetChainId(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.message;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.UUID;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -33,37 +35,47 @@ public class SenderKeyMessage implements CiphertextMessage, NativeHandleGuard.Ow
public SenderKeyMessage(byte[] serialized)
throws InvalidMessageException, InvalidVersionException, LegacyMessageException {
unsafeHandle = Native.SenderKeyMessage_Deserialize(serialized);
unsafeHandle =
filterExceptions(
InvalidMessageException.class,
InvalidVersionException.class,
LegacyMessageException.class,
() -> Native.SenderKeyMessage_Deserialize(serialized));
}
public UUID getDistributionId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyMessage_GetDistributionId(guard.nativeHandle());
return filterExceptions(
() -> Native.SenderKeyMessage_GetDistributionId(guard.nativeHandle()));
}
}
public int getChainId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyMessage_GetChainId(guard.nativeHandle());
return filterExceptions(() -> Native.SenderKeyMessage_GetChainId(guard.nativeHandle()));
}
}
public int getIteration() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyMessage_GetIteration(guard.nativeHandle());
return filterExceptions(() -> Native.SenderKeyMessage_GetIteration(guard.nativeHandle()));
}
}
public byte[] getCipherText() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyMessage_GetCipherText(guard.nativeHandle());
return filterExceptions(() -> Native.SenderKeyMessage_GetCipherText(guard.nativeHandle()));
}
}
public void verifySignature(ECPublicKey signatureKey) throws InvalidMessageException {
try (NativeHandleGuard guard = new NativeHandleGuard(this);
NativeHandleGuard keyGuard = new NativeHandleGuard(signatureKey); ) {
if (!Native.SenderKeyMessage_VerifySignature(guard.nativeHandle(), keyGuard.nativeHandle())) {
if (!filterExceptions(
InvalidMessageException.class,
() ->
Native.SenderKeyMessage_VerifySignature(
guard.nativeHandle(), keyGuard.nativeHandle()))) {
throw new InvalidMessageException("Invalid signature!");
}
}
@ -72,7 +84,7 @@ public class SenderKeyMessage implements CiphertextMessage, NativeHandleGuard.Ow
@Override
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderKeyMessage_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.SenderKeyMessage_GetSerialized(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.message;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import javax.crypto.spec.SecretKeySpec;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -30,7 +32,13 @@ public class SignalMessage implements CiphertextMessage, NativeHandleGuard.Owner
InvalidVersionException,
InvalidKeyException,
LegacyMessageException {
unsafeHandle = Native.SignalMessage_Deserialize(serialized);
unsafeHandle =
filterExceptions(
InvalidMessageException.class,
InvalidVersionException.class,
InvalidKeyException.class,
LegacyMessageException.class,
() -> Native.SignalMessage_Deserialize(serialized));
}
public SignalMessage(long unsafeHandle) {
@ -39,25 +47,26 @@ public class SignalMessage implements CiphertextMessage, NativeHandleGuard.Owner
public ECPublicKey getSenderRatchetKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new ECPublicKey(Native.SignalMessage_GetSenderRatchetKey(guard.nativeHandle()));
return new ECPublicKey(
filterExceptions(() -> Native.SignalMessage_GetSenderRatchetKey(guard.nativeHandle())));
}
}
public int getMessageVersion() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SignalMessage_GetMessageVersion(guard.nativeHandle());
return filterExceptions(() -> Native.SignalMessage_GetMessageVersion(guard.nativeHandle()));
}
}
public int getCounter() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SignalMessage_GetCounter(guard.nativeHandle());
return filterExceptions(() -> Native.SignalMessage_GetCounter(guard.nativeHandle()));
}
}
public byte[] getBody() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SignalMessage_GetBody(guard.nativeHandle());
return filterExceptions(() -> Native.SignalMessage_GetBody(guard.nativeHandle()));
}
}
@ -69,11 +78,15 @@ public class SignalMessage implements CiphertextMessage, NativeHandleGuard.Owner
new NativeHandleGuard(senderIdentityKey.getPublicKey());
NativeHandleGuard receiverIdentityGuard =
new NativeHandleGuard(receiverIdentityKey.getPublicKey()); ) {
if (!Native.SignalMessage_VerifyMac(
guard.nativeHandle(),
senderIdentityGuard.nativeHandle(),
receiverIdentityGuard.nativeHandle(),
macKey.getEncoded())) {
if (!filterExceptions(
InvalidMessageException.class,
InvalidKeyException.class,
() ->
Native.SignalMessage_VerifyMac(
guard.nativeHandle(),
senderIdentityGuard.nativeHandle(),
receiverIdentityGuard.nativeHandle(),
macKey.getEncoded()))) {
throw new InvalidMessageException("Bad Mac!");
}
}
@ -82,7 +95,7 @@ public class SignalMessage implements CiphertextMessage, NativeHandleGuard.Owner
@Override
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SignalMessage_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.SignalMessage_GetSerialized(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.metadata.certificate;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Optional;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -39,31 +41,34 @@ public class SenderCertificate implements NativeHandleGuard.Owner {
public ServerCertificate getSigner() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new ServerCertificate(
Native.SenderCertificate_GetServerCertificate(guard.nativeHandle()));
filterExceptions(
() -> Native.SenderCertificate_GetServerCertificate(guard.nativeHandle())));
}
}
public ECPublicKey getKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new ECPublicKey(Native.SenderCertificate_GetKey(guard.nativeHandle()));
return new ECPublicKey(
filterExceptions(() -> Native.SenderCertificate_GetKey(guard.nativeHandle())));
}
}
public int getSenderDeviceId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderCertificate_GetDeviceId(guard.nativeHandle());
return filterExceptions(() -> Native.SenderCertificate_GetDeviceId(guard.nativeHandle()));
}
}
public String getSenderUuid() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderCertificate_GetSenderUuid(guard.nativeHandle());
return filterExceptions(() -> Native.SenderCertificate_GetSenderUuid(guard.nativeHandle()));
}
}
public Optional<String> getSenderE164() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Optional.ofNullable(Native.SenderCertificate_GetSenderE164(guard.nativeHandle()));
return Optional.ofNullable(
filterExceptions(() -> Native.SenderCertificate_GetSenderE164(guard.nativeHandle())));
}
}
@ -86,25 +91,25 @@ public class SenderCertificate implements NativeHandleGuard.Owner {
public long getExpiration() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderCertificate_GetExpiration(guard.nativeHandle());
return filterExceptions(() -> Native.SenderCertificate_GetExpiration(guard.nativeHandle()));
}
}
public byte[] getSerialized() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderCertificate_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.SenderCertificate_GetSerialized(guard.nativeHandle()));
}
}
public byte[] getCertificate() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderCertificate_GetCertificate(guard.nativeHandle());
return filterExceptions(() -> Native.SenderCertificate_GetCertificate(guard.nativeHandle()));
}
}
public byte[] getSignature() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SenderCertificate_GetSignature(guard.nativeHandle());
return filterExceptions(() -> Native.SenderCertificate_GetSignature(guard.nativeHandle()));
}
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.metadata.certificate;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.Optional;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -38,38 +40,43 @@ public class ServerCertificate implements NativeHandleGuard.Owner {
try (NativeHandleGuard serverPublicGuard = new NativeHandleGuard(key);
NativeHandleGuard trustRootPrivateGuard = new NativeHandleGuard(trustRoot)) {
this.unsafeHandle =
Native.ServerCertificate_New(
keyId, serverPublicGuard.nativeHandle(), trustRootPrivateGuard.nativeHandle());
filterExceptions(
() ->
Native.ServerCertificate_New(
keyId,
serverPublicGuard.nativeHandle(),
trustRootPrivateGuard.nativeHandle()));
}
}
public int getKeyId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ServerCertificate_GetKeyId(guard.nativeHandle());
return filterExceptions(() -> Native.ServerCertificate_GetKeyId(guard.nativeHandle()));
}
}
public ECPublicKey getKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new ECPublicKey(Native.ServerCertificate_GetKey(guard.nativeHandle()));
return new ECPublicKey(
filterExceptions(() -> Native.ServerCertificate_GetKey(guard.nativeHandle())));
}
}
public byte[] getSerialized() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ServerCertificate_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.ServerCertificate_GetSerialized(guard.nativeHandle()));
}
}
public byte[] getCertificate() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ServerCertificate_GetCertificate(guard.nativeHandle());
return filterExceptions(() -> Native.ServerCertificate_GetCertificate(guard.nativeHandle()));
}
}
public byte[] getSignature() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ServerCertificate_GetSignature(guard.nativeHandle());
return filterExceptions(() -> Native.ServerCertificate_GetSignature(guard.nativeHandle()));
}
}
@ -94,14 +101,16 @@ public class ServerCertificate implements NativeHandleGuard.Owner {
NativeHandleGuard serverCertificateGuard = new NativeHandleGuard(this);
NativeHandleGuard serverPrivateGuard = new NativeHandleGuard(signingKey)) {
return new SenderCertificate(
Native.SenderCertificate_New(
senderUuid,
senderE164.orElse(null),
senderDeviceId,
identityGuard.nativeHandle(),
expiration,
serverCertificateGuard.nativeHandle(),
serverPrivateGuard.nativeHandle()));
filterExceptions(
() ->
Native.SenderCertificate_New(
senderUuid,
senderE164.orElse(null),
senderDeviceId,
identityGuard.nativeHandle(),
expiration,
serverCertificateGuard.nativeHandle(),
serverPrivateGuard.nativeHandle())));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.state;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidMessageException;
@ -28,36 +30,39 @@ public class KyberPreKeyRecord implements NativeHandleGuard.Owner {
// FIXME: This shouldn't be considered a "message".
public KyberPreKeyRecord(byte[] serialized) throws InvalidMessageException {
this.unsafeHandle = Native.KyberPreKeyRecord_Deserialize(serialized);
this.unsafeHandle =
filterExceptions(
InvalidMessageException.class, () -> Native.KyberPreKeyRecord_Deserialize(serialized));
}
public int getId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.KyberPreKeyRecord_GetId(guard.nativeHandle());
return filterExceptions(() -> Native.KyberPreKeyRecord_GetId(guard.nativeHandle()));
}
}
public long getTimestamp() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.KyberPreKeyRecord_GetTimestamp(guard.nativeHandle());
return filterExceptions(() -> Native.KyberPreKeyRecord_GetTimestamp(guard.nativeHandle()));
}
}
public KEMKeyPair getKeyPair() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new KEMKeyPair(Native.KyberPreKeyRecord_GetKeyPair(guard.nativeHandle()));
return new KEMKeyPair(
filterExceptions(() -> Native.KyberPreKeyRecord_GetKeyPair(guard.nativeHandle())));
}
}
public byte[] getSignature() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.KyberPreKeyRecord_GetSignature(guard.nativeHandle());
return filterExceptions(() -> Native.KyberPreKeyRecord_GetSignature(guard.nativeHandle()));
}
}
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.KyberPreKeyRecord_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.KyberPreKeyRecord_GetSerialized(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.state;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.IdentityKey;
@ -69,18 +71,20 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
NativeHandleGuard kyberPreKeyPublicGuard = new NativeHandleGuard(kyberPreKeyPublic); ) {
byte[] kyberSignature = kyberPreKeySignature == null ? new byte[] {} : kyberPreKeySignature;
this.unsafeHandle =
Native.PreKeyBundle_New(
registrationId,
deviceId,
preKeyId,
preKeyPublicGuard.nativeHandle(),
signedPreKeyId,
signedPreKeyPublicGuard.nativeHandle(),
signedPreKeySignature,
identityKeyGuard.nativeHandle(),
kyberPreKeyId,
kyberPreKeyPublicGuard.nativeHandle(),
kyberSignature);
filterExceptions(
() ->
Native.PreKeyBundle_New(
registrationId,
deviceId,
preKeyId,
preKeyPublicGuard.nativeHandle(),
signedPreKeyId,
signedPreKeyPublicGuard.nativeHandle(),
signedPreKeySignature,
identityKeyGuard.nativeHandle(),
kyberPreKeyId,
kyberPreKeyPublicGuard.nativeHandle(),
kyberSignature));
}
}
@ -89,7 +93,7 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public int getDeviceId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeyBundle_GetDeviceId(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeyBundle_GetDeviceId(guard.nativeHandle()));
}
}
@ -98,7 +102,7 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public int getPreKeyId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeyBundle_GetPreKeyId(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeyBundle_GetPreKeyId(guard.nativeHandle()));
}
}
@ -107,7 +111,8 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public ECPublicKey getPreKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
long handle = Native.PreKeyBundle_GetPreKeyPublic(guard.nativeHandle());
long handle =
filterExceptions(() -> Native.PreKeyBundle_GetPreKeyPublic(guard.nativeHandle()));
if (handle != 0) {
return new ECPublicKey(handle);
}
@ -120,7 +125,7 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public int getSignedPreKeyId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeyBundle_GetSignedPreKeyId(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeyBundle_GetSignedPreKeyId(guard.nativeHandle()));
}
}
@ -129,7 +134,8 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public ECPublicKey getSignedPreKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new ECPublicKey(Native.PreKeyBundle_GetSignedPreKeyPublic(guard.nativeHandle()));
return new ECPublicKey(
filterExceptions(() -> Native.PreKeyBundle_GetSignedPreKeyPublic(guard.nativeHandle())));
}
}
@ -138,7 +144,8 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public byte[] getSignedPreKeySignature() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeyBundle_GetSignedPreKeySignature(guard.nativeHandle());
return filterExceptions(
() -> Native.PreKeyBundle_GetSignedPreKeySignature(guard.nativeHandle()));
}
}
@ -148,7 +155,8 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
public IdentityKey getIdentityKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return new IdentityKey(
new ECPublicKey(Native.PreKeyBundle_GetIdentityKey(guard.nativeHandle())));
new ECPublicKey(
filterExceptions(() -> Native.PreKeyBundle_GetIdentityKey(guard.nativeHandle()))));
}
}
@ -157,7 +165,7 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public int getRegistrationId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeyBundle_GetRegistrationId(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeyBundle_GetRegistrationId(guard.nativeHandle()));
}
}
@ -166,7 +174,7 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public int getKyberPreKeyId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeyBundle_GetKyberPreKeyId(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeyBundle_GetKyberPreKeyId(guard.nativeHandle()));
}
}
@ -175,7 +183,8 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public KEMPublicKey getKyberPreKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
long handle = Native.PreKeyBundle_GetKyberPreKeyPublic(guard.nativeHandle());
long handle =
filterExceptions(() -> Native.PreKeyBundle_GetKyberPreKeyPublic(guard.nativeHandle()));
if (handle != 0) {
return new KEMPublicKey(handle);
}
@ -188,7 +197,8 @@ public class PreKeyBundle implements NativeHandleGuard.Owner {
*/
public byte[] getKyberPreKeySignature() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
byte[] signature = Native.PreKeyBundle_GetKyberPreKeySignature(guard.nativeHandle());
byte[] signature =
filterExceptions(() -> Native.PreKeyBundle_GetKyberPreKeySignature(guard.nativeHandle()));
if (signature.length == 0) {
return null;
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.state;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidKeyException;
@ -32,28 +34,34 @@ public class PreKeyRecord implements NativeHandleGuard.Owner {
// FIXME: This shouldn't be considered a "message".
public PreKeyRecord(byte[] serialized) throws InvalidMessageException {
this.unsafeHandle = Native.PreKeyRecord_Deserialize(serialized);
this.unsafeHandle =
filterExceptions(
InvalidMessageException.class, () -> Native.PreKeyRecord_Deserialize(serialized));
}
public int getId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeyRecord_GetId(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeyRecord_GetId(guard.nativeHandle()));
}
}
public ECKeyPair getKeyPair() throws InvalidKeyException {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
ECPublicKey publicKey =
new ECPublicKey(Native.PreKeyRecord_GetPublicKey(guard.nativeHandle()));
ECPrivateKey privateKey =
new ECPrivateKey(Native.PreKeyRecord_GetPrivateKey(guard.nativeHandle()));
return new ECKeyPair(publicKey, privateKey);
return filterExceptions(
InvalidKeyException.class,
() -> {
ECPublicKey publicKey =
new ECPublicKey(Native.PreKeyRecord_GetPublicKey(guard.nativeHandle()));
ECPrivateKey privateKey =
new ECPrivateKey(Native.PreKeyRecord_GetPrivateKey(guard.nativeHandle()));
return new ECKeyPair(publicKey, privateKey);
});
}
}
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.PreKeyRecord_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.PreKeyRecord_GetSerialized(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.state;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
@ -40,7 +42,9 @@ public class SessionRecord implements NativeHandleGuard.Owner {
// FIXME: This shouldn't be considered a "message".
public SessionRecord(byte[] serialized) throws InvalidMessageException {
this.unsafeHandle = Native.SessionRecord_Deserialize(serialized);
this.unsafeHandle =
filterExceptions(
InvalidMessageException.class, () -> Native.SessionRecord_Deserialize(serialized));
}
/**
@ -49,31 +53,36 @@ public class SessionRecord implements NativeHandleGuard.Owner {
*/
public void archiveCurrentState() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
Native.SessionRecord_ArchiveCurrentState(guard.nativeHandle());
filterExceptions(() -> Native.SessionRecord_ArchiveCurrentState(guard.nativeHandle()));
}
}
public int getSessionVersion() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SessionRecord_GetSessionVersion(guard.nativeHandle());
return filterExceptions(() -> Native.SessionRecord_GetSessionVersion(guard.nativeHandle()));
}
}
public int getRemoteRegistrationId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SessionRecord_GetRemoteRegistrationId(guard.nativeHandle());
return filterExceptions(
() -> Native.SessionRecord_GetRemoteRegistrationId(guard.nativeHandle()));
}
}
public int getLocalRegistrationId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SessionRecord_GetLocalRegistrationId(guard.nativeHandle());
return filterExceptions(
() -> Native.SessionRecord_GetLocalRegistrationId(guard.nativeHandle()));
}
}
public IdentityKey getRemoteIdentityKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
byte[] keyBytes = Native.SessionRecord_GetRemoteIdentityKeyPublic(guard.nativeHandle());
byte[] keyBytes =
filterExceptions(
InvalidKeyException.class,
() -> Native.SessionRecord_GetRemoteIdentityKeyPublic(guard.nativeHandle()));
if (keyBytes == null) {
return null;
@ -87,7 +96,10 @@ public class SessionRecord implements NativeHandleGuard.Owner {
public IdentityKey getLocalIdentityKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
byte[] keyBytes = Native.SessionRecord_GetLocalIdentityKeyPublic(guard.nativeHandle());
byte[] keyBytes =
filterExceptions(
InvalidKeyException.class,
() -> Native.SessionRecord_GetLocalIdentityKeyPublic(guard.nativeHandle()));
return new IdentityKey(keyBytes);
} catch (InvalidKeyException e) {
throw new AssertionError(e);
@ -112,15 +124,19 @@ public class SessionRecord implements NativeHandleGuard.Owner {
*/
public boolean hasSenderChain(Instant now) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SessionRecord_HasUsableSenderChain(guard.nativeHandle(), now.toEpochMilli());
return filterExceptions(
() ->
Native.SessionRecord_HasUsableSenderChain(guard.nativeHandle(), now.toEpochMilli()));
}
}
public boolean currentRatchetKeyMatches(ECPublicKey key) {
try (NativeHandleGuard guard = new NativeHandleGuard(this);
NativeHandleGuard keyGuard = new NativeHandleGuard(key); ) {
return Native.SessionRecord_CurrentRatchetKeyMatches(
guard.nativeHandle(), keyGuard.nativeHandle());
return filterExceptions(
() ->
Native.SessionRecord_CurrentRatchetKeyMatches(
guard.nativeHandle(), keyGuard.nativeHandle()));
}
}
@ -129,7 +145,7 @@ public class SessionRecord implements NativeHandleGuard.Owner {
*/
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SessionRecord_Serialize(guard.nativeHandle());
return filterExceptions(() -> Native.SessionRecord_Serialize(guard.nativeHandle()));
}
}
@ -138,20 +154,23 @@ public class SessionRecord implements NativeHandleGuard.Owner {
public byte[] getReceiverChainKeyValue(ECPublicKey senderEphemeral) {
try (NativeHandleGuard guard = new NativeHandleGuard(this);
NativeHandleGuard ephemeralGuard = new NativeHandleGuard(senderEphemeral); ) {
return Native.SessionRecord_GetReceiverChainKeyValue(
guard.nativeHandle(), ephemeralGuard.nativeHandle());
return filterExceptions(
() ->
Native.SessionRecord_GetReceiverChainKeyValue(
guard.nativeHandle(), ephemeralGuard.nativeHandle()));
}
}
public byte[] getSenderChainKeyValue() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SessionRecord_GetSenderChainKeyValue(guard.nativeHandle());
return filterExceptions(
() -> Native.SessionRecord_GetSenderChainKeyValue(guard.nativeHandle()));
}
}
public byte[] getAliceBaseKey() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SessionRecord_GetAliceBaseKey(guard.nativeHandle());
return filterExceptions(() -> Native.SessionRecord_GetAliceBaseKey(guard.nativeHandle()));
}
}
@ -172,14 +191,16 @@ public class SessionRecord implements NativeHandleGuard.Owner {
NativeHandleGuard theirSignedPreKeyGuard = new NativeHandleGuard(theirSignedPreKey);
NativeHandleGuard theirRatchetKeyGuard = new NativeHandleGuard(theirRatchetKey); ) {
return new SessionRecord(
Native.SessionRecord_InitializeAliceSession(
identityPrivateGuard.nativeHandle(),
identityPublicGuard.nativeHandle(),
basePrivateGuard.nativeHandle(),
basePublicGuard.nativeHandle(),
theirIdentityGuard.nativeHandle(),
theirSignedPreKeyGuard.nativeHandle(),
theirRatchetKeyGuard.nativeHandle()));
filterExceptions(
() ->
Native.SessionRecord_InitializeAliceSession(
identityPrivateGuard.nativeHandle(),
identityPublicGuard.nativeHandle(),
basePrivateGuard.nativeHandle(),
basePublicGuard.nativeHandle(),
theirIdentityGuard.nativeHandle(),
theirSignedPreKeyGuard.nativeHandle(),
theirRatchetKeyGuard.nativeHandle())));
}
}
@ -205,15 +226,17 @@ public class SessionRecord implements NativeHandleGuard.Owner {
new NativeHandleGuard(theirIdentityKey.getPublicKey());
NativeHandleGuard theirBaseKeyGuard = new NativeHandleGuard(theirBaseKey); ) {
return new SessionRecord(
Native.SessionRecord_InitializeBobSession(
identityPrivateGuard.nativeHandle(),
identityPublicGuard.nativeHandle(),
signedPreKeyPrivateGuard.nativeHandle(),
signedPreKeyPublicGuard.nativeHandle(),
ephemeralPrivateGuard.nativeHandle(),
ephemeralPublicGuard.nativeHandle(),
theirIdentityGuard.nativeHandle(),
theirBaseKeyGuard.nativeHandle()));
filterExceptions(
() ->
Native.SessionRecord_InitializeBobSession(
identityPrivateGuard.nativeHandle(),
identityPublicGuard.nativeHandle(),
signedPreKeyPrivateGuard.nativeHandle(),
signedPreKeyPublicGuard.nativeHandle(),
ephemeralPrivateGuard.nativeHandle(),
ephemeralPublicGuard.nativeHandle(),
theirIdentityGuard.nativeHandle(),
theirBaseKeyGuard.nativeHandle())));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.protocol.state;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidMessageException;
@ -32,40 +34,45 @@ public class SignedPreKeyRecord implements NativeHandleGuard.Owner {
// FIXME: This shouldn't be considered a "message".
public SignedPreKeyRecord(byte[] serialized) throws InvalidMessageException {
this.unsafeHandle = Native.SignedPreKeyRecord_Deserialize(serialized);
this.unsafeHandle =
filterExceptions(
InvalidMessageException.class, () -> Native.SignedPreKeyRecord_Deserialize(serialized));
}
public int getId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SignedPreKeyRecord_GetId(guard.nativeHandle());
return filterExceptions(() -> Native.SignedPreKeyRecord_GetId(guard.nativeHandle()));
}
}
public long getTimestamp() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SignedPreKeyRecord_GetTimestamp(guard.nativeHandle());
return filterExceptions(() -> Native.SignedPreKeyRecord_GetTimestamp(guard.nativeHandle()));
}
}
public ECKeyPair getKeyPair() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
ECPublicKey publicKey =
new ECPublicKey(Native.SignedPreKeyRecord_GetPublicKey(guard.nativeHandle()));
ECPrivateKey privateKey =
new ECPrivateKey(Native.SignedPreKeyRecord_GetPrivateKey(guard.nativeHandle()));
return new ECKeyPair(publicKey, privateKey);
return filterExceptions(
() -> {
ECPublicKey publicKey =
new ECPublicKey(Native.SignedPreKeyRecord_GetPublicKey(guard.nativeHandle()));
ECPrivateKey privateKey =
new ECPrivateKey(Native.SignedPreKeyRecord_GetPrivateKey(guard.nativeHandle()));
return new ECKeyPair(publicKey, privateKey);
});
}
}
public byte[] getSignature() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SignedPreKeyRecord_GetSignature(guard.nativeHandle());
return filterExceptions(() -> Native.SignedPreKeyRecord_GetSignature(guard.nativeHandle()));
}
}
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.SignedPreKeyRecord_GetSerialized(guard.nativeHandle());
return filterExceptions(() -> Native.SignedPreKeyRecord_GetSerialized(guard.nativeHandle()));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.usernames;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
@ -70,7 +72,10 @@ public final class Username {
public static List<Username> candidatesFrom(
String nickname, int minNicknameLength, int maxNicknameLength) throws BaseUsernameException {
Object[] names = Native.Username_CandidatesFrom(nickname, minNicknameLength, maxNicknameLength);
Object[] names =
filterExceptions(
BaseUsernameException.class,
() -> Native.Username_CandidatesFrom(nickname, minNicknameLength, maxNicknameLength));
ArrayList<Username> result = new ArrayList<>(names.length);
for (Object name : names) {
result.add(new Username((String) name));
@ -82,8 +87,11 @@ public final class Username {
String nickname, String discriminator, int minNicknameLength, int maxNicknameLength)
throws BaseUsernameException {
byte[] hash =
Native.Username_HashFromParts(
nickname, discriminator, minNicknameLength, maxNicknameLength);
filterExceptions(
BaseUsernameException.class,
() ->
Native.Username_HashFromParts(
nickname, discriminator, minNicknameLength, maxNicknameLength));
// If we generated the hash correctly, we can format the nickname and discriminator manually.
String username = nickname + "." + discriminator;
return new Username(username, hash);
@ -91,8 +99,11 @@ public final class Username {
public static Username fromLink(final UsernameLink usernameLink) throws BaseUsernameException {
final String username =
Native.UsernameLink_DecryptUsername(
usernameLink.getEntropy(), usernameLink.getEncryptedUsername());
filterExceptions(
BaseUsernameException.class,
() ->
Native.UsernameLink_DecryptUsername(
usernameLink.getEntropy(), usernameLink.getEncryptedUsername()));
return new Username(username);
}
@ -104,7 +115,8 @@ public final class Username {
}
public byte[] generateProofWithRandomness(byte[] randomness) throws BaseUsernameException {
return Native.Username_Proof(this.username, randomness);
return filterExceptions(
BaseUsernameException.class, () -> Native.Username_Proof(this.username, randomness));
}
public UsernameLink generateLink() throws BaseUsernameException {
@ -112,7 +124,10 @@ public final class Username {
}
public UsernameLink generateLink(byte[] previousEntropy) throws BaseUsernameException {
final byte[] bytes = Native.UsernameLink_Create(username, previousEntropy);
final byte[] bytes =
filterExceptions(
BaseUsernameException.class,
() -> Native.UsernameLink_Create(username, previousEntropy));
final byte[] entropy = Arrays.copyOfRange(bytes, 0, 32);
final byte[] enctyptedUsername = Arrays.copyOfRange(bytes, 32, bytes.length);
return new UsernameLink(entropy, enctyptedUsername);
@ -121,23 +136,27 @@ public final class Username {
@Deprecated
public static List<String> generateCandidates(
String nickname, int minNicknameLength, int maxNicknameLength) throws BaseUsernameException {
Object[] names = Native.Username_CandidatesFrom(nickname, minNicknameLength, maxNicknameLength);
Object[] names =
filterExceptions(
BaseUsernameException.class,
() -> Native.Username_CandidatesFrom(nickname, minNicknameLength, maxNicknameLength));
return Arrays.asList((String[]) names);
}
@Deprecated
public static byte[] hash(String username) throws BaseUsernameException {
return Native.Username_Hash(username);
return filterExceptions(BaseUsernameException.class, () -> Native.Username_Hash(username));
}
@Deprecated
public static byte[] generateProof(String username, byte[] randomness)
throws BaseUsernameException {
return Native.Username_Proof(username, randomness);
return filterExceptions(
BaseUsernameException.class, () -> Native.Username_Proof(username, randomness));
}
public static void verifyProof(byte[] proof, byte[] hash) throws BaseUsernameException {
Native.Username_Verify(proof, hash);
filterExceptions(BaseUsernameException.class, () -> Native.Username_Verify(proof, hash));
}
@Override

View File

@ -5,12 +5,16 @@
package org.signal.libsignal.zkgroup;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class GenericServerPublicParams extends ByteArray {
public GenericServerPublicParams(byte[] contents) throws InvalidInputException {
super(contents);
Native.GenericServerPublicParams_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.GenericServerPublicParams_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -32,7 +33,9 @@ public final class GenericServerSecretParams extends ByteArray {
public GenericServerSecretParams(byte[] contents) throws InvalidInputException {
super(contents);
Native.GenericServerSecretParams_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.GenericServerSecretParams_CheckValidContents(contents));
}
public GenericServerPublicParams getPublicParams() {

View File

@ -5,18 +5,24 @@
package org.signal.libsignal.zkgroup;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ServerPublicParams extends ByteArray {
public ServerPublicParams(byte[] contents) throws InvalidInputException {
super(contents);
Native.ServerPublicParams_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class, () -> Native.ServerPublicParams_CheckValidContents(contents));
}
public void verifySignature(byte[] message, NotarySignature notarySignature)
throws VerificationFailedException {
Native.ServerPublicParams_VerifySignature(
contents, message, notarySignature.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerPublicParams_VerifySignature(
contents, message, notarySignature.getInternalContentsForJNI()));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -32,7 +33,8 @@ public final class ServerSecretParams extends ByteArray {
public ServerSecretParams(byte[] contents) throws InvalidInputException {
super(contents);
Native.ServerSecretParams_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class, () -> Native.ServerSecretParams_CheckValidContents(contents));
}
public ServerPublicParams getPublicParams() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.auth;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,7 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class AuthCredential extends ByteArray {
public AuthCredential(byte[] contents) throws InvalidInputException {
super(contents);
Native.AuthCredential_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class, () -> Native.AuthCredential_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.auth;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
@ -22,7 +24,9 @@ public final class AuthCredentialPresentation extends ByteArray {
public AuthCredentialPresentation(byte[] contents) throws InvalidInputException {
super(contents);
Native.AuthCredentialPresentation_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.AuthCredentialPresentation_CheckValidContents(contents));
}
public UuidCiphertext getUuidCiphertext() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.auth;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class AuthCredentialResponse extends ByteArray {
public AuthCredentialResponse(byte[] contents) throws InvalidInputException {
super(contents);
Native.AuthCredentialResponse_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.AuthCredentialResponse_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.auth;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class AuthCredentialWithPni extends ByteArray {
public AuthCredentialWithPni(byte[] contents) throws InvalidInputException {
super(contents);
Native.AuthCredentialWithPni_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.AuthCredentialWithPni_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.auth;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class AuthCredentialWithPniResponse extends ByteArray {
public AuthCredentialWithPniResponse(byte[] contents) throws InvalidInputException {
super(contents);
Native.AuthCredentialWithPniResponse_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.AuthCredentialWithPniResponse_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.auth;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -28,11 +29,14 @@ public class ClientZkAuthOperations {
Aci aci, int redemptionTime, AuthCredentialResponse authCredentialResponse)
throws VerificationFailedException {
byte[] newContents =
Native.ServerPublicParams_ReceiveAuthCredential(
serverPublicParams.getInternalContentsForJNI(),
aci.toServiceIdFixedWidthBinary(),
redemptionTime,
authCredentialResponse.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerPublicParams_ReceiveAuthCredential(
serverPublicParams.getInternalContentsForJNI(),
aci.toServiceIdFixedWidthBinary(),
redemptionTime,
authCredentialResponse.getInternalContentsForJNI()));
try {
return new AuthCredential(newContents);
@ -51,12 +55,15 @@ public class ClientZkAuthOperations {
Aci aci, Pni pni, long redemptionTime, AuthCredentialWithPniResponse authCredentialResponse)
throws VerificationFailedException {
byte[] newContents =
Native.ServerPublicParams_ReceiveAuthCredentialWithPniAsServiceId(
serverPublicParams.getInternalContentsForJNI(),
aci.toServiceIdFixedWidthBinary(),
pni.toServiceIdFixedWidthBinary(),
redemptionTime,
authCredentialResponse.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerPublicParams_ReceiveAuthCredentialWithPniAsServiceId(
serverPublicParams.getInternalContentsForJNI(),
aci.toServiceIdFixedWidthBinary(),
pni.toServiceIdFixedWidthBinary(),
redemptionTime,
authCredentialResponse.getInternalContentsForJNI()));
try {
return new AuthCredentialWithPni(newContents);
@ -78,12 +85,15 @@ public class ClientZkAuthOperations {
Aci aci, Pni pni, long redemptionTime, AuthCredentialWithPniResponse authCredentialResponse)
throws VerificationFailedException {
byte[] newContents =
Native.ServerPublicParams_ReceiveAuthCredentialWithPniAsAci(
serverPublicParams.getInternalContentsForJNI(),
aci.toServiceIdFixedWidthBinary(),
pni.toServiceIdFixedWidthBinary(),
redemptionTime,
authCredentialResponse.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerPublicParams_ReceiveAuthCredentialWithPniAsAci(
serverPublicParams.getInternalContentsForJNI(),
aci.toServiceIdFixedWidthBinary(),
pni.toServiceIdFixedWidthBinary(),
redemptionTime,
authCredentialResponse.getInternalContentsForJNI()));
try {
return new AuthCredentialWithPni(newContents);

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.auth;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -112,10 +113,13 @@ public class ServerZkAuthOperations {
AuthCredentialPresentation authCredentialPresentation,
Instant currentTime)
throws VerificationFailedException {
Native.ServerSecretParams_VerifyAuthCredentialPresentation(
serverSecretParams.getInternalContentsForJNI(),
groupPublicParams.getInternalContentsForJNI(),
authCredentialPresentation.getInternalContentsForJNI(),
currentTime.getEpochSecond());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerSecretParams_VerifyAuthCredentialPresentation(
serverSecretParams.getInternalContentsForJNI(),
groupPublicParams.getInternalContentsForJNI(),
authCredentialPresentation.getInternalContentsForJNI(),
currentTime.getEpochSecond()));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.backups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -17,7 +18,9 @@ public final class BackupAuthCredential extends ByteArray {
public BackupAuthCredential(byte[] contents) throws InvalidInputException {
super(contents);
Native.BackupAuthCredential_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.BackupAuthCredential_CheckValidContents(contents));
}
public BackupAuthCredentialPresentation present(GenericServerPublicParams serverParams) {
@ -30,8 +33,10 @@ public final class BackupAuthCredential extends ByteArray {
secureRandom.nextBytes(random);
final byte[] newContents =
Native.BackupAuthCredential_PresentDeterministic(
getInternalContentsForJNI(), serverParams.getInternalContentsForJNI(), random);
filterExceptions(
() ->
Native.BackupAuthCredential_PresentDeterministic(
getInternalContentsForJNI(), serverParams.getInternalContentsForJNI(), random));
try {
return new BackupAuthCredentialPresentation(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.backups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.GenericServerSecretParams;
@ -16,7 +18,9 @@ public final class BackupAuthCredentialPresentation extends ByteArray {
public BackupAuthCredentialPresentation(byte[] contents) throws InvalidInputException {
super(contents);
Native.BackupAuthCredentialPresentation_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.BackupAuthCredentialPresentation_CheckValidContents(contents));
}
public void verify(GenericServerSecretParams serverParams) throws VerificationFailedException {
@ -25,10 +29,13 @@ public final class BackupAuthCredentialPresentation extends ByteArray {
public void verify(Instant currentTime, GenericServerSecretParams serverParams)
throws VerificationFailedException {
Native.BackupAuthCredentialPresentation_Verify(
getInternalContentsForJNI(),
currentTime.getEpochSecond(),
serverParams.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.BackupAuthCredentialPresentation_Verify(
getInternalContentsForJNI(),
currentTime.getEpochSecond(),
serverParams.getInternalContentsForJNI()));
}
public byte[] getBackupId() {

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.backups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -18,7 +19,9 @@ public final class BackupAuthCredentialRequest extends ByteArray {
public BackupAuthCredentialRequest(byte[] contents) throws InvalidInputException {
super(contents);
Native.BackupAuthCredentialRequest_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.BackupAuthCredentialRequest_CheckValidContents(contents));
}
/**

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.backups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.util.UUID;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.GenericServerPublicParams;
@ -16,7 +18,9 @@ public final class BackupAuthCredentialRequestContext extends ByteArray {
public BackupAuthCredentialRequestContext(byte[] contents) throws InvalidInputException {
super(contents);
Native.BackupAuthCredentialRequestContext_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.BackupAuthCredentialRequestContext_CheckValidContents(contents));
}
public static BackupAuthCredentialRequestContext create(final byte[] backupKey, final UUID aci) {
@ -45,11 +49,14 @@ public final class BackupAuthCredentialRequestContext extends ByteArray {
long expectedReceiptLevel)
throws VerificationFailedException {
final byte[] newContents =
Native.BackupAuthCredentialRequestContext_ReceiveResponse(
getInternalContentsForJNI(),
response.getInternalContentsForJNI(),
params.getInternalContentsForJNI(),
expectedReceiptLevel);
filterExceptions(
VerificationFailedException.class,
() ->
Native.BackupAuthCredentialRequestContext_ReceiveResponse(
getInternalContentsForJNI(),
response.getInternalContentsForJNI(),
params.getInternalContentsForJNI(),
expectedReceiptLevel));
try {
return new BackupAuthCredential(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.backups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class BackupAuthCredentialResponse extends ByteArray {
public BackupAuthCredentialResponse(byte[] contents) throws InvalidInputException {
super(contents);
Native.BackupAuthCredentialResponse_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.BackupAuthCredentialResponse_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -19,7 +20,9 @@ public final class CallLinkAuthCredential extends ByteArray {
public CallLinkAuthCredential(byte[] contents) throws InvalidInputException {
super(contents);
Native.CallLinkAuthCredential_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CallLinkAuthCredential_CheckValidContents(contents));
}
public CallLinkAuthCredentialPresentation present(
@ -40,13 +43,15 @@ public final class CallLinkAuthCredential extends ByteArray {
secureRandom.nextBytes(random);
byte[] newContents =
Native.CallLinkAuthCredential_PresentDeterministic(
getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary(),
redemptionTime.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
callLinkParams.getInternalContentsForJNI(),
random);
filterExceptions(
() ->
Native.CallLinkAuthCredential_PresentDeterministic(
getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary(),
redemptionTime.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
callLinkParams.getInternalContentsForJNI(),
random));
try {
return new CallLinkAuthCredentialPresentation(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.GenericServerSecretParams;
@ -17,7 +19,9 @@ public final class CallLinkAuthCredentialPresentation extends ByteArray {
public CallLinkAuthCredentialPresentation(byte[] contents) throws InvalidInputException {
super(contents);
Native.CallLinkAuthCredentialPresentation_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CallLinkAuthCredentialPresentation_CheckValidContents(contents));
}
public void verify(GenericServerSecretParams serverParams, CallLinkPublicParams callLinkParams)
@ -30,11 +34,14 @@ public final class CallLinkAuthCredentialPresentation extends ByteArray {
GenericServerSecretParams serverParams,
CallLinkPublicParams callLinkParams)
throws VerificationFailedException {
Native.CallLinkAuthCredentialPresentation_Verify(
getInternalContentsForJNI(),
currentTime.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
callLinkParams.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.CallLinkAuthCredentialPresentation_Verify(
getInternalContentsForJNI(),
currentTime.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
callLinkParams.getInternalContentsForJNI()));
}
public UuidCiphertext getUserId() {

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -20,7 +21,9 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class CallLinkAuthCredentialResponse extends ByteArray {
public CallLinkAuthCredentialResponse(byte[] contents) throws InvalidInputException {
super(contents);
Native.CallLinkAuthCredentialResponse_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CallLinkAuthCredentialResponse_CheckValidContents(contents));
}
public static CallLinkAuthCredentialResponse issueCredential(
@ -54,11 +57,14 @@ public final class CallLinkAuthCredentialResponse extends ByteArray {
Aci userId, Instant redemptionTime, GenericServerPublicParams params)
throws VerificationFailedException {
byte[] newContents =
Native.CallLinkAuthCredentialResponse_Receive(
getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary(),
redemptionTime.getEpochSecond(),
params.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.CallLinkAuthCredentialResponse_Receive(
getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary(),
redemptionTime.getEpochSecond(),
params.getInternalContentsForJNI()));
try {
return new CallLinkAuthCredential(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class CallLinkPublicParams extends ByteArray {
public CallLinkPublicParams(byte[] contents) throws InvalidInputException {
super(contents);
Native.CallLinkPublicParams_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CallLinkPublicParams_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.protocol.ServiceId;
import org.signal.libsignal.protocol.ServiceId.Aci;
@ -27,7 +29,9 @@ public final class CallLinkSecretParams extends ByteArray {
public CallLinkSecretParams(byte[] contents) throws InvalidInputException {
super(contents);
Native.CallLinkSecretParams_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CallLinkSecretParams_CheckValidContents(contents));
}
public CallLinkPublicParams getPublicParams() {
@ -43,8 +47,11 @@ public final class CallLinkSecretParams extends ByteArray {
public Aci decryptUserId(UuidCiphertext ciphertext) throws VerificationFailedException {
try {
return Aci.parseFromFixedWidthBinary(
Native.CallLinkSecretParams_DecryptUserId(
getInternalContentsForJNI(), ciphertext.getInternalContentsForJNI()));
filterExceptions(
VerificationFailedException.class,
() ->
Native.CallLinkSecretParams_DecryptUserId(
getInternalContentsForJNI(), ciphertext.getInternalContentsForJNI())));
} catch (ServiceId.InvalidServiceIdException e) {
throw new VerificationFailedException();
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -18,7 +19,9 @@ public final class CreateCallLinkCredential extends ByteArray {
public CreateCallLinkCredential(byte[] contents) throws InvalidInputException {
super(contents);
Native.CreateCallLinkCredential_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CreateCallLinkCredential_CheckValidContents(contents));
}
public CreateCallLinkCredentialPresentation present(
@ -39,13 +42,15 @@ public final class CreateCallLinkCredential extends ByteArray {
secureRandom.nextBytes(random);
byte[] newContents =
Native.CreateCallLinkCredential_PresentDeterministic(
getInternalContentsForJNI(),
roomId,
userId.toServiceIdFixedWidthBinary(),
serverParams.getInternalContentsForJNI(),
callLinkParams.getInternalContentsForJNI(),
random);
filterExceptions(
() ->
Native.CreateCallLinkCredential_PresentDeterministic(
getInternalContentsForJNI(),
roomId,
userId.toServiceIdFixedWidthBinary(),
serverParams.getInternalContentsForJNI(),
callLinkParams.getInternalContentsForJNI(),
random));
try {
return new CreateCallLinkCredentialPresentation(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.GenericServerSecretParams;
@ -16,7 +18,9 @@ public final class CreateCallLinkCredentialPresentation extends ByteArray {
public CreateCallLinkCredentialPresentation(byte[] contents) throws InvalidInputException {
super(contents);
Native.CreateCallLinkCredentialPresentation_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CreateCallLinkCredentialPresentation_CheckValidContents(contents));
}
public void verify(
@ -31,11 +35,14 @@ public final class CreateCallLinkCredentialPresentation extends ByteArray {
GenericServerSecretParams serverParams,
CallLinkPublicParams callLinkParams)
throws VerificationFailedException {
Native.CreateCallLinkCredentialPresentation_Verify(
getInternalContentsForJNI(),
roomId,
currentTime.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
callLinkParams.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.CreateCallLinkCredentialPresentation_Verify(
getInternalContentsForJNI(),
roomId,
currentTime.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
callLinkParams.getInternalContentsForJNI()));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -19,7 +20,9 @@ public final class CreateCallLinkCredentialRequest extends ByteArray {
public CreateCallLinkCredentialRequest(byte[] contents) throws InvalidInputException {
super(contents);
Native.CreateCallLinkCredentialRequest_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CreateCallLinkCredentialRequest_CheckValidContents(contents));
}
/**

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -19,7 +20,9 @@ public final class CreateCallLinkCredentialRequestContext extends ByteArray {
public CreateCallLinkCredentialRequestContext(byte[] contents) throws InvalidInputException {
super(contents);
Native.CreateCallLinkCredentialRequestContext_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CreateCallLinkCredentialRequestContext_CheckValidContents(contents));
}
public static CreateCallLinkCredentialRequestContext forRoom(byte[] roomId) {
@ -55,11 +58,14 @@ public final class CreateCallLinkCredentialRequestContext extends ByteArray {
CreateCallLinkCredentialResponse response, Aci userId, GenericServerPublicParams params)
throws VerificationFailedException {
byte[] newContents =
Native.CreateCallLinkCredentialRequestContext_ReceiveResponse(
getInternalContentsForJNI(),
response.getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary(),
params.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.CreateCallLinkCredentialRequestContext_ReceiveResponse(
getInternalContentsForJNI(),
response.getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary(),
params.getInternalContentsForJNI()));
try {
return new CreateCallLinkCredential(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.calllinks;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class CreateCallLinkCredentialResponse extends ByteArray {
public CreateCallLinkCredentialResponse(byte[] contents) throws InvalidInputException {
super(contents);
Native.CreateCallLinkCredentialResponse_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.CreateCallLinkCredentialResponse_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.groups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -37,9 +38,12 @@ public class ClientZkGroupCipher {
public ServiceId decrypt(UuidCiphertext uuidCiphertext) throws VerificationFailedException {
try {
return ServiceId.parseFromFixedWidthBinary(
Native.GroupSecretParams_DecryptServiceId(
groupSecretParams.getInternalContentsForJNI(),
uuidCiphertext.getInternalContentsForJNI()));
filterExceptions(
VerificationFailedException.class,
() ->
Native.GroupSecretParams_DecryptServiceId(
groupSecretParams.getInternalContentsForJNI(),
uuidCiphertext.getInternalContentsForJNI())));
} catch (ServiceId.InvalidServiceIdException e) {
throw new VerificationFailedException();
}
@ -63,10 +67,13 @@ public class ClientZkGroupCipher {
ProfileKeyCiphertext profileKeyCiphertext, ServiceId.Aci userId)
throws VerificationFailedException {
byte[] newContents =
Native.GroupSecretParams_DecryptProfileKey(
groupSecretParams.getInternalContentsForJNI(),
profileKeyCiphertext.getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary());
filterExceptions(
VerificationFailedException.class,
() ->
Native.GroupSecretParams_DecryptProfileKey(
groupSecretParams.getInternalContentsForJNI(),
profileKeyCiphertext.getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary()));
try {
return new ProfileKey(newContents);
@ -88,7 +95,10 @@ public class ClientZkGroupCipher {
}
public byte[] decryptBlob(byte[] blobCiphertext) throws VerificationFailedException {
return Native.GroupSecretParams_DecryptBlobWithPadding(
groupSecretParams.getInternalContentsForJNI(), blobCiphertext);
return filterExceptions(
VerificationFailedException.class,
() ->
Native.GroupSecretParams_DecryptBlobWithPadding(
groupSecretParams.getInternalContentsForJNI(), blobCiphertext));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.groups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -13,7 +15,8 @@ public final class GroupPublicParams extends ByteArray {
public GroupPublicParams(byte[] contents) throws InvalidInputException {
super(contents);
Native.GroupPublicParams_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class, () -> Native.GroupPublicParams_CheckValidContents(contents));
}
public GroupIdentifier getGroupIdentifier() {

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.groups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -44,7 +45,8 @@ public final class GroupSecretParams extends ByteArray {
public GroupSecretParams(byte[] contents) throws InvalidInputException {
super(contents);
Native.GroupSecretParams_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class, () -> Native.GroupSecretParams_CheckValidContents(contents));
}
public GroupMasterKey getMasterKey() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.groups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ProfileKeyCiphertext extends ByteArray {
public ProfileKeyCiphertext(byte[] contents) throws InvalidInputException {
super(contents);
Native.ProfileKeyCiphertext_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ProfileKeyCiphertext_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.groups;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
@ -15,7 +17,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class UuidCiphertext extends ByteArray {
public UuidCiphertext(byte[] contents) throws InvalidInputException {
super(contents);
Native.UuidCiphertext_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class, () -> Native.UuidCiphertext_CheckValidContents(contents));
}
public static byte[] serializeAndConcatenate(List<UuidCiphertext> ciphertexts) {

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.groupsend;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -27,7 +28,8 @@ public final class GroupSendCredential extends ByteArray {
public GroupSendCredential(byte[] contents) throws InvalidInputException {
super(contents);
Native.GroupSendCredential_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class, () -> Native.GroupSendCredential_CheckValidContents(contents));
}
/** Generates a new presentation, so that multiple uses of this credential are harder to link. */
@ -48,8 +50,10 @@ public final class GroupSendCredential extends ByteArray {
secureRandom.nextBytes(random);
byte[] newContents =
Native.GroupSendCredential_PresentDeterministic(
getInternalContentsForJNI(), serverParams.getInternalContentsForJNI(), random);
filterExceptions(
() ->
Native.GroupSendCredential_PresentDeterministic(
getInternalContentsForJNI(), serverParams.getInternalContentsForJNI(), random));
try {
return new GroupSendCredentialPresentation(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.groupsend;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import java.util.List;
import org.signal.libsignal.internal.Native;
@ -28,7 +30,9 @@ public final class GroupSendCredentialPresentation extends ByteArray {
public GroupSendCredentialPresentation(byte[] contents) throws InvalidInputException {
super(contents);
Native.GroupSendCredentialPresentation_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.GroupSendCredentialPresentation_CheckValidContents(contents));
}
/**
@ -54,10 +58,13 @@ public final class GroupSendCredentialPresentation extends ByteArray {
public void verify(
List<ServiceId> groupMembers, Instant currentTime, ServerSecretParams serverParams)
throws VerificationFailedException {
Native.GroupSendCredentialPresentation_Verify(
getInternalContentsForJNI(),
ServiceId.toConcatenatedFixedWidthBinary(groupMembers),
currentTime.getEpochSecond(),
serverParams.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.GroupSendCredentialPresentation_Verify(
getInternalContentsForJNI(),
ServiceId.toConcatenatedFixedWidthBinary(groupMembers),
currentTime.getEpochSecond(),
serverParams.getInternalContentsForJNI()));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.groupsend;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -33,7 +34,9 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class GroupSendCredentialResponse extends ByteArray {
public GroupSendCredentialResponse(byte[] contents) throws InvalidInputException {
super(contents);
Native.GroupSendCredentialResponse_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.GroupSendCredentialResponse_CheckValidContents(contents));
}
private static Instant defaultExpiration() {
@ -71,12 +74,14 @@ public final class GroupSendCredentialResponse extends ByteArray {
secureRandom.nextBytes(random);
byte[] newContents =
Native.GroupSendCredentialResponse_IssueDeterministic(
UuidCiphertext.serializeAndConcatenate(groupMembers),
requestingUser.getInternalContentsForJNI(),
expiration.getEpochSecond(),
params.getInternalContentsForJNI(),
random);
filterExceptions(
() ->
Native.GroupSendCredentialResponse_IssueDeterministic(
UuidCiphertext.serializeAndConcatenate(groupMembers),
requestingUser.getInternalContentsForJNI(),
expiration.getEpochSecond(),
params.getInternalContentsForJNI(),
random));
try {
return new GroupSendCredentialResponse(newContents);
@ -123,13 +128,16 @@ public final class GroupSendCredentialResponse extends ByteArray {
GroupSecretParams groupParams)
throws VerificationFailedException {
byte[] newContents =
Native.GroupSendCredentialResponse_Receive(
getInternalContentsForJNI(),
ServiceId.toConcatenatedFixedWidthBinary(groupMembers),
localUser.toServiceIdFixedWidthBinary(),
now.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
groupParams.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.GroupSendCredentialResponse_Receive(
getInternalContentsForJNI(),
ServiceId.toConcatenatedFixedWidthBinary(groupMembers),
localUser.toServiceIdFixedWidthBinary(),
now.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
groupParams.getInternalContentsForJNI()));
try {
return new GroupSendCredential(newContents);
@ -176,13 +184,16 @@ public final class GroupSendCredentialResponse extends ByteArray {
GroupSecretParams groupParams)
throws VerificationFailedException {
byte[] newContents =
Native.GroupSendCredentialResponse_ReceiveWithCiphertexts(
getInternalContentsForJNI(),
UuidCiphertext.serializeAndConcatenate(groupMembers),
localUser.getInternalContentsForJNI(),
now.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
groupParams.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.GroupSendCredentialResponse_ReceiveWithCiphertexts(
getInternalContentsForJNI(),
UuidCiphertext.serializeAndConcatenate(groupMembers),
localUser.getInternalContentsForJNI(),
now.getEpochSecond(),
serverParams.getInternalContentsForJNI(),
groupParams.getInternalContentsForJNI()));
try {
return new GroupSendCredential(newContents);

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -66,11 +67,14 @@ public class ClientZkProfileOperations {
}
byte[] newContents =
Native.ServerPublicParams_ReceiveExpiringProfileKeyCredential(
serverPublicParams.getInternalContentsForJNI(),
profileKeyCredentialRequestContext.getInternalContentsForJNI(),
profileKeyCredentialResponse.getInternalContentsForJNI(),
now.getEpochSecond());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerPublicParams_ReceiveExpiringProfileKeyCredential(
serverPublicParams.getInternalContentsForJNI(),
profileKeyCredentialRequestContext.getInternalContentsForJNI(),
profileKeyCredentialResponse.getInternalContentsForJNI(),
now.getEpochSecond()));
try {
return new ExpiringProfileKeyCredential(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import java.time.Instant;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
@ -13,7 +15,9 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ExpiringProfileKeyCredential extends ByteArray {
public ExpiringProfileKeyCredential(byte[] contents) throws InvalidInputException {
super(contents);
Native.ExpiringProfileKeyCredential_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ExpiringProfileKeyCredential_CheckValidContents(contents));
}
public Instant getExpirationTime() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ExpiringProfileKeyCredentialResponse extends ByteArray {
public ExpiringProfileKeyCredentialResponse(byte[] contents) throws InvalidInputException {
super(contents);
Native.ExpiringProfileKeyCredentialResponse_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ExpiringProfileKeyCredentialResponse_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.protocol.ServiceId.Aci;
import org.signal.libsignal.zkgroup.InvalidInputException;
@ -14,7 +16,11 @@ public final class ProfileKey extends ByteArray {
public ProfileKey(byte[] contents) throws InvalidInputException {
super(contents);
Native.ProfileKey_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() ->
filterExceptions(
InvalidInputException.class, () -> Native.ProfileKey_CheckValidContents(contents)));
}
public ProfileKeyCommitment getCommitment(Aci userId) {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,11 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ProfileKeyCommitment extends ByteArray {
public ProfileKeyCommitment(byte[] contents) throws InvalidInputException {
super(contents);
Native.ProfileKeyCommitment_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() ->
filterExceptions(
InvalidInputException.class,
() -> Native.ProfileKeyCommitment_CheckValidContents(contents)));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.groups.ProfileKeyCiphertext;
@ -22,7 +24,9 @@ public final class ProfileKeyCredentialPresentation extends ByteArray {
public ProfileKeyCredentialPresentation(byte[] contents) throws InvalidInputException {
super(contents);
Native.ProfileKeyCredentialPresentation_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ProfileKeyCredentialPresentation_CheckValidContents(contents));
}
public UuidCiphertext getUuidCiphertext() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ProfileKeyCredentialRequest extends ByteArray {
public ProfileKeyCredentialRequest(byte[] contents) throws InvalidInputException {
super(contents);
Native.ProfileKeyCredentialRequest_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ProfileKeyCredentialRequest_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,7 +14,9 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ProfileKeyCredentialRequestContext extends ByteArray {
public ProfileKeyCredentialRequestContext(byte[] contents) throws InvalidInputException {
super(contents);
Native.ProfileKeyCredentialRequestContext_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ProfileKeyCredentialRequestContext_CheckValidContents(contents));
}
public ProfileKeyCredentialRequest getRequest() {

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.profiles;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -54,13 +55,16 @@ public class ServerZkProfileOperations {
secureRandom.nextBytes(random);
byte[] newContents =
Native.ServerSecretParams_IssueExpiringProfileKeyCredentialDeterministic(
serverSecretParams.getInternalContentsForJNI(),
random,
profileKeyCredentialRequest.getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary(),
profileKeyCommitment.getInternalContentsForJNI(),
expiration.getEpochSecond());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerSecretParams_IssueExpiringProfileKeyCredentialDeterministic(
serverSecretParams.getInternalContentsForJNI(),
random,
profileKeyCredentialRequest.getInternalContentsForJNI(),
userId.toServiceIdFixedWidthBinary(),
profileKeyCommitment.getInternalContentsForJNI(),
expiration.getEpochSecond()));
try {
return new ExpiringProfileKeyCredentialResponse(newContents);
@ -82,10 +86,13 @@ public class ServerZkProfileOperations {
ProfileKeyCredentialPresentation profileKeyCredentialPresentation,
Instant now)
throws VerificationFailedException {
Native.ServerSecretParams_VerifyProfileKeyCredentialPresentation(
serverSecretParams.getInternalContentsForJNI(),
groupPublicParams.getInternalContentsForJNI(),
profileKeyCredentialPresentation.getInternalContentsForJNI(),
now.getEpochSecond());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerSecretParams_VerifyProfileKeyCredentialPresentation(
serverSecretParams.getInternalContentsForJNI(),
groupPublicParams.getInternalContentsForJNI(),
profileKeyCredentialPresentation.getInternalContentsForJNI(),
now.getEpochSecond()));
}
}

View File

@ -5,6 +5,7 @@
package org.signal.libsignal.zkgroup.receipts;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import static org.signal.libsignal.zkgroup.internal.Constants.RANDOM_LENGTH;
import java.security.SecureRandom;
@ -49,10 +50,13 @@ public class ClientZkReceiptOperations {
ReceiptCredentialResponse receiptCredentialResponse)
throws VerificationFailedException {
byte[] newContents =
Native.ServerPublicParams_ReceiveReceiptCredential(
serverPublicParams.getInternalContentsForJNI(),
receiptCredentialRequestContext.getInternalContentsForJNI(),
receiptCredentialResponse.getInternalContentsForJNI());
filterExceptions(
VerificationFailedException.class,
() ->
Native.ServerPublicParams_ReceiveReceiptCredential(
serverPublicParams.getInternalContentsForJNI(),
receiptCredentialRequestContext.getInternalContentsForJNI(),
receiptCredentialResponse.getInternalContentsForJNI()));
try {
return new ReceiptCredential(newContents);

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.receipts;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -13,7 +15,8 @@ public final class ReceiptCredential extends ByteArray {
public ReceiptCredential(byte[] contents) throws InvalidInputException {
super(contents);
Native.ReceiptCredential_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class, () -> Native.ReceiptCredential_CheckValidContents(contents));
}
public long getReceiptExpirationTime() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.receipts;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,7 +14,12 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ReceiptCredentialPresentation extends ByteArray {
public ReceiptCredentialPresentation(byte[] contents) throws InvalidInputException {
super(contents);
Native.ReceiptCredentialPresentation_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() ->
filterExceptions(
InvalidInputException.class,
() -> Native.ReceiptCredentialPresentation_CheckValidContents(contents)));
}
public long getReceiptExpirationTime() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.receipts;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ReceiptCredentialRequest extends ByteArray {
public ReceiptCredentialRequest(byte[] contents) throws InvalidInputException {
super(contents);
Native.ReceiptCredentialRequest_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ReceiptCredentialRequest_CheckValidContents(contents));
}
}

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.receipts;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -15,7 +17,9 @@ public final class ReceiptCredentialRequestContext extends ByteArray {
public ReceiptCredentialRequestContext(byte[] contents) throws InvalidInputException {
super(contents, SIZE);
Native.ReceiptCredentialRequestContext_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ReceiptCredentialRequestContext_CheckValidContents(contents));
}
public ReceiptCredentialRequest getRequest() {

View File

@ -5,6 +5,8 @@
package org.signal.libsignal.zkgroup.receipts;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;
@ -12,6 +14,8 @@ import org.signal.libsignal.zkgroup.internal.ByteArray;
public final class ReceiptCredentialResponse extends ByteArray {
public ReceiptCredentialResponse(byte[] contents) throws InvalidInputException {
super(contents);
Native.ReceiptCredentialResponse_CheckValidContents(contents);
filterExceptions(
InvalidInputException.class,
() -> Native.ReceiptCredentialResponse_CheckValidContents(contents));
}
}

Some files were not shown because too many files have changed in this diff Show More