Search in sources :

Example 1 with PushAttachmentData

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

the class SignalServiceMessageSender method createAttachmentPointer.

private AttachmentPointer createAttachmentPointer(SignalServiceAttachmentStream attachment) throws IOException {
    byte[] attachmentKey = Util.getSecretBytes(64);
    long paddedLength = PaddingInputStream.getPaddedSize(attachment.getLength());
    long ciphertextLength = AttachmentCipherOutputStream.getCiphertextLength(paddedLength);
    PushAttachmentData attachmentData = new PushAttachmentData(attachment.getContentType(), new PaddingInputStream(attachment.getInputStream(), attachment.getLength()), ciphertextLength, new AttachmentCipherOutputStreamFactory(attachmentKey), attachment.getListener());
    Pair<Long, byte[]> attachmentIdAndDigest = socket.sendAttachment(attachmentData);
    AttachmentPointer.Builder builder = AttachmentPointer.newBuilder().setContentType(attachment.getContentType()).setId(attachmentIdAndDigest.first()).setKey(ByteString.copyFrom(attachmentKey)).setDigest(ByteString.copyFrom(attachmentIdAndDigest.second())).setSize((int) attachment.getLength());
    if (attachment.getFileName().isPresent()) {
        builder.setFileName(attachment.getFileName().get());
    }
    if (attachment.getPreview().isPresent()) {
        builder.setThumbnail(ByteString.copyFrom(attachment.getPreview().get()));
    }
    if (attachment.getWidth() > 0) {
        builder.setWidth(attachment.getWidth());
    }
    if (attachment.getHeight() > 0) {
        builder.setHeight(attachment.getHeight());
    }
    if (attachment.getVoiceNote()) {
        builder.setFlags(AttachmentPointer.Flags.VOICE_MESSAGE_VALUE);
    }
    return builder.build();
}
Also used : PaddingInputStream(org.whispersystems.signalservice.internal.crypto.PaddingInputStream) PushAttachmentData(org.whispersystems.signalservice.internal.push.PushAttachmentData) AttachmentPointer(org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer) AttachmentCipherOutputStreamFactory(org.whispersystems.signalservice.internal.push.http.AttachmentCipherOutputStreamFactory)

Example 2 with PushAttachmentData

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

the class SignalServiceMessageSender method uploadAttachment.

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 (attachment.getResumableUploadSpec().isPresent()) {
        return uploadAttachmentV3(attachment, attachmentKey, attachmentData);
    } else {
        return uploadAttachmentV2(attachment, attachmentKey, attachmentData);
    }
}
Also used : PaddingInputStream(org.whispersystems.signalservice.internal.crypto.PaddingInputStream) InputStream(java.io.InputStream) PaddingInputStream(org.whispersystems.signalservice.internal.crypto.PaddingInputStream) PushAttachmentData(org.whispersystems.signalservice.internal.push.PushAttachmentData) AttachmentCipherOutputStreamFactory(org.whispersystems.signalservice.internal.push.http.AttachmentCipherOutputStreamFactory)

Aggregations

PaddingInputStream (org.whispersystems.signalservice.internal.crypto.PaddingInputStream)2 PushAttachmentData (org.whispersystems.signalservice.internal.push.PushAttachmentData)2 AttachmentCipherOutputStreamFactory (org.whispersystems.signalservice.internal.push.http.AttachmentCipherOutputStreamFactory)2 InputStream (java.io.InputStream)1 AttachmentPointer (org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer)1