コード例 #1
0
  private static byte[] retrieve(Context context, String key) throws IOException {
    SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, 0);
    String encodedValue = settings.getString(key, "");

    if (TextUtils.isEmpty(encodedValue)) return null;
    else return Base64.decode(encodedValue);
  }
コード例 #2
0
 private byte[] decodeAndDecryptBytes(String body) throws InvalidMessageException {
   try {
     byte[] decodedBody = Base64.decode(body);
     return decryptBytes(decodedBody);
   } catch (IOException e) {
     throw new InvalidMessageException("Bad Base64 Encoding...", e);
   }
 }
コード例 #3
0
 private static void save(Context context, String key, byte[] value) {
   if (!context
       .getSharedPreferences(PREFERENCES_NAME, 0)
       .edit()
       .putString(key, Base64.encodeBytes(value))
       .commit()) {
     throw new AssertionError("failed to save a shared pref in MasterSecretUtil");
   }
 }
コード例 #4
0
  public OutgoingGroupMediaMessage(
      @NonNull Recipients recipients,
      @NonNull String encodedGroupContext,
      @NonNull List<Attachment> avatar,
      long sentTimeMillis)
      throws IOException {
    super(
        recipients,
        encodedGroupContext,
        avatar,
        sentTimeMillis,
        ThreadDatabase.DistributionTypes.CONVERSATION);

    this.group = GroupContext.parseFrom(Base64.decode(encodedGroupContext));
  }
コード例 #5
0
  public OutgoingGroupMediaMessage(
      @NonNull Recipients recipients,
      @NonNull GroupContext group,
      @Nullable final Attachment avatar,
      long sentTimeMillis) {
    super(
        recipients,
        Base64.encodeBytes(group.toByteArray()),
        new LinkedList<Attachment>() {
          {
            if (avatar != null) add(avatar);
          }
        },
        System.currentTimeMillis(),
        ThreadDatabase.DistributionTypes.CONVERSATION);

    this.group = group;
  }
コード例 #6
0
  private void deliver(MasterSecret masterSecret, SendReq message)
      throws IOException, RecipientFormattingException, InvalidNumberException,
          EncapsulatedExceptions {
    TextSecureMessageSender messageSender = messageSenderFactory.create(masterSecret);
    byte[] groupId = GroupUtil.getDecodedId(message.getTo()[0].getString());
    Recipients recipients =
        DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
    List<PushAddress> addresses = getPushAddresses(recipients);
    List<TextSecureAttachment> attachments = getAttachments(masterSecret, message);

    if (MmsSmsColumns.Types.isGroupUpdate(message.getDatabaseMessageBox())
        || MmsSmsColumns.Types.isGroupQuit(message.getDatabaseMessageBox())) {
      String content = PartParser.getMessageText(message.getBody());

      if (content != null && !content.trim().isEmpty()) {
        PushMessageProtos.PushMessageContent.GroupContext groupContext =
            PushMessageProtos.PushMessageContent.GroupContext.parseFrom(Base64.decode(content));
        TextSecureAttachment avatar = attachments.isEmpty() ? null : attachments.get(0);
        TextSecureGroup.Type type =
            MmsSmsColumns.Types.isGroupQuit(message.getDatabaseMessageBox())
                ? TextSecureGroup.Type.QUIT
                : TextSecureGroup.Type.UPDATE;
        TextSecureGroup group =
            new TextSecureGroup(
                type, groupId, groupContext.getName(), groupContext.getMembersList(), avatar);
        TextSecureMessage groupMessage =
            new TextSecureMessage(message.getSentTimestamp(), group, null, null);

        messageSender.sendMessage(addresses, groupMessage);
      }
    } else {
      String body = PartParser.getMessageText(message.getBody());
      TextSecureGroup group = new TextSecureGroup(groupId);
      TextSecureMessage groupMessage =
          new TextSecureMessage(message.getSentTimestamp(), group, attachments, body);

      messageSender.sendMessage(addresses, groupMessage);
    }
  }
コード例 #7
0
 private String encryptAndEncodeBytes(byte[] bytes) {
   byte[] encryptedAndMacBody = encryptBytes(bytes);
   return Base64.encodeBytes(encryptedAndMacBody);
 }