mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Make headers for giphy requests random sizes.
This commit is contained in:
parent
77524ae1f2
commit
29cdb5290b
@ -41,6 +41,7 @@ public class ChunkedImageUrlLoader implements ModelLoader<ChunkedImageUrl, Input
|
||||
this.client = new OkHttpClient.Builder()
|
||||
.proxySelector(new ContentProxySelector())
|
||||
.cache(null)
|
||||
.addNetworkInterceptor(new PaddedHeadersInterceptor())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
package org.thoughtcrime.securesms.glide;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* An interceptor that adds a header with a random amount of bytes to disguise header length.
|
||||
*/
|
||||
public class PaddedHeadersInterceptor implements Interceptor {
|
||||
|
||||
private static final String PADDING_HEADER = "X-SignalPadding";
|
||||
private static final int MIN_RANDOM_BYTES = 1;
|
||||
private static final int MAX_RANDOM_BYTES = 64;
|
||||
|
||||
@Override
|
||||
public Response intercept(@NonNull Chain chain) throws IOException {
|
||||
Request padded = chain.request().newBuilder()
|
||||
.headers(getPaddedHeaders(chain.request().headers()))
|
||||
.build();
|
||||
|
||||
return chain.proceed(padded);
|
||||
}
|
||||
|
||||
private @NonNull Headers getPaddedHeaders(@NonNull Headers headers) {
|
||||
return headers.newBuilder()
|
||||
.add(PADDING_HEADER, getRandomString(new SecureRandom(), MIN_RANDOM_BYTES, MAX_RANDOM_BYTES))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static @NonNull String getRandomString(@NonNull SecureRandom secureRandom, int minLength, int maxLength) {
|
||||
char[] buffer = new char[secureRandom.nextInt(maxLength - minLength) + minLength];
|
||||
|
||||
for (int i = 0 ; i < buffer.length; i++) {
|
||||
buffer[i] = (char) (secureRandom.nextInt(74) + 48); // Random char from 0-Z
|
||||
}
|
||||
|
||||
return new String(buffer);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user