mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 03:08:04 +01:00
Align chat endpoints with "distinguished key" changes in key transparency service
This commit is contained in:
@@ -57,7 +57,8 @@ import java.util.concurrent.CompletionException;
|
||||
public class KeyTransparencyController {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(KeyTransparencyController.class);
|
||||
private static final Duration KEY_TRANSPARENCY_RPC_TIMEOUT = Duration.ofSeconds(15);
|
||||
@VisibleForTesting
|
||||
static final Duration KEY_TRANSPARENCY_RPC_TIMEOUT = Duration.ofSeconds(15);
|
||||
private static final byte USERNAME_PREFIX = (byte) 'u';
|
||||
private static final byte E164_PREFIX = (byte) 'n';
|
||||
@VisibleForTesting
|
||||
@@ -95,12 +96,14 @@ public class KeyTransparencyController {
|
||||
final CompletableFuture<SearchResponse> aciSearchKeyResponseFuture = keyTransparencyServiceClient.search(
|
||||
getFullSearchKeyByteString(ACI_PREFIX, request.aci().toCompactByteArray()),
|
||||
request.lastTreeHeadSize(),
|
||||
request.distinguishedTreeHeadSize(),
|
||||
KEY_TRANSPARENCY_RPC_TIMEOUT);
|
||||
|
||||
final CompletableFuture<SearchResponse> e164SearchKeyResponseFuture = request.e164()
|
||||
.map(e164 -> keyTransparencyServiceClient.search(
|
||||
getFullSearchKeyByteString(E164_PREFIX, e164.getBytes(StandardCharsets.UTF_8)),
|
||||
request.lastTreeHeadSize(),
|
||||
request.distinguishedTreeHeadSize(),
|
||||
KEY_TRANSPARENCY_RPC_TIMEOUT))
|
||||
.orElse(CompletableFuture.completedFuture(null));
|
||||
|
||||
@@ -108,6 +111,7 @@ public class KeyTransparencyController {
|
||||
.map(usernameHash -> keyTransparencyServiceClient.search(
|
||||
getFullSearchKeyByteString(USERNAME_PREFIX, request.usernameHash().get()),
|
||||
request.lastTreeHeadSize(),
|
||||
request.distinguishedTreeHeadSize(),
|
||||
KEY_TRANSPARENCY_RPC_TIMEOUT))
|
||||
.orElse(CompletableFuture.completedFuture(null));
|
||||
|
||||
@@ -169,7 +173,8 @@ public class KeyTransparencyController {
|
||||
|
||||
final MonitorResponse monitorResponse = keyTransparencyServiceClient.monitor(
|
||||
monitorKeys,
|
||||
request.lastTreeHeadSize(),
|
||||
request.lastNonDistinguishedTreeHeadSize(),
|
||||
request.lastDistinguishedTreeHeadSize(),
|
||||
KEY_TRANSPARENCY_RPC_TIMEOUT).join();
|
||||
|
||||
MonitorProof usernameHashMonitorProof = null;
|
||||
|
||||
@@ -45,7 +45,10 @@ public record KeyTransparencyMonitorRequest(
|
||||
Optional<List<@Positive Long>> usernameHashPositions,
|
||||
|
||||
@Schema(description = "The tree head size to prove consistency against.")
|
||||
Optional<@Positive Long> lastTreeHeadSize
|
||||
Optional<@Positive Long> lastNonDistinguishedTreeHeadSize,
|
||||
|
||||
@Schema(description = "The distinguished tree head size to prove consistency against.")
|
||||
Optional<@Positive Long> lastDistinguishedTreeHeadSize
|
||||
) {
|
||||
|
||||
@AssertTrue
|
||||
|
||||
@@ -33,6 +33,9 @@ public record KeyTransparencySearchRequest(
|
||||
@Schema(description = "The username hash to look up, encoded in web-safe unpadded base64.")
|
||||
Optional<byte[]> usernameHash,
|
||||
|
||||
@Schema(description = "The tree head size to prove consistency against.")
|
||||
Optional<@Positive Long> lastTreeHeadSize
|
||||
@Schema(description = "The non-distinguished tree head size to prove consistency against.")
|
||||
Optional<@Positive Long> lastTreeHeadSize,
|
||||
|
||||
@Schema(description = "The distinguished tree head size to prove consistency against.")
|
||||
Optional<@Positive Long> distinguishedTreeHeadSize
|
||||
) {}
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.grpc.TlsChannelCredentials;
|
||||
import katie.ConsistencyParameters;
|
||||
import katie.KatieGrpc;
|
||||
import katie.MonitorKey;
|
||||
import katie.MonitorRequest;
|
||||
@@ -55,11 +56,16 @@ public class KeyTransparencyServiceClient implements Managed {
|
||||
public CompletableFuture<SearchResponse> search(
|
||||
final ByteString searchKey,
|
||||
final Optional<Long> lastTreeHeadSize,
|
||||
final Optional<Long> distinguishedTreeHeadSize,
|
||||
final Duration timeout) {
|
||||
final SearchRequest.Builder searchRequestBuilder = SearchRequest.newBuilder()
|
||||
.setSearchKey(searchKey);
|
||||
|
||||
lastTreeHeadSize.ifPresent(searchRequestBuilder::setLast);
|
||||
final ConsistencyParameters.Builder consistency = ConsistencyParameters.newBuilder();
|
||||
lastTreeHeadSize.ifPresent(consistency::setLast);
|
||||
distinguishedTreeHeadSize.ifPresent(consistency::setDistinguished);
|
||||
|
||||
searchRequestBuilder.setConsistency(consistency);
|
||||
|
||||
return CompletableFutureUtil.toCompletableFuture(stub.withDeadline(toDeadline(timeout))
|
||||
.search(searchRequestBuilder.build()), callbackExecutor);
|
||||
@@ -67,11 +73,16 @@ public class KeyTransparencyServiceClient implements Managed {
|
||||
|
||||
public CompletableFuture<MonitorResponse> monitor(final List<MonitorKey> monitorKeys,
|
||||
final Optional<Long> lastTreeHeadSize,
|
||||
final Optional<Long> distinguishedTreeHeadSize,
|
||||
final Duration timeout) {
|
||||
final MonitorRequest.Builder monitorRequestBuilder = MonitorRequest.newBuilder()
|
||||
.addAllContactKeys(monitorKeys);
|
||||
|
||||
lastTreeHeadSize.ifPresent(monitorRequestBuilder::setLast);
|
||||
final ConsistencyParameters.Builder consistency = ConsistencyParameters.newBuilder();
|
||||
lastTreeHeadSize.ifPresent(consistency::setLast);
|
||||
distinguishedTreeHeadSize.ifPresent(consistency::setDistinguished);
|
||||
|
||||
monitorRequestBuilder.setConsistency(consistency);
|
||||
|
||||
return CompletableFutureUtil.toCompletableFuture(stub.withDeadline(toDeadline(timeout))
|
||||
.monitor(monitorRequestBuilder.build()), callbackExecutor);
|
||||
|
||||
Reference in New Issue
Block a user