diff --git a/service/config/sample.yml b/service/config/sample.yml index 5c82854d3..fa9f31e80 100644 --- a/service/config/sample.yml +++ b/service/config/sample.yml @@ -255,7 +255,8 @@ fcm: # FCM configuration credentials: secret://fcm.credentials cdn: - bucket: cdn # S3 Bucket name + baseUrl: https://cdn.example.com # Public base URL for objects in the bucket + bucket: cdn # S3 Bucket name credentials: accessKeyId: secret://cdn.accessKey secretAccessKey: secret://cdn.accessSecret diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index f7858ce3c..56dc33af9 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -1141,7 +1141,8 @@ public class WhisperServerService extends Application ProfileGrpcHelper - .getProfileV1(account, profilesManager, profileBadgeConverter, version) + .getProfileV1(account, profilesManager, profileBadgeConverter, cdnBaseUrl, version) .map(v1Result -> GetProfileAnonymousResponse.newBuilder().setProfileV1(v1Result).build()))) .orElseGet(() -> GetProfileAnonymousResponse.newBuilder().setNotFound(NotFound.getDefaultInstance()).build()); @@ -238,7 +244,7 @@ public class ProfileAnonymousGrpcService extends SimpleProfileAnonymousGrpc.Prof return profilesManager.extendAvatarTtlForIdentity(identity) .map(extendedPath -> ExtendAvatarTTLResponse.newBuilder() - .setPath(extendedPath) + .setUrl(ProfileGrpcHelper.cdnUrl(cdnBaseUrl, extendedPath)) .build()) .orElseGet(() -> ExtendAvatarTTLResponse.newBuilder() .setNotFound(NotFound.getDefaultInstance()) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcHelper.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcHelper.java index d50e2aeed..432e0cc91 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcHelper.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcHelper.java @@ -14,6 +14,7 @@ import java.time.Clock; import java.util.Arrays; import java.util.HexFormat; import java.util.Optional; +import org.apache.commons.lang3.Strings; import org.bouncycastle.crypto.digests.TupleHash; import org.signal.chat.common.S3UploadForm; import org.signal.chat.profile.AccountInfo; @@ -47,9 +48,14 @@ public class ProfileGrpcHelper { .setAlgorithm(PostPolicyGenerator.ALGORITHM) .build(); + static String cdnUrl(final String cdnBaseUrl, final String path) { + return Strings.CS.removeEnd(cdnBaseUrl, "/") + "/" + Strings.CS.removeStart(path, "/"); + } + static Optional getProfileV1(final Account account, final ProfilesManager profilesManager, final ProfileBadgeConverter profileBadgeConverter, + final String cdnBaseUrl, final byte[] requestVersion) { final Optional maybeV1Profile = profilesManager.getV1(account.getAccountIdentifier(), HexFormat.of().formatHex(requestVersion)); @@ -74,7 +80,7 @@ public class ProfileGrpcHelper { builder.setPhoneNumberSharing(ByteString.copyFrom(v1Profile.phoneNumberSharing())); } if (v1Profile.avatar() != null) { - builder.setAvatar(v1Profile.avatar()); + builder.setAvatarUrl(cdnUrl(cdnBaseUrl, v1Profile.avatar())); } // If present, include the payment address if the version matches the latest version on Account or the latest diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcService.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcService.java index 82cc712d0..2da2487b0 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcService.java @@ -18,6 +18,7 @@ import java.util.UUID; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; +import org.apache.commons.lang3.Strings; import org.signal.chat.common.S3UploadForm; import org.signal.chat.errors.FailedPrecondition; import org.signal.chat.errors.NotFound; @@ -73,6 +74,7 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase { private final GenericServerSecretParams genericServerSecretParams; private final ProfileBadgeConverter profileBadgeConverter; private final RateLimiters rateLimiters; + private final String cdnBaseUrl; private record AvatarData(Optional currentAvatar, Optional finalAvatar, @@ -86,6 +88,7 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase { final DynamicConfigurationManager dynamicConfigurationManager, final BadgesConfiguration badgesConfiguration, final PostPolicyGenerator policyGenerator, + final String cdnBaseUrl, final GenericServerSecretParams genericServerSecretParams, final ProfileBadgeConverter profileBadgeConverter, final RateLimiters rateLimiters) { @@ -97,6 +100,7 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase { this.badgeConfigurationMap = badgesConfiguration.getBadges().stream() .collect(Collectors.toMap(BadgeConfiguration::getId, Function.identity())); this.policyGenerator = policyGenerator; + this.cdnBaseUrl = Strings.CS.removeEnd(cdnBaseUrl, "/"); this.genericServerSecretParams = genericServerSecretParams; this.profileBadgeConverter = profileBadgeConverter; this.rateLimiters = rateLimiters; @@ -268,7 +272,7 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase { // If we didn't find a v2 profile, try a v1 profile .or(() -> ProfileGrpcHelper - .getProfileV1(account, profilesManager, profileBadgeConverter, version) + .getProfileV1(account, profilesManager, profileBadgeConverter, cdnBaseUrl, version) .map(v1Result -> GetProfileResponse.newBuilder().setLegacyProfile(v1Result).build()))) .orElseGet(() -> GetProfileResponse.newBuilder().setNotFound(NotFound.getDefaultInstance()).build()); } diff --git a/service/src/main/proto/org/signal/chat/profile.proto b/service/src/main/proto/org/signal/chat/profile.proto index d14397687..a81c07608 100644 --- a/service/src/main/proto/org/signal/chat/profile.proto +++ b/service/src/main/proto/org/signal/chat/profile.proto @@ -289,8 +289,8 @@ message LegacyProfileResult { bytes about = 2; // The ciphertext of the emoji on the profile. bytes about_emoji = 3; - // The cdn0 path of the avatar on the profile. - string avatar = 4; + // The URL of the avatar on the profile. + string avatar_url = 4; // The ciphertext of the phone-number sharing setting on the profile. bytes phone_number_sharing = 5; // The ciphertext of the MobileCoin wallet ID on the profile. @@ -414,7 +414,7 @@ message ExtendAvatarTTLRequest { message ExtendAvatarTTLResponse { oneof response { // The avatar that was extended. May be used as a check against state de-synchronization. - string path = 1; + string url = 1; errors.FailedZkAuthentication invalid_credential_presentation = 2 [(tag.reason) = "invalid_credential_presentation"]; // the identity does not have an active avatar errors.NotFound not_found = 3 [(tag.reason) = "no_active_avatar"]; diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileAnonymousGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileAnonymousGrpcServiceTest.java index 14f322b78..afc5695de 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileAnonymousGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileAnonymousGrpcServiceTest.java @@ -111,6 +111,8 @@ import org.whispersystems.textsecuregcm.util.UUIDUtil; public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest { + private static final String CDN_BASE_URL = "https://cdn.example.com"; + private static final ServerSecretParams SERVER_SECRET_PARAMS = ServerSecretParams.generate(); @Mock @@ -152,6 +154,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest cdnUrl() { + return Stream.of( + Arguments.of("https://cdn.example.com", "profiles/abc"), + Arguments.of("https://cdn.example.com/", "profiles/abc"), + Arguments.of("https://cdn.example.com", "/profiles/abc"), + Arguments.of("https://cdn.example.com/", "/profiles/abc")); + } + private static ProfileResult.Builder profile() { return ProfileResult.newBuilder() .setData(ByteString.copyFromUtf8("profile-data")) diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcServiceTest.java index 1dfc55708..f6f4b864e 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/ProfileGrpcServiceTest.java @@ -118,6 +118,8 @@ import org.whispersystems.textsecuregcm.util.UUIDUtil; public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest { + private static final String CDN_BASE_URL = "https://cdn.example.com"; + private static final byte[] VERSION = TestRandomUtil.nextBytes(32); private static final byte[] VALID_DATA = new byte[128]; @@ -215,6 +217,7 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest