@@ -126,18 +126,23 @@ public static SecretKey generateSecretKey(String alg, int keySize)
126126 * this is thrown with the original {@code UnsupportedEncodingException}
127127 * as the cause. (NOTE: This should never happen as "UTF-8" is supposed to
128128 * be a common encoding supported by all Java implementations. Support
129- * for it is usually in rt.jar.)
129+ * for it is usually in rt.jar.) This exception is also thrown if the
130+ * requested {@code keySize} parameter exceeds the length of the number of
131+ * bytes provded in the {@code keyDerivationKey} parameter.
130132 * @throws InvalidKeyException Likely indicates a coding error. Should not happen.
131133 * @throws EncryptionException Throw for some precondition violations.
132- * @deprecated Use{@code KeyDerivationFunction} instead. This method will be removed as of
133- * ESAPI release 2.3 so if you are using this, please change your code.
134+ * @deprecated Use same method in {@code KeyDerivationFunction} instead. This method will be <b>removed</b> as of
135+ * ESAPI release 2.3 so if you are using this, please CHANGE YOUR CODE. Note that the replacement
136+ * is not a static method, so create your own wrapper if you wish, but this will soon disappear.
134137 */
135138 @ Deprecated
136139 public static SecretKey computeDerivedKey (SecretKey keyDerivationKey , int keySize , String purpose )
137140 throws NoSuchAlgorithmException , InvalidKeyException , EncryptionException
138141 {
139- // These really should be turned into actual runtime checks and an
140- // IllegalArgumentException should be thrown if they are violated.
142+ // Fingers cross; maybe this will help.
143+ logger .warning (Logger .SECURITY_AUDIT ,
144+ "Your code is using the deprecated CryptoHelper.computeDerivedKey() method which will be removed next release" );
145+
141146 if ( keyDerivationKey == null ) {
142147 throw new IllegalArgumentException ("Key derivation key cannot be null." );
143148 }
@@ -159,6 +164,9 @@ public static SecretKey computeDerivedKey(SecretKey keyDerivationKey, int keySiz
159164 // DISCUSS: Should we use HmacSHA1 (what we were using) or the HMAC defined by
160165 // Encryptor.KDF.PRF instead? Either way, this is not compatible with
161166 // previous ESAPI versions. JavaEncryptor doesn't use this any longer.
167+ // ANSWER: This is deprecated and will be removed in 2.3.0.0, so it really matter
168+ // that much. However, Since the property Encryptor.KDF.PRF is (and has
169+ // been) "HMacSHA256". changing this could unintentionally break code.
162170 KeyDerivationFunction kdf = new KeyDerivationFunction (
163171 KeyDerivationFunction .PRF_ALGORITHMS .HmacSHA1 );
164172 return kdf .computeDerivedKey (keyDerivationKey , keySize , purpose );
@@ -260,7 +268,8 @@ public static boolean isCipherTextMACvalid(SecretKey sk, CipherText ct)
260268 {
261269 if ( CryptoHelper .isMACRequired ( ct ) ) {
262270 try {
263- SecretKey authKey = CryptoHelper .computeDerivedKey ( sk , ct .getKeySize (), "authenticity" );
271+ KeyDerivationFunction kdf = new KeyDerivationFunction ( ct .getKDF_PRF () );
272+ SecretKey authKey = kdf .computeDerivedKey (sk , ct .getKeySize (), "authenticity" );
264273 boolean validMAC = ct .validateMAC ( authKey );
265274 return validMAC ;
266275 } catch (Exception ex ) {
0 commit comments