Replace `TreeSearchResponse` with `CondensedTreeSearchResponse`

This commit is contained in:
Katherine 2024-11-04 10:36:15 -05:00 committed by GitHub
parent 00d0dba62c
commit 7633a9b07a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 21 deletions

View File

@ -121,10 +121,7 @@ public class KeyTransparencyController {
request.lastTreeHeadSize(), request.lastTreeHeadSize(),
request.distinguishedTreeHeadSize(), request.distinguishedTreeHeadSize(),
KEY_TRANSPARENCY_RPC_TIMEOUT) KEY_TRANSPARENCY_RPC_TIMEOUT)
.thenApply(searchResponse -> .thenApply(KeyTransparencySearchResponse::new).join();
new KeyTransparencySearchResponse(
searchResponse.toByteArray())
).join();
} catch (final CancellationException exception) { } catch (final CancellationException exception) {
LOGGER.error("Unexpected cancellation from key transparency service", exception); LOGGER.error("Unexpected cancellation from key transparency service", exception);
throw new ServerErrorException(Response.Status.SERVICE_UNAVAILABLE, exception); throw new ServerErrorException(Response.Status.SERVICE_UNAVAILABLE, exception);

View File

@ -31,7 +31,6 @@ import org.signal.keytransparency.client.KeyTransparencyQueryServiceGrpc;
import org.signal.keytransparency.client.MonitorKey; import org.signal.keytransparency.client.MonitorKey;
import org.signal.keytransparency.client.MonitorRequest; import org.signal.keytransparency.client.MonitorRequest;
import org.signal.keytransparency.client.SearchRequest; import org.signal.keytransparency.client.SearchRequest;
import org.signal.keytransparency.client.SearchResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.metrics.MetricsUtil; import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
@ -113,7 +112,7 @@ public class KeyTransparencyServiceClient implements Managed {
} }
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public CompletableFuture<SearchResponse> search( public CompletableFuture<byte[]> search(
final ByteString aci, final ByteString aci,
final ByteString aciIdentityKey, final ByteString aciIdentityKey,
final Optional<ByteString> usernameHash, final Optional<ByteString> usernameHash,
@ -121,21 +120,22 @@ public class KeyTransparencyServiceClient implements Managed {
final Optional<Long> lastTreeHeadSize, final Optional<Long> lastTreeHeadSize,
final long distinguishedTreeHeadSize, final long distinguishedTreeHeadSize,
final Duration timeout) { final Duration timeout) {
final SearchRequest.Builder searchKeysRequestBuilder = SearchRequest.newBuilder() final SearchRequest.Builder searchRequestBuilder = SearchRequest.newBuilder()
.setAci(aci) .setAci(aci)
.setAciIdentityKey(aciIdentityKey); .setAciIdentityKey(aciIdentityKey);
usernameHash.ifPresent(searchKeysRequestBuilder::setUsernameHash); usernameHash.ifPresent(searchRequestBuilder::setUsernameHash);
e164SearchRequest.ifPresent(searchKeysRequestBuilder::setE164SearchRequest); e164SearchRequest.ifPresent(searchRequestBuilder::setE164SearchRequest);
final ConsistencyParameters.Builder consistency = ConsistencyParameters.newBuilder() final ConsistencyParameters.Builder consistency = ConsistencyParameters.newBuilder()
.setDistinguished(distinguishedTreeHeadSize); .setDistinguished(distinguishedTreeHeadSize);
lastTreeHeadSize.ifPresent(consistency::setLast); lastTreeHeadSize.ifPresent(consistency::setLast);
searchKeysRequestBuilder.setConsistency(consistency.build()); searchRequestBuilder.setConsistency(consistency.build());
return CompletableFutureUtil.toCompletableFuture(stub.withDeadline(toDeadline(timeout)) return CompletableFutureUtil.toCompletableFuture(stub.withDeadline(toDeadline(timeout))
.search(searchKeysRequestBuilder.build()), callbackExecutor); .search(searchRequestBuilder.build()), callbackExecutor)
.thenApply(AbstractMessageLite::toByteArray);
} }
public CompletableFuture<byte[]> monitor(final List<MonitorKey> monitorKeys, public CompletableFuture<byte[]> monitor(final List<MonitorKey> monitorKeys,

View File

@ -89,7 +89,7 @@ message SearchResponse {
/** /**
* The ACI search response is always provided. * The ACI search response is always provided.
*/ */
TreeSearchResponse aci = 2; CondensedTreeSearchResponse aci = 2;
/** /**
* This response is only provided if all of the conditions are met: * This response is only provided if all of the conditions are met:
* - the E164 exists in the log * - the E164 exists in the log
@ -97,12 +97,12 @@ message SearchResponse {
* - the account associated with the ACI is discoverable * - the account associated with the ACI is discoverable
* - the unidentified access key provided in E164SearchRequest matches the one on the account * - the unidentified access key provided in E164SearchRequest matches the one on the account
*/ */
optional TreeSearchResponse e164 = 3; optional CondensedTreeSearchResponse e164 = 3;
/** /**
* This response is only provided if the username hash exists in the log and * This response is only provided if the username hash exists in the log and
* its mapped ACI matches the one provided in the request. * its mapped ACI matches the one provided in the request.
*/ */
optional TreeSearchResponse username_hash = 4; optional CondensedTreeSearchResponse username_hash = 4;
} }
/** /**
@ -152,10 +152,10 @@ message DistinguishedResponse {
/** /**
* This search response is always provided. * This search response is always provided.
*/ */
TreeSearchResponse distinguished = 2; CondensedTreeSearchResponse distinguished = 2;
} }
message TreeSearchResponse { message CondensedTreeSearchResponse {
/** /**
* A proof that is combined with the original requested identifier and the VRF public key * A proof that is combined with the original requested identifier and the VRF public key
* and outputs whether the proof is valid, and if so, the commitment index. * and outputs whether the proof is valid, and if so, the commitment index.

View File

@ -59,7 +59,7 @@ import org.signal.keytransparency.client.E164SearchRequest;
import org.signal.keytransparency.client.FullTreeHead; import org.signal.keytransparency.client.FullTreeHead;
import org.signal.keytransparency.client.SearchProof; import org.signal.keytransparency.client.SearchProof;
import org.signal.keytransparency.client.SearchResponse; import org.signal.keytransparency.client.SearchResponse;
import org.signal.keytransparency.client.TreeSearchResponse; import org.signal.keytransparency.client.CondensedTreeSearchResponse;
import org.signal.keytransparency.client.UpdateValue; import org.signal.keytransparency.client.UpdateValue;
import org.signal.libsignal.protocol.IdentityKey; import org.signal.libsignal.protocol.IdentityKey;
import org.signal.libsignal.protocol.ecc.Curve; import org.signal.libsignal.protocol.ecc.Curve;
@ -140,7 +140,7 @@ public class KeyTransparencyControllerTest {
@ParameterizedTest @ParameterizedTest
@MethodSource @MethodSource
void searchSuccess(final Optional<String> e164, final Optional<byte[]> usernameHash) { void searchSuccess(final Optional<String> e164, final Optional<byte[]> usernameHash) {
final TreeSearchResponse aciSearchResponse = TreeSearchResponse.newBuilder() final CondensedTreeSearchResponse aciSearchResponse = CondensedTreeSearchResponse.newBuilder()
.setOpening(ByteString.copyFrom(TestRandomUtil.nextBytes(16))) .setOpening(ByteString.copyFrom(TestRandomUtil.nextBytes(16)))
.setSearch(SearchProof.getDefaultInstance()) .setSearch(SearchProof.getDefaultInstance())
.setValue(UpdateValue.newBuilder() .setValue(UpdateValue.newBuilder()
@ -152,11 +152,11 @@ public class KeyTransparencyControllerTest {
.setTreeHead(FullTreeHead.getDefaultInstance()) .setTreeHead(FullTreeHead.getDefaultInstance())
.setAci(aciSearchResponse); .setAci(aciSearchResponse);
e164.ifPresent(ignored -> searchResponseBuilder.setE164(TreeSearchResponse.getDefaultInstance())); e164.ifPresent(ignored -> searchResponseBuilder.setE164(CondensedTreeSearchResponse.getDefaultInstance()));
usernameHash.ifPresent(ignored -> searchResponseBuilder.setUsernameHash(TreeSearchResponse.getDefaultInstance())); usernameHash.ifPresent(ignored -> searchResponseBuilder.setUsernameHash(CondensedTreeSearchResponse.getDefaultInstance()));
when(keyTransparencyServiceClient.search(any(), any(), any(), any(), any(), anyLong(), any())) when(keyTransparencyServiceClient.search(any(), any(), any(), any(), any(), anyLong(), any()))
.thenReturn(CompletableFuture.completedFuture(searchResponseBuilder.build())); .thenReturn(CompletableFuture.completedFuture(searchResponseBuilder.build().toByteArray()));
final Invocation.Builder request = resources.getJerseyTest() final Invocation.Builder request = resources.getJerseyTest()
.target("/v1/key-transparency/search") .target("/v1/key-transparency/search")