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

The following examples show how to use org.whispersystems.signalservice.api.crypto.ProfileCipher. 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
Source File: SignalServiceAccountManager.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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
Source File: SignalServiceAccountManager.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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 File: ProfileUtil.java    From mollyim-android with 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
Source File: RetrieveProfileJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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 File: JsonProfile.java    From signald with 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
Source File: SignalServiceAccountManager.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
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 File: Manager.java    From signal-cli with 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;
    }
}