diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ArchiveController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ArchiveController.java index 99e1a7e5c..711393d53 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ArchiveController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ArchiveController.java @@ -32,7 +32,6 @@ import javax.validation.Valid; import javax.validation.constraints.Max; import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.PositiveOrZero; import javax.validation.constraints.Size; @@ -60,13 +59,13 @@ import org.whispersystems.textsecuregcm.backup.CopyParameters; import org.whispersystems.textsecuregcm.backup.CopyResult; import org.whispersystems.textsecuregcm.backup.MediaEncryptionParameters; +import org.whispersystems.textsecuregcm.entities.RemoteAttachment; import org.whispersystems.textsecuregcm.util.BackupAuthCredentialAdapter; import org.whispersystems.textsecuregcm.util.ByteArrayAdapter; import org.whispersystems.textsecuregcm.util.ByteArrayBase64UrlAdapter; import org.whispersystems.textsecuregcm.util.ECPublicKeyAdapter; import org.whispersystems.textsecuregcm.util.ExactlySize; import org.whispersystems.textsecuregcm.util.Util; -import org.whispersystems.textsecuregcm.util.ValidBase64URLString; import org.whispersystems.websocket.auth.Mutable; import org.whispersystems.websocket.auth.ReadOnly; import reactor.core.publisher.Mono; @@ -462,16 +461,6 @@ public CompletionStage uploadTemporaryAttachment( result.signedUploadLocation())); } - public record RemoteAttachment( - @Schema(description = "The attachment cdn") - @NotNull - Integer cdn, - - @NotBlank - @ValidBase64URLString - @Schema(description = "The attachment key") - String key) {} - public record CopyMediaRequest( @Schema(description = "The object on the attachment CDN to copy") @NotNull @@ -510,7 +499,7 @@ public record CopyMediaRequest( CopyParameters toCopyParameters() { return new CopyParameters( - sourceAttachment.cdn, sourceAttachment.key, + sourceAttachment.cdn(), sourceAttachment.key(), objectLength, new MediaEncryptionParameters(encryptionKey, hmacKey, iv), mediaId); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/RemoteAttachment.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/RemoteAttachment.java new file mode 100644 index 000000000..9b95e0554 --- /dev/null +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/RemoteAttachment.java @@ -0,0 +1,22 @@ +/* + * Copyright 2024 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ + +package org.whispersystems.textsecuregcm.entities; + +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import org.whispersystems.textsecuregcm.util.ValidBase64URLString; + +public record RemoteAttachment( + @Schema(description = "The attachment cdn") + @NotNull + Integer cdn, + + @NotBlank + @ValidBase64URLString + @Schema(description = "The attachment key") + String key) { +} diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/ArchiveControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/ArchiveControllerTest.java index 21de15c31..a26955c90 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/ArchiveControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/ArchiveControllerTest.java @@ -66,6 +66,7 @@ import org.whispersystems.textsecuregcm.backup.BackupManager; import org.whispersystems.textsecuregcm.backup.BackupUploadDescriptor; import org.whispersystems.textsecuregcm.backup.CopyResult; +import org.whispersystems.textsecuregcm.entities.RemoteAttachment; import org.whispersystems.textsecuregcm.mappers.CompletionExceptionMapper; import org.whispersystems.textsecuregcm.mappers.GrpcStatusRuntimeExceptionMapper; import org.whispersystems.textsecuregcm.mappers.RateLimitExceededExceptionMapper; @@ -357,7 +358,7 @@ public void putMediaBatchSuccess() throws VerificationFailedException { .header("X-Signal-ZK-Auth-Signature", "aaa") .put(Entity.json(new ArchiveController.CopyMediaBatchRequest(List.of( new ArchiveController.CopyMediaRequest( - new ArchiveController.RemoteAttachment(3, "abc"), + new RemoteAttachment(3, "abc"), 100, mediaIds[0], TestRandomUtil.nextBytes(32), @@ -365,7 +366,7 @@ public void putMediaBatchSuccess() throws VerificationFailedException { TestRandomUtil.nextBytes(16)), new ArchiveController.CopyMediaRequest( - new ArchiveController.RemoteAttachment(3, "def"), + new RemoteAttachment(3, "def"), 200, mediaIds[1], TestRandomUtil.nextBytes(32), @@ -402,7 +403,7 @@ public void putMediaBatchPartialFailure() throws VerificationFailedException { final List copyRequests = Arrays.stream(mediaIds) .map(mediaId -> new ArchiveController.CopyMediaRequest( - new ArchiveController.RemoteAttachment(3, "abc"), + new RemoteAttachment(3, "abc"), 100, mediaId, TestRandomUtil.nextBytes(32), @@ -458,7 +459,7 @@ public void copyMediaWithNegativeLength() throws VerificationFailedException { .header("X-Signal-ZK-Auth-Signature", "aaa") .put(Entity.json(new ArchiveController.CopyMediaBatchRequest(List.of( new ArchiveController.CopyMediaRequest( - new ArchiveController.RemoteAttachment(3, "abc"), + new RemoteAttachment(3, "abc"), 1, mediaIds[0], TestRandomUtil.nextBytes(32), @@ -466,7 +467,7 @@ public void copyMediaWithNegativeLength() throws VerificationFailedException { TestRandomUtil.nextBytes(16)), new ArchiveController.CopyMediaRequest( - new ArchiveController.RemoteAttachment(3, "def"), + new RemoteAttachment(3, "def"), -1, mediaIds[1], TestRandomUtil.nextBytes(32), @@ -639,7 +640,7 @@ public void invalidSourceAttachmentKey() throws VerificationFailedException { .header("X-Signal-ZK-Auth", Base64.getEncoder().encodeToString(presentation.serialize())) .header("X-Signal-ZK-Auth-Signature", "aaa") .put(Entity.json(new ArchiveController.CopyMediaRequest( - new ArchiveController.RemoteAttachment(3, "invalid/urlBase64"), + new RemoteAttachment(3, "invalid/urlBase64"), 100, TestRandomUtil.nextBytes(15), TestRandomUtil.nextBytes(32),