summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Aranda <miguelaranda@google.com>2023-04-18 11:43:13 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-04-18 11:43:13 +0000
commit7ea8c17d1ad13bf9269750c4f0ebe9f51e0928e5 (patch)
tree39be991fa9e225803cfa7afe5e139ae3afa38a29
parentbcb46fde64799fc7efdb3f48a2302a8d5bcfc6a5 (diff)
parentdd46e8b30d7938693a5f2327bf053918982950de (diff)
downloadbouncycastle-7ea8c17d1ad13bf9269750c4f0ebe9f51e0928e5.tar.gz
Merge "Reject BC keys without IV."
-rw-r--r--bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java48
-rw-r--r--repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java48
-rw-r--r--repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java48
3 files changed, 27 insertions, 117 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
index 8c678059..7dadfa7f 100644
--- a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
+++ b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
@@ -957,56 +957,26 @@ public class BaseBlockCipher
{
byte[] iv = new byte[ivLength];
- // BEGIN Android-changed: For PBE keys with no IV, log and use IV of 0
+ // BEGIN Android-changed: Reject PBE keys with no IV
// These keys were accepted in BC 1.52 (and treated as having an IV of 0) but
- // rejected outright in BC 1.54 (even if an IV was passed in params). We
- // want the eventual state to be that an IV can be passed in params, but the key
- // is rejected otherwise. For now, log that these will be rejected in a future
- // release. See b/27995180 for historical details.
- // ivRandom.nextBytes(iv);
+ // rejected outright in BC 1.54 (even if an IV was passed in params).
+ // See b/27995180 for historical details.
if (!isBCPBEKeyWithoutIV(key)) {
ivRandom.nextBytes(iv);
} else {
- // TODO(b/70275132): Change to rejecting these keys
- System.err.println(" ******** DEPRECATED FUNCTIONALITY ********");
- System.err.println(" * You have initialized a cipher with a PBE key with no IV and");
- System.err.println(" * have not provided an IV in the AlgorithmParameterSpec. This");
- System.err.println(" * configuration is deprecated. The cipher will be initialized");
- System.err.println(" * with an all-zero IV, but in a future release this call will");
- System.err.println(" * throw an exception.");
- new InvalidAlgorithmParameterException("No IV set when using PBE key")
- .printStackTrace(System.err);
+ throw new InvalidAlgorithmParameterException("No IV set when using PBE key");
}
- // END Android-changed: For PBE keys with no IV, log and use IV of 0
+ // END Android-changed: Reject PBE keys with no IV
param = new ParametersWithIV(param, iv);
ivParam = (ParametersWithIV)param;
}
else if (cipher.getUnderlyingCipher().getAlgorithmName().indexOf("PGPCFB") < 0)
{
- // BEGIN Android-changed: For PBE keys with no IV, log and use IV of 0
+ // BEGIN Android-changed: Reject PBE keys with no IV
// These keys were accepted in BC 1.52 (and treated as having an IV of 0) but
- // rejected outright in BC 1.54 (even if an IV was passed in params). We
- // want the eventual state to be that an IV can be passed in params, but the key
- // is rejected otherwise. For now, log that these will be rejected in a future
- // release. See b/27995180 for historical details.
- // throw new InvalidAlgorithmParameterException("no IV set when one expected");
- if (!isBCPBEKeyWithoutIV(key)) {
- throw new InvalidAlgorithmParameterException("no IV set when one expected");
- } else {
- // TODO(b/70275132): Change to rejecting these keys
- System.err.println(" ******** DEPRECATED FUNCTIONALITY ********");
- System.err.println(" * You have initialized a cipher with a PBE key with no IV and");
- System.err.println(" * have not provided an IV in the AlgorithmParameterSpec. This");
- System.err.println(" * configuration is deprecated. The cipher will be initialized");
- System.err.println(" * with an all-zero IV, but in a future release this call will");
- System.err.println(" * throw an exception.");
- new InvalidAlgorithmParameterException("No IV set when using PBE key")
- .printStackTrace(System.err);
- // Mimic behaviour in 1.52 by using an IV of 0's
- param = new ParametersWithIV(param, new byte[ivLength]);
- ivParam = (ParametersWithIV)param;
- }
- // END Android-changed: For PBE keys with no IV, log and use IV of 0
+ // rejected outright in BC 1.54 (even if an IV was passed in params).
+ throw new InvalidAlgorithmParameterException("No IV set when using PBE key");
+ // END Android-changed: Reject PBE keys with no IV
}
}
diff --git a/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java b/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
index 1eeb6e96..51310cb5 100644
--- a/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
+++ b/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
@@ -961,56 +961,26 @@ public class BaseBlockCipher
{
byte[] iv = new byte[ivLength];
- // BEGIN Android-changed: For PBE keys with no IV, log and use IV of 0
+ // BEGIN Android-changed: Reject PBE keys with no IV
// These keys were accepted in BC 1.52 (and treated as having an IV of 0) but
- // rejected outright in BC 1.54 (even if an IV was passed in params). We
- // want the eventual state to be that an IV can be passed in params, but the key
- // is rejected otherwise. For now, log that these will be rejected in a future
- // release. See b/27995180 for historical details.
- // ivRandom.nextBytes(iv);
+ // rejected outright in BC 1.54 (even if an IV was passed in params).
+ // See b/27995180 for historical details.
if (!isBCPBEKeyWithoutIV(key)) {
ivRandom.nextBytes(iv);
} else {
- // TODO(b/70275132): Change to rejecting these keys
- System.err.println(" ******** DEPRECATED FUNCTIONALITY ********");
- System.err.println(" * You have initialized a cipher with a PBE key with no IV and");
- System.err.println(" * have not provided an IV in the AlgorithmParameterSpec. This");
- System.err.println(" * configuration is deprecated. The cipher will be initialized");
- System.err.println(" * with an all-zero IV, but in a future release this call will");
- System.err.println(" * throw an exception.");
- new InvalidAlgorithmParameterException("No IV set when using PBE key")
- .printStackTrace(System.err);
+ throw new InvalidAlgorithmParameterException("No IV set when using PBE key");
}
- // END Android-changed: For PBE keys with no IV, log and use IV of 0
+ // END Android-changed: Reject PBE keys with no IV
param = new ParametersWithIV(param, iv);
ivParam = (ParametersWithIV)param;
}
else if (cipher.getUnderlyingCipher().getAlgorithmName().indexOf("PGPCFB") < 0)
{
- // BEGIN Android-changed: For PBE keys with no IV, log and use IV of 0
+ // BEGIN Android-changed: Reject PBE keys with no IV
// These keys were accepted in BC 1.52 (and treated as having an IV of 0) but
- // rejected outright in BC 1.54 (even if an IV was passed in params). We
- // want the eventual state to be that an IV can be passed in params, but the key
- // is rejected otherwise. For now, log that these will be rejected in a future
- // release. See b/27995180 for historical details.
- // throw new InvalidAlgorithmParameterException("no IV set when one expected");
- if (!isBCPBEKeyWithoutIV(key)) {
- throw new InvalidAlgorithmParameterException("no IV set when one expected");
- } else {
- // TODO(b/70275132): Change to rejecting these keys
- System.err.println(" ******** DEPRECATED FUNCTIONALITY ********");
- System.err.println(" * You have initialized a cipher with a PBE key with no IV and");
- System.err.println(" * have not provided an IV in the AlgorithmParameterSpec. This");
- System.err.println(" * configuration is deprecated. The cipher will be initialized");
- System.err.println(" * with an all-zero IV, but in a future release this call will");
- System.err.println(" * throw an exception.");
- new InvalidAlgorithmParameterException("No IV set when using PBE key")
- .printStackTrace(System.err);
- // Mimic behaviour in 1.52 by using an IV of 0's
- param = new ParametersWithIV(param, new byte[ivLength]);
- ivParam = (ParametersWithIV)param;
- }
- // END Android-changed: For PBE keys with no IV, log and use IV of 0
+ // rejected outright in BC 1.54 (even if an IV was passed in params).
+ throw new InvalidAlgorithmParameterException("No IV set when using PBE key");
+ // END Android-changed: Reject PBE keys with no IV
}
}
diff --git a/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java b/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
index 7eaf8ac8..50417c7a 100644
--- a/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
+++ b/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/provider/symmetric/util/BaseBlockCipher.java
@@ -961,56 +961,26 @@ public class BaseBlockCipher
{
byte[] iv = new byte[ivLength];
- // BEGIN Android-changed: For PBE keys with no IV, log and use IV of 0
+ // BEGIN Android-changed: Reject PBE keys with no IV
// These keys were accepted in BC 1.52 (and treated as having an IV of 0) but
- // rejected outright in BC 1.54 (even if an IV was passed in params). We
- // want the eventual state to be that an IV can be passed in params, but the key
- // is rejected otherwise. For now, log that these will be rejected in a future
- // release. See b/27995180 for historical details.
- // ivRandom.nextBytes(iv);
+ // rejected outright in BC 1.54 (even if an IV was passed in params).
+ // See b/27995180 for historical details.
if (!isBCPBEKeyWithoutIV(key)) {
ivRandom.nextBytes(iv);
} else {
- // TODO(b/70275132): Change to rejecting these keys
- System.err.println(" ******** DEPRECATED FUNCTIONALITY ********");
- System.err.println(" * You have initialized a cipher with a PBE key with no IV and");
- System.err.println(" * have not provided an IV in the AlgorithmParameterSpec. This");
- System.err.println(" * configuration is deprecated. The cipher will be initialized");
- System.err.println(" * with an all-zero IV, but in a future release this call will");
- System.err.println(" * throw an exception.");
- new InvalidAlgorithmParameterException("No IV set when using PBE key")
- .printStackTrace(System.err);
+ throw new InvalidAlgorithmParameterException("No IV set when using PBE key");
}
- // END Android-changed: For PBE keys with no IV, log and use IV of 0
+ // END Android-changed: Reject PBE keys with no IV
param = new ParametersWithIV(param, iv);
ivParam = (ParametersWithIV)param;
}
else if (cipher.getUnderlyingCipher().getAlgorithmName().indexOf("PGPCFB") < 0)
{
- // BEGIN Android-changed: For PBE keys with no IV, log and use IV of 0
+ // BEGIN Android-changed: Reject PBE keys with no IV
// These keys were accepted in BC 1.52 (and treated as having an IV of 0) but
- // rejected outright in BC 1.54 (even if an IV was passed in params). We
- // want the eventual state to be that an IV can be passed in params, but the key
- // is rejected otherwise. For now, log that these will be rejected in a future
- // release. See b/27995180 for historical details.
- // throw new InvalidAlgorithmParameterException("no IV set when one expected");
- if (!isBCPBEKeyWithoutIV(key)) {
- throw new InvalidAlgorithmParameterException("no IV set when one expected");
- } else {
- // TODO(b/70275132): Change to rejecting these keys
- System.err.println(" ******** DEPRECATED FUNCTIONALITY ********");
- System.err.println(" * You have initialized a cipher with a PBE key with no IV and");
- System.err.println(" * have not provided an IV in the AlgorithmParameterSpec. This");
- System.err.println(" * configuration is deprecated. The cipher will be initialized");
- System.err.println(" * with an all-zero IV, but in a future release this call will");
- System.err.println(" * throw an exception.");
- new InvalidAlgorithmParameterException("No IV set when using PBE key")
- .printStackTrace(System.err);
- // Mimic behaviour in 1.52 by using an IV of 0's
- param = new ParametersWithIV(param, new byte[ivLength]);
- ivParam = (ParametersWithIV)param;
- }
- // END Android-changed: For PBE keys with no IV, log and use IV of 0
+ // rejected outright in BC 1.54 (even if an IV was passed in params).
+ throw new InvalidAlgorithmParameterException("No IV set when using PBE key");
+ // END Android-changed: Reject PBE keys with no IV
}
}