Replace CachedContentIndex usage of Random with SecureRandom

This is used to generate the initialization vector for encrypting the
cache contents.

Startblock:
   <unknown commit> is submitted
   and then
   3w have passed
PiperOrigin-RevId: 303932151
This commit is contained in:
ibaker 2020-03-31 11:42:59 +01:00 committed by Oliver Woodman
parent 3aac5b58b8
commit 823666587b
2 changed files with 5 additions and 3 deletions

View File

@ -61,6 +61,8 @@
`DecoderVideoRenderer` and `DecoderAudioRenderer` respectively, and `DecoderVideoRenderer` and `DecoderAudioRenderer` respectively, and
generalized to work with `Decoder` rather than `SimpleDecoder`. generalized to work with `Decoder` rather than `SimpleDecoder`.
* Add media item based playlist API to Player. * Add media item based playlist API to Player.
* Update `CachedContentIndex` to use `SecureRandom` for generating the
initialization vector used to encrypt the cache contents.
* Text: * Text:
* Parse `<ruby>` and `<rt>` tags in WebVTT subtitles (rendering is coming * Parse `<ruby>` and `<rt>` tags in WebVTT subtitles (rendering is coming
later). later).

View File

@ -45,11 +45,11 @@ import java.io.OutputStream;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random;
import java.util.Set; import java.util.Set;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.CipherInputStream; import javax.crypto.CipherInputStream;
@ -494,7 +494,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
private final boolean encrypt; private final boolean encrypt;
@Nullable private final Cipher cipher; @Nullable private final Cipher cipher;
@Nullable private final SecretKeySpec secretKeySpec; @Nullable private final SecretKeySpec secretKeySpec;
@Nullable private final Random random; @Nullable private final SecureRandom random;
private final AtomicFile atomicFile; private final AtomicFile atomicFile;
private boolean changed; private boolean changed;
@ -517,7 +517,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
this.encrypt = encrypt; this.encrypt = encrypt;
this.cipher = cipher; this.cipher = cipher;
this.secretKeySpec = secretKeySpec; this.secretKeySpec = secretKeySpec;
random = encrypt ? new Random() : null; random = encrypt ? new SecureRandom() : null;
atomicFile = new AtomicFile(file); atomicFile = new AtomicFile(file);
} }