Search in sources :

Example 1 with ProfileAvatarData

use of org.whispersystems.signalservice.internal.push.ProfileAvatarData in project libsignal-service-java by signalapp.

the class SignalServiceAccountManager method setProfileAvatar.

public void setProfileAvatar(byte[] key, StreamDetails avatar) throws IOException {
    ProfileAvatarData profileAvatarData = null;
    if (avatar != null) {
        profileAvatarData = new ProfileAvatarData(avatar.getStream(), ProfileCipherOutputStream.getCiphertextLength(avatar.getLength()), avatar.getContentType(), new ProfileCipherOutputStreamFactory(key));
    }
    this.pushServiceSocket.setProfileAvatar(profileAvatarData);
}
Also used : ProfileCipherOutputStreamFactory(org.whispersystems.signalservice.internal.push.http.ProfileCipherOutputStreamFactory) ProfileAvatarData(org.whispersystems.signalservice.internal.push.ProfileAvatarData)

Example 2 with ProfileAvatarData

use of org.whispersystems.signalservice.internal.push.ProfileAvatarData in project Signal-Android by signalapp.

the class SignalServiceAccountManager method setVersionedProfile.

/**
 * @return The avatar URL path, if one was written.
 */
public Optional<String> setVersionedProfile(ACI aci, ProfileKey profileKey, String name, String about, String aboutEmoji, Optional<SignalServiceProtos.PaymentAddress> paymentsAddress, StreamDetails avatar, List<String> visibleBadgeIds) throws IOException {
    if (name == null)
        name = "";
    ProfileCipher profileCipher = new ProfileCipher(profileKey);
    byte[] ciphertextName = profileCipher.encryptString(name, ProfileCipher.getTargetNameLength(name));
    byte[] ciphertextAbout = profileCipher.encryptString(about, ProfileCipher.getTargetAboutLength(about));
    byte[] ciphertextEmoji = profileCipher.encryptString(aboutEmoji, ProfileCipher.EMOJI_PADDED_LENGTH);
    byte[] ciphertextMobileCoinAddress = paymentsAddress.transform(address -> profileCipher.encryptWithLength(address.toByteArray(), ProfileCipher.PAYMENTS_ADDRESS_CONTENT_SIZE)).orNull();
    boolean hasAvatar = avatar != null;
    ProfileAvatarData profileAvatarData = null;
    if (hasAvatar) {
        profileAvatarData = new ProfileAvatarData(avatar.getStream(), ProfileCipherOutputStream.getCiphertextLength(avatar.getLength()), avatar.getContentType(), new ProfileCipherOutputStreamFactory(profileKey));
    }
    return this.pushServiceSocket.writeProfile(new SignalServiceProfileWrite(profileKey.getProfileKeyVersion(aci.uuid()).serialize(), ciphertextName, ciphertextAbout, ciphertextEmoji, ciphertextMobileCoinAddress, hasAvatar, profileKey.getCommitment(aci.uuid()).serialize(), visibleBadgeIds), profileAvatarData);
}
Also used : ReadOperation(org.whispersystems.signalservice.internal.storage.protos.ReadOperation) ServiceIdType(org.whispersystems.signalservice.api.push.ServiceIdType) Quote(org.whispersystems.signalservice.internal.contacts.crypto.Quote) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) StorageManifest(org.whispersystems.signalservice.internal.storage.protos.StorageManifest) ProfileCipher(org.whispersystems.signalservice.api.crypto.ProfileCipher) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) StorageKey(org.whispersystems.signalservice.api.storage.StorageKey) Preconditions(org.whispersystems.libsignal.util.guava.Preconditions) Map(java.util.Map) SignalStorageModels(org.whispersystems.signalservice.api.storage.SignalStorageModels) AuthCredentials(org.whispersystems.signalservice.internal.push.AuthCredentials) ProvisionMessage(org.whispersystems.signalservice.internal.push.ProvisioningProtos.ProvisionMessage) RequestVerificationCodeResponse(org.whispersystems.signalservice.internal.push.RequestVerificationCodeResponse) SignalStorageCipher(org.whispersystems.signalservice.api.storage.SignalStorageCipher) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) RemoteAttestationUtil(org.whispersystems.signalservice.internal.push.RemoteAttestationUtil) ACI(org.whispersystems.signalservice.api.push.ACI) Set(java.util.Set) GroupsV2Operations(org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations) IdentityKey(org.whispersystems.libsignal.IdentityKey) CredentialsProvider(org.whispersystems.signalservice.api.util.CredentialsProvider) ProfileCipherOutputStream(org.whispersystems.signalservice.api.crypto.ProfileCipherOutputStream) Base64(org.whispersystems.util.Base64) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) StorageManifestKey(org.whispersystems.signalservice.api.storage.StorageManifestKey) SignalStorageRecord(org.whispersystems.signalservice.api.storage.SignalStorageRecord) NoContentException(org.whispersystems.signalservice.api.push.exceptions.NoContentException) Single(io.reactivex.rxjava3.core.Single) SignalServiceProfileWrite(org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) ArrayList(java.util.ArrayList) WhoAmIResponse(org.whispersystems.signalservice.internal.push.WhoAmIResponse) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) DeviceInfo(org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo) StaticCredentialsProvider(org.whispersystems.signalservice.internal.util.StaticCredentialsProvider) UnauthenticatedQuoteException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) StreamDetails(org.whispersystems.signalservice.api.util.StreamDetails) IOException(java.io.IOException) ProfileAvatarData(org.whispersystems.signalservice.internal.push.ProfileAvatarData) GroupsV2Api(org.whispersystems.signalservice.api.groupsv2.GroupsV2Api) Optional(org.whispersystems.libsignal.util.guava.Optional) ExecutionException(java.util.concurrent.ExecutionException) PrimaryProvisioningCipher(org.whispersystems.signalservice.internal.crypto.PrimaryProvisioningCipher) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) RemoteConfigResponse(org.whispersystems.signalservice.internal.push.RemoteConfigResponse) StorageItems(org.whispersystems.signalservice.internal.storage.protos.StorageItems) MasterKey(org.whispersystems.signalservice.api.kbs.MasterKey) TurnServerInfo(org.whispersystems.signalservice.api.messages.calls.TurnServerInfo) ManifestRecord(org.whispersystems.signalservice.internal.storage.protos.ManifestRecord) WriteOperation(org.whispersystems.signalservice.internal.storage.protos.WriteOperation) Util(org.whispersystems.signalservice.internal.util.Util) TimeoutException(java.util.concurrent.TimeoutException) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) DiscoveryRequest(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) CdshAuthResponse(org.whispersystems.signalservice.internal.push.CdshAuthResponse) StorageId(org.whispersystems.signalservice.api.storage.StorageId) ContactDiscoveryCipher(org.whispersystems.signalservice.internal.contacts.crypto.ContactDiscoveryCipher) VerifyAccountResponse(org.whispersystems.signalservice.internal.push.VerifyAccountResponse) PushServiceSocket(org.whispersystems.signalservice.internal.push.PushServiceSocket) VerifyDeviceResponse(org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse) SignatureException(java.security.SignatureException) Collection(java.util.Collection) KeyStore(java.security.KeyStore) UUID(java.util.UUID) SignalServiceConfiguration(org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration) ByteString(com.google.protobuf.ByteString) DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) List(java.util.List) CurrencyConversions(org.whispersystems.signalservice.api.payments.CurrencyConversions) ProfileCipherOutputStreamFactory(org.whispersystems.signalservice.internal.push.http.ProfileCipherOutputStreamFactory) ProvisioningVersion(org.whispersystems.signalservice.internal.push.ProvisioningProtos.ProvisioningVersion) CdshService(org.whispersystems.signalservice.api.services.CdshService) AccountAttributes(org.whispersystems.signalservice.api.account.AccountAttributes) DataInputStream(java.io.DataInputStream) MessageDigest(java.security.MessageDigest) HashMap(java.util.HashMap) ClientZkOperations(org.whispersystems.signalservice.api.groupsv2.ClientZkOperations) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) Log(org.whispersystems.libsignal.logging.Log) LinkedList(java.util.LinkedList) SignalStorageManifest(org.whispersystems.signalservice.api.storage.SignalStorageManifest) PNI(org.whispersystems.signalservice.api.push.PNI) SignedPreKeyEntity(org.whispersystems.signalservice.api.push.SignedPreKeyEntity) RemoteAttestation(org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) TimeUnit(java.util.concurrent.TimeUnit) StorageItem(org.whispersystems.signalservice.internal.storage.protos.StorageItem) Collections(java.util.Collections) ProfileCipherOutputStreamFactory(org.whispersystems.signalservice.internal.push.http.ProfileCipherOutputStreamFactory) SignalServiceProfileWrite(org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite) ProfileCipher(org.whispersystems.signalservice.api.crypto.ProfileCipher) ProfileAvatarData(org.whispersystems.signalservice.internal.push.ProfileAvatarData)

Example 3 with ProfileAvatarData

use of org.whispersystems.signalservice.internal.push.ProfileAvatarData in project Signal-Android by WhisperSystems.

the class SignalServiceAccountManager method setVersionedProfile.

/**
 * @return The avatar URL path, if one was written.
 */
public Optional<String> setVersionedProfile(ACI aci, ProfileKey profileKey, String name, String about, String aboutEmoji, Optional<SignalServiceProtos.PaymentAddress> paymentsAddress, StreamDetails avatar, List<String> visibleBadgeIds) throws IOException {
    if (name == null)
        name = "";
    ProfileCipher profileCipher = new ProfileCipher(profileKey);
    byte[] ciphertextName = profileCipher.encryptString(name, ProfileCipher.getTargetNameLength(name));
    byte[] ciphertextAbout = profileCipher.encryptString(about, ProfileCipher.getTargetAboutLength(about));
    byte[] ciphertextEmoji = profileCipher.encryptString(aboutEmoji, ProfileCipher.EMOJI_PADDED_LENGTH);
    byte[] ciphertextMobileCoinAddress = paymentsAddress.transform(address -> profileCipher.encryptWithLength(address.toByteArray(), ProfileCipher.PAYMENTS_ADDRESS_CONTENT_SIZE)).orNull();
    boolean hasAvatar = avatar != null;
    ProfileAvatarData profileAvatarData = null;
    if (hasAvatar) {
        profileAvatarData = new ProfileAvatarData(avatar.getStream(), ProfileCipherOutputStream.getCiphertextLength(avatar.getLength()), avatar.getContentType(), new ProfileCipherOutputStreamFactory(profileKey));
    }
    return this.pushServiceSocket.writeProfile(new SignalServiceProfileWrite(profileKey.getProfileKeyVersion(aci.uuid()).serialize(), ciphertextName, ciphertextAbout, ciphertextEmoji, ciphertextMobileCoinAddress, hasAvatar, profileKey.getCommitment(aci.uuid()).serialize(), visibleBadgeIds), profileAvatarData);
}
Also used : ReadOperation(org.whispersystems.signalservice.internal.storage.protos.ReadOperation) ServiceIdType(org.whispersystems.signalservice.api.push.ServiceIdType) Quote(org.whispersystems.signalservice.internal.contacts.crypto.Quote) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) StorageManifest(org.whispersystems.signalservice.internal.storage.protos.StorageManifest) ProfileCipher(org.whispersystems.signalservice.api.crypto.ProfileCipher) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) StorageKey(org.whispersystems.signalservice.api.storage.StorageKey) Preconditions(org.whispersystems.libsignal.util.guava.Preconditions) Map(java.util.Map) SignalStorageModels(org.whispersystems.signalservice.api.storage.SignalStorageModels) AuthCredentials(org.whispersystems.signalservice.internal.push.AuthCredentials) ProvisionMessage(org.whispersystems.signalservice.internal.push.ProvisioningProtos.ProvisionMessage) RequestVerificationCodeResponse(org.whispersystems.signalservice.internal.push.RequestVerificationCodeResponse) SignalStorageCipher(org.whispersystems.signalservice.api.storage.SignalStorageCipher) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) RemoteAttestationUtil(org.whispersystems.signalservice.internal.push.RemoteAttestationUtil) ACI(org.whispersystems.signalservice.api.push.ACI) Set(java.util.Set) GroupsV2Operations(org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations) IdentityKey(org.whispersystems.libsignal.IdentityKey) CredentialsProvider(org.whispersystems.signalservice.api.util.CredentialsProvider) ProfileCipherOutputStream(org.whispersystems.signalservice.api.crypto.ProfileCipherOutputStream) Base64(org.whispersystems.util.Base64) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) StorageManifestKey(org.whispersystems.signalservice.api.storage.StorageManifestKey) SignalStorageRecord(org.whispersystems.signalservice.api.storage.SignalStorageRecord) NoContentException(org.whispersystems.signalservice.api.push.exceptions.NoContentException) Single(io.reactivex.rxjava3.core.Single) SignalServiceProfileWrite(org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) ArrayList(java.util.ArrayList) WhoAmIResponse(org.whispersystems.signalservice.internal.push.WhoAmIResponse) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) DeviceInfo(org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo) StaticCredentialsProvider(org.whispersystems.signalservice.internal.util.StaticCredentialsProvider) UnauthenticatedQuoteException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) StreamDetails(org.whispersystems.signalservice.api.util.StreamDetails) IOException(java.io.IOException) ProfileAvatarData(org.whispersystems.signalservice.internal.push.ProfileAvatarData) GroupsV2Api(org.whispersystems.signalservice.api.groupsv2.GroupsV2Api) Optional(org.whispersystems.libsignal.util.guava.Optional) ExecutionException(java.util.concurrent.ExecutionException) PrimaryProvisioningCipher(org.whispersystems.signalservice.internal.crypto.PrimaryProvisioningCipher) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) RemoteConfigResponse(org.whispersystems.signalservice.internal.push.RemoteConfigResponse) StorageItems(org.whispersystems.signalservice.internal.storage.protos.StorageItems) MasterKey(org.whispersystems.signalservice.api.kbs.MasterKey) TurnServerInfo(org.whispersystems.signalservice.api.messages.calls.TurnServerInfo) ManifestRecord(org.whispersystems.signalservice.internal.storage.protos.ManifestRecord) WriteOperation(org.whispersystems.signalservice.internal.storage.protos.WriteOperation) Util(org.whispersystems.signalservice.internal.util.Util) TimeoutException(java.util.concurrent.TimeoutException) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) DiscoveryRequest(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) CdshAuthResponse(org.whispersystems.signalservice.internal.push.CdshAuthResponse) StorageId(org.whispersystems.signalservice.api.storage.StorageId) ContactDiscoveryCipher(org.whispersystems.signalservice.internal.contacts.crypto.ContactDiscoveryCipher) VerifyAccountResponse(org.whispersystems.signalservice.internal.push.VerifyAccountResponse) PushServiceSocket(org.whispersystems.signalservice.internal.push.PushServiceSocket) VerifyDeviceResponse(org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse) SignatureException(java.security.SignatureException) Collection(java.util.Collection) KeyStore(java.security.KeyStore) UUID(java.util.UUID) SignalServiceConfiguration(org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration) ByteString(com.google.protobuf.ByteString) DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) List(java.util.List) CurrencyConversions(org.whispersystems.signalservice.api.payments.CurrencyConversions) ProfileCipherOutputStreamFactory(org.whispersystems.signalservice.internal.push.http.ProfileCipherOutputStreamFactory) ProvisioningVersion(org.whispersystems.signalservice.internal.push.ProvisioningProtos.ProvisioningVersion) CdshService(org.whispersystems.signalservice.api.services.CdshService) AccountAttributes(org.whispersystems.signalservice.api.account.AccountAttributes) DataInputStream(java.io.DataInputStream) MessageDigest(java.security.MessageDigest) HashMap(java.util.HashMap) ClientZkOperations(org.whispersystems.signalservice.api.groupsv2.ClientZkOperations) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) Log(org.whispersystems.libsignal.logging.Log) LinkedList(java.util.LinkedList) SignalStorageManifest(org.whispersystems.signalservice.api.storage.SignalStorageManifest) PNI(org.whispersystems.signalservice.api.push.PNI) SignedPreKeyEntity(org.whispersystems.signalservice.api.push.SignedPreKeyEntity) RemoteAttestation(org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) TimeUnit(java.util.concurrent.TimeUnit) StorageItem(org.whispersystems.signalservice.internal.storage.protos.StorageItem) Collections(java.util.Collections) ProfileCipherOutputStreamFactory(org.whispersystems.signalservice.internal.push.http.ProfileCipherOutputStreamFactory) SignalServiceProfileWrite(org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite) ProfileCipher(org.whispersystems.signalservice.api.crypto.ProfileCipher) ProfileAvatarData(org.whispersystems.signalservice.internal.push.ProfileAvatarData)

Aggregations

ByteString (com.google.protobuf.ByteString)2 Single (io.reactivex.rxjava3.core.Single)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 KeyStore (java.security.KeyStore)2 MessageDigest (java.security.MessageDigest)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Set (java.util.Set)2 UUID (java.util.UUID)2 ExecutionException (java.util.concurrent.ExecutionException)2