mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-02 06:33:38 +01:00
Only generate incremental mac for faststart videos.
This commit is contained in:
@@ -792,6 +792,7 @@ public class SignalServiceMessageSender {
|
||||
PushAttachmentData attachmentData = new PushAttachmentData(attachment.getContentType(),
|
||||
dataStream,
|
||||
ciphertextLength,
|
||||
attachment.isFaststart(),
|
||||
new AttachmentCipherOutputStreamFactory(attachmentKey, attachmentIV),
|
||||
attachment.getListener(),
|
||||
attachment.getCancelationSignal(),
|
||||
@@ -877,7 +878,7 @@ public class SignalServiceMessageSender {
|
||||
attachment.getHeight(),
|
||||
Optional.of(digest.getDigest()),
|
||||
Optional.ofNullable(digest.getIncrementalDigest()),
|
||||
digest.getIncrementalMacChunkSize(),
|
||||
digest.getIncrementalDigest() != null ? digest.getIncrementalMacChunkSize() : 0,
|
||||
attachment.getFileName(),
|
||||
attachment.getVoiceNote(),
|
||||
attachment.isBorderless(),
|
||||
|
||||
@@ -41,7 +41,7 @@ public abstract class SignalServiceAttachment {
|
||||
}
|
||||
|
||||
public static SignalServiceAttachmentStream emptyStream(String contentType) {
|
||||
return new SignalServiceAttachmentStream(new ByteArrayInputStream(new byte[0]), contentType, 0, Optional.empty(), false, false, false, null, null);
|
||||
return new SignalServiceAttachmentStream(new ByteArrayInputStream(new byte[0]), contentType, 0, Optional.empty(), false, false, false, false, null, null);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@@ -55,6 +55,7 @@ public abstract class SignalServiceAttachment {
|
||||
private boolean voiceNote;
|
||||
private boolean borderless;
|
||||
private boolean gif;
|
||||
private boolean faststart;
|
||||
private int width;
|
||||
private int height;
|
||||
private String caption;
|
||||
@@ -109,6 +110,11 @@ public abstract class SignalServiceAttachment {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withFaststart(boolean faststart) {
|
||||
this.faststart = faststart;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withWidth(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
@@ -151,6 +157,7 @@ public abstract class SignalServiceAttachment {
|
||||
voiceNote,
|
||||
borderless,
|
||||
gif,
|
||||
faststart,
|
||||
Optional.empty(),
|
||||
width,
|
||||
height,
|
||||
|
||||
@@ -29,6 +29,7 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment imple
|
||||
private final boolean voiceNote;
|
||||
private final boolean borderless;
|
||||
private final boolean gif;
|
||||
private final boolean faststart;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final long uploadTimestamp;
|
||||
@@ -43,10 +44,11 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment imple
|
||||
boolean voiceNote,
|
||||
boolean borderless,
|
||||
boolean gif,
|
||||
boolean faststart,
|
||||
ProgressListener listener,
|
||||
CancelationSignal cancelationSignal)
|
||||
{
|
||||
this(inputStream, contentType, length, fileName, voiceNote, borderless, gif, Optional.empty(), 0, 0, System.currentTimeMillis(), Optional.empty(), Optional.empty(), listener, cancelationSignal, Optional.empty());
|
||||
this(inputStream, contentType, length, fileName, voiceNote, borderless, gif, faststart, Optional.empty(), 0, 0, System.currentTimeMillis(), Optional.empty(), Optional.empty(), listener, cancelationSignal, Optional.empty());
|
||||
}
|
||||
|
||||
public SignalServiceAttachmentStream(InputStream inputStream,
|
||||
@@ -56,6 +58,7 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment imple
|
||||
boolean voiceNote,
|
||||
boolean borderless,
|
||||
boolean gif,
|
||||
boolean faststart,
|
||||
Optional<byte[]> preview,
|
||||
int width,
|
||||
int height,
|
||||
@@ -67,21 +70,22 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment imple
|
||||
Optional<ResumableUploadSpec> resumableUploadSpec)
|
||||
{
|
||||
super(contentType);
|
||||
this.inputStream = inputStream;
|
||||
this.length = length;
|
||||
this.fileName = fileName;
|
||||
this.listener = listener;
|
||||
this.voiceNote = voiceNote;
|
||||
this.borderless = borderless;
|
||||
this.gif = gif;
|
||||
this.preview = preview;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.uploadTimestamp = uploadTimestamp;
|
||||
this.caption = caption;
|
||||
this.blurHash = blurHash;
|
||||
this.cancelationSignal = cancelationSignal;
|
||||
this.resumableUploadSpec = resumableUploadSpec;
|
||||
this.inputStream = inputStream;
|
||||
this.length = length;
|
||||
this.fileName = fileName;
|
||||
this.listener = listener;
|
||||
this.voiceNote = voiceNote;
|
||||
this.borderless = borderless;
|
||||
this.gif = gif;
|
||||
this.preview = preview;
|
||||
this.faststart = faststart;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.uploadTimestamp = uploadTimestamp;
|
||||
this.caption = caption;
|
||||
this.blurHash = blurHash;
|
||||
this.cancelationSignal = cancelationSignal;
|
||||
this.resumableUploadSpec = resumableUploadSpec;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,6 +134,10 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment imple
|
||||
return gif;
|
||||
}
|
||||
|
||||
public boolean isFaststart() {
|
||||
return faststart;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DeviceContactsInputStream extends ChunkedInputStream {
|
||||
InputStream avatarStream = new LimitedInputStream(in, avatarLength);
|
||||
String avatarContentType = details.avatar.contentType;
|
||||
|
||||
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.empty(), false, false, false, null, null));
|
||||
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.empty(), false, false, false, false, null, null));
|
||||
}
|
||||
|
||||
if (details.verified != null) {
|
||||
|
||||
@@ -18,19 +18,21 @@ public class PushAttachmentData {
|
||||
private final String contentType;
|
||||
private final InputStream data;
|
||||
private final long dataSize;
|
||||
private final boolean incremental;
|
||||
private final OutputStreamFactory outputStreamFactory;
|
||||
private final ProgressListener listener;
|
||||
private final CancelationSignal cancelationSignal;
|
||||
private final ResumableUploadSpec resumableUploadSpec;
|
||||
|
||||
public PushAttachmentData(String contentType, InputStream data, long dataSize,
|
||||
OutputStreamFactory outputStreamFactory,
|
||||
boolean incremental, OutputStreamFactory outputStreamFactory,
|
||||
ProgressListener listener, CancelationSignal cancelationSignal,
|
||||
ResumableUploadSpec resumableUploadSpec)
|
||||
{
|
||||
this.contentType = contentType;
|
||||
this.data = data;
|
||||
this.dataSize = dataSize;
|
||||
this.incremental = incremental;
|
||||
this.outputStreamFactory = outputStreamFactory;
|
||||
this.resumableUploadSpec = resumableUploadSpec;
|
||||
this.listener = listener;
|
||||
@@ -49,6 +51,10 @@ public class PushAttachmentData {
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
public boolean getIncremental() {
|
||||
return incremental;
|
||||
}
|
||||
|
||||
public OutputStreamFactory getOutputStreamFactory() {
|
||||
return outputStreamFactory;
|
||||
}
|
||||
|
||||
@@ -946,7 +946,7 @@ public class PushServiceSocket {
|
||||
formAttributes.getPolicy(), formAttributes.getAlgorithm(),
|
||||
formAttributes.getCredential(), formAttributes.getDate(),
|
||||
formAttributes.getSignature(), profileAvatar.getData(),
|
||||
profileAvatar.getContentType(), profileAvatar.getDataLength(),
|
||||
profileAvatar.getContentType(), profileAvatar.getDataLength(), false,
|
||||
profileAvatar.getOutputStreamFactory(), null, null);
|
||||
|
||||
return Optional.of(formAttributes.getKey());
|
||||
@@ -1393,7 +1393,7 @@ public class PushServiceSocket {
|
||||
uploadAttributes.credential, uploadAttributes.date,
|
||||
uploadAttributes.signature,
|
||||
new ByteArrayInputStream(avatarCipherText),
|
||||
"application/octet-stream", avatarCipherText.length,
|
||||
"application/octet-stream", avatarCipherText.length, false,
|
||||
new NoCipherOutputStreamFactory(),
|
||||
null, null);
|
||||
}
|
||||
@@ -1407,8 +1407,8 @@ public class PushServiceSocket {
|
||||
uploadAttributes.getCredential(), uploadAttributes.getDate(),
|
||||
uploadAttributes.getSignature(), attachment.getData(),
|
||||
"application/octet-stream", attachment.getDataSize(),
|
||||
attachment.getOutputStreamFactory(), attachment.getListener(),
|
||||
attachment.getCancelationSignal());
|
||||
attachment.getIncremental(), attachment.getOutputStreamFactory(),
|
||||
attachment.getListener(), attachment.getCancelationSignal());
|
||||
|
||||
return new Pair<>(id, digest);
|
||||
}
|
||||
@@ -1434,6 +1434,7 @@ public class PushServiceSocket {
|
||||
attachment.getData(),
|
||||
"application/octet-stream",
|
||||
attachment.getDataSize(),
|
||||
attachment.getIncremental(),
|
||||
attachment.getOutputStreamFactory(),
|
||||
attachment.getListener(),
|
||||
attachment.getCancelationSignal());
|
||||
@@ -1442,6 +1443,7 @@ public class PushServiceSocket {
|
||||
attachment.getData(),
|
||||
"application/offset+octet-stream",
|
||||
attachment.getDataSize(),
|
||||
attachment.getIncremental(),
|
||||
attachment.getOutputStreamFactory(),
|
||||
attachment.getListener(),
|
||||
attachment.getCancelationSignal(),
|
||||
@@ -1529,7 +1531,7 @@ public class PushServiceSocket {
|
||||
|
||||
private AttachmentDigest uploadToCdn0(String path, String acl, String key, String policy, String algorithm,
|
||||
String credential, String date, String signature,
|
||||
InputStream data, String contentType, long length,
|
||||
InputStream data, String contentType, long length, boolean incremental,
|
||||
OutputStreamFactory outputStreamFactory, ProgressListener progressListener,
|
||||
CancelationSignal cancelationSignal)
|
||||
throws PushNetworkException, NonSuccessfulResponseCodeException
|
||||
@@ -1541,7 +1543,7 @@ public class PushServiceSocket {
|
||||
.readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, progressListener, cancelationSignal, 0);
|
||||
DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, incremental, progressListener, cancelationSignal, 0);
|
||||
|
||||
RequestBody requestBody = new MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
@@ -1639,7 +1641,7 @@ public class PushServiceSocket {
|
||||
}
|
||||
}
|
||||
|
||||
private AttachmentDigest uploadToCdn2(String resumableUrl, InputStream data, String contentType, long length, OutputStreamFactory outputStreamFactory, ProgressListener progressListener, CancelationSignal cancelationSignal) throws IOException {
|
||||
private AttachmentDigest uploadToCdn2(String resumableUrl, InputStream data, String contentType, long length, boolean incremental, OutputStreamFactory outputStreamFactory, ProgressListener progressListener, CancelationSignal cancelationSignal) throws IOException {
|
||||
ConnectionHolder connectionHolder = getRandom(cdnClientsMap.get(2), random);
|
||||
OkHttpClient okHttpClient = connectionHolder.getClient()
|
||||
.newBuilder()
|
||||
@@ -1648,7 +1650,7 @@ public class PushServiceSocket {
|
||||
.build();
|
||||
|
||||
ResumeInfo resumeInfo = getResumeInfoCdn2(resumableUrl, length);
|
||||
DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, progressListener, cancelationSignal, resumeInfo.contentStart);
|
||||
DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, incremental, progressListener, cancelationSignal, resumeInfo.contentStart);
|
||||
|
||||
if (resumeInfo.contentStart == length) {
|
||||
Log.w(TAG, "Resume start point == content length");
|
||||
@@ -1690,6 +1692,7 @@ public class PushServiceSocket {
|
||||
InputStream data,
|
||||
String contentType,
|
||||
long length,
|
||||
boolean incremental,
|
||||
OutputStreamFactory outputStreamFactory,
|
||||
ProgressListener progressListener,
|
||||
CancelationSignal cancelationSignal,
|
||||
@@ -1704,7 +1707,7 @@ public class PushServiceSocket {
|
||||
.build();
|
||||
|
||||
ResumeInfo resumeInfo = getResumeInfoCdn3(resumableUrl, headers);
|
||||
DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, progressListener, cancelationSignal, resumeInfo.contentStart);
|
||||
DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, incremental, progressListener, cancelationSignal, resumeInfo.contentStart);
|
||||
|
||||
if (resumeInfo.contentStart == length) {
|
||||
Log.w(TAG, "Resume start point == content length");
|
||||
|
||||
@@ -22,6 +22,7 @@ class DigestingRequestBody(
|
||||
private val outputStreamFactory: OutputStreamFactory,
|
||||
private val contentType: String,
|
||||
private val contentLength: Long,
|
||||
private val incremental: Boolean,
|
||||
private val progressListener: SignalServiceAttachment.ProgressListener?,
|
||||
private val cancelationSignal: CancelationSignal?,
|
||||
private val contentStart: Long
|
||||
@@ -41,7 +42,7 @@ class DigestingRequestBody(
|
||||
override fun writeTo(sink: BufferedSink) {
|
||||
val digestStream = ByteArrayOutputStream()
|
||||
val inner = SkippingOutputStream(contentStart, sink.outputStream())
|
||||
val isIncremental = outputStreamFactory is AttachmentCipherOutputStreamFactory
|
||||
val isIncremental = incremental && outputStreamFactory is AttachmentCipherOutputStreamFactory
|
||||
val sizeChoice: ChunkSizeChoice = ChunkSizeChoice.inferChunkSize(contentLength.toInt())
|
||||
val outputStream: DigestingOutputStream = if (isIncremental) {
|
||||
(outputStreamFactory as AttachmentCipherOutputStreamFactory).createIncrementalFor(inner, contentLength, sizeChoice, digestStream)
|
||||
|
||||
Reference in New Issue
Block a user