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

The following examples show how to use org.whispersystems.signalservice.api.crypto.AttachmentCipherOutputStream. 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: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public SignalServiceAttachmentPointer uploadAttachment(SignalServiceAttachmentStream attachment) throws IOException {
  byte[]             attachmentKey    = attachment.getResumableUploadSpec().transform(ResumableUploadSpec::getSecretKey).or(() -> Util.getSecretBytes(64));
  byte[]             attachmentIV     = attachment.getResumableUploadSpec().transform(ResumableUploadSpec::getIV).or(() -> Util.getSecretBytes(16));
  long               paddedLength     = PaddingInputStream.getPaddedSize(attachment.getLength());
  InputStream        dataStream       = new PaddingInputStream(attachment.getInputStream(), attachment.getLength());
  long               ciphertextLength = AttachmentCipherOutputStream.getCiphertextLength(paddedLength);
  PushAttachmentData attachmentData   = new PushAttachmentData(attachment.getContentType(),
                                                               dataStream,
                                                               ciphertextLength,
                                                               new AttachmentCipherOutputStreamFactory(attachmentKey, attachmentIV),
                                                               attachment.getListener(),
                                                               attachment.getCancelationSignal(),
                                                               attachment.getResumableUploadSpec().orNull());

  if (attachmentsV3.get()) {
    return uploadAttachmentV3(attachment, attachmentKey, attachmentData);
  } else {
    return uploadAttachmentV2(attachment, attachmentKey, attachmentData);
  }
}
 
Example #2
Source File: AttachmentCipherOutputStreamFactory.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DigestingOutputStream createFor(OutputStream wrap) throws IOException {
  return new AttachmentCipherOutputStream(key, iv, wrap);
}
 
Example #3
Source File: AttachmentCipherOutputStreamFactory.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DigestingOutputStream createFor(OutputStream wrap) throws IOException {
  return new AttachmentCipherOutputStream(key, wrap);
}
 
Example #4
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public SignalServiceAttachmentPointer uploadAttachment(SignalServiceAttachmentStream attachment) throws IOException {
  byte[]             attachmentKey    = Util.getSecretBytes(64);
  long               paddedLength     = PaddingInputStream.getPaddedSize(attachment.getLength());
  InputStream        dataStream       = new PaddingInputStream(attachment.getInputStream(), attachment.getLength());
  long               ciphertextLength = AttachmentCipherOutputStream.getCiphertextLength(paddedLength);
  PushAttachmentData attachmentData   = new PushAttachmentData(attachment.getContentType(),
                                                               dataStream,
                                                               ciphertextLength,
                                                               new AttachmentCipherOutputStreamFactory(attachmentKey),
                                                               attachment.getListener());

  AttachmentUploadAttributes uploadAttributes = null;

  if (pipe.get().isPresent()) {
    Log.d(TAG, "Using pipe to retrieve attachment upload attributes...");
    try {
      uploadAttributes = pipe.get().get().getAttachmentUploadAttributes();
    } catch (IOException e) {
      Log.w(TAG, "Failed to retrieve attachment upload attributes using pipe. Falling back...");
    }
  }

  if (uploadAttributes == null) {
    Log.d(TAG, "Not using pipe to retrieve attachment upload attributes...");
    uploadAttributes = socket.getAttachmentUploadAttributes();
  }

  Pair<Long, byte[]> attachmentIdAndDigest = socket.uploadAttachment(attachmentData, uploadAttributes);

  return new SignalServiceAttachmentPointer(attachmentIdAndDigest.first(),
                                            attachment.getContentType(),
                                            attachmentKey,
                                            Optional.of(Util.toIntExact(attachment.getLength())),
                                            attachment.getPreview(),
                                            attachment.getWidth(), attachment.getHeight(),
                                            Optional.of(attachmentIdAndDigest.second()),
                                            attachment.getFileName(),
                                            attachment.getVoiceNote(),
                                            attachment.getCaption(),
                                            attachment.getBlurHash());
}
 
Example #5
Source File: AttachmentCipherOutputStreamFactory.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DigestingOutputStream createFor(OutputStream wrap) throws IOException {
  return new AttachmentCipherOutputStream(key, wrap);
}