Java Code Examples for org.whispersystems.signalservice.api.crypto.ProfileCipher

The following examples show how to use org.whispersystems.signalservice.api.crypto.ProfileCipher. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * @return The avatar URL path, if one was written.
 */
public Optional<String> setVersionedProfile(UUID uuid, ProfileKey profileKey, String name, StreamDetails avatar)
    throws IOException
{
  if (name == null) name = "";

  byte[]            ciphertextName    = new ProfileCipher(profileKey).encryptName(name.getBytes(StandardCharsets.UTF_8), ProfileCipher.NAME_PADDED_LENGTH);
  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(uuid).serialize(),
                                                                           ciphertextName,
                                                                           hasAvatar,
                                                                           profileKey.getCommitment(uuid).serialize()),
                                                                           profileAvatarData);
}
 
Example 2
public void setProfileName(ProfileKey key, String name)
    throws IOException
{
  if (FeatureFlags.DISALLOW_OLD_PROFILE_SETTING) {
    throw new AssertionError();
  }

  if (name == null) name = "";

  String ciphertextName = Base64.encodeBytesWithoutPadding(new ProfileCipher(key).encryptName(name.getBytes(StandardCharsets.UTF_8), ProfileCipher.NAME_PADDED_LENGTH));

  this.pushServiceSocket.setProfileName(ciphertextName);
}
 
Example 3
Source Project: mollyim-android   Source File: ProfileUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static @Nullable String decryptName(@NonNull ProfileKey profileKey, @Nullable String encryptedName)
    throws InvalidCiphertextException, IOException
{
  if (encryptedName == null) {
    return null;
  }

  ProfileCipher profileCipher = new ProfileCipher(profileKey);
  return new String(profileCipher.decryptName(Base64.decode(encryptedName)));
}
 
Example 4
private void setUnidentifiedAccessMode(Recipient recipient, String unidentifiedAccessVerifier, boolean unrestrictedUnidentifiedAccess) {
  RecipientDatabase recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
  ProfileKey        profileKey        = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());

  if (unrestrictedUnidentifiedAccess && unidentifiedAccessVerifier != null) {
    if (recipient.getUnidentifiedAccessMode() != UnidentifiedAccessMode.UNRESTRICTED) {
      Log.i(TAG, "Marking recipient UD status as unrestricted.");
      recipientDatabase.setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.UNRESTRICTED);
    }
  } else if (profileKey == null || unidentifiedAccessVerifier == null) {
    if (recipient.getUnidentifiedAccessMode() != UnidentifiedAccessMode.DISABLED) {
      Log.i(TAG, "Marking recipient UD status as disabled.");
      recipientDatabase.setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.DISABLED);
    }
  } else {
    ProfileCipher profileCipher = new ProfileCipher(profileKey);
    boolean verifiedUnidentifiedAccess;

    try {
      verifiedUnidentifiedAccess = profileCipher.verifyUnidentifiedAccess(Base64.decode(unidentifiedAccessVerifier));
    } catch (IOException e) {
      Log.w(TAG, e);
      verifiedUnidentifiedAccess = false;
    }

    UnidentifiedAccessMode mode = verifiedUnidentifiedAccess ? UnidentifiedAccessMode.ENABLED : UnidentifiedAccessMode.DISABLED;

    if (recipient.getUnidentifiedAccessMode() != mode) {
      Log.i(TAG, "Marking recipient UD status as " + mode.name() + " after verification.");
      recipientDatabase.setUnidentifiedAccessMode(recipient.getId(), mode);
    }
  }
}
 
Example 5
Source Project: signald   Source File: JsonProfile.java    License: GNU General Public License v3.0 5 votes vote down vote up
JsonProfile(SignalServiceProfile p, byte[] profileKey) throws IOException, InvalidCiphertextException {
    ProfileCipher profileCipher = new ProfileCipher(profileKey);
    name = new String(profileCipher.decryptName(Base64.decode(p.getName())));
    identity_key = p.getIdentityKey();
    avatar = p.getAvatar();
    unidentified_access = p.getUnidentifiedAccess();
    if (p.isUnrestrictedUnidentifiedAccess()) {
        unrestricted_unidentified_access = true;
    }

}
 
Example 6
public void setProfileName(byte[] key, String name)
    throws IOException
{
  if (name == null) name = "";

  String ciphertextName = Base64.encodeBytesWithoutPadding(new ProfileCipher(key).encryptName(name.getBytes("UTF-8"), ProfileCipher.NAME_PADDED_LENGTH));

  this.pushServiceSocket.setProfileName(ciphertextName);
}
 
Example 7
Source Project: signal-cli   Source File: Manager.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static SignalProfile decryptProfile(SignalServiceProfile encryptedProfile, ProfileKey profileKey) throws IOException {
    ProfileCipher profileCipher = new ProfileCipher(profileKey);
    try {
        return new SignalProfile(
                encryptedProfile.getIdentityKey(),
                encryptedProfile.getName() == null ? null : new String(profileCipher.decryptName(Base64.decode(encryptedProfile.getName()))),
                encryptedProfile.getAvatar(),
                encryptedProfile.getUnidentifiedAccess() == null || !profileCipher.verifyUnidentifiedAccess(Base64.decode(encryptedProfile.getUnidentifiedAccess())) ? null : encryptedProfile.getUnidentifiedAccess(),
                encryptedProfile.isUnrestrictedUnidentifiedAccess()
        );
    } catch (InvalidCiphertextException e) {
        return null;
    }
}