Skip to content

Commit f8b1ed5

Browse files
committed
Fix test that was failing if BC was JCE provided and was failing on MacOS and
Windows.
1 parent 188c1aa commit f8b1ed5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/test/java/org/owasp/esapi/reference/crypto/EncryptorTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void testNewEncryptDecrypt() {
238238
* strength crypto is not available for this Java VM.
239239
*/
240240
private String runNewEncryptDecryptTestCase(String cipherXform, int keySize, byte[] plaintextBytes) {
241-
System.err.println("New encrypt / decrypt: " + cipherXform + "; requested key size: " + keySize + " bits.");
241+
// System.err.println("New encrypt / decrypt: " + cipherXform + "; requested key size: " + keySize + " bits.");
242242

243243
if ( keySize > 128 && !unlimitedStrengthJurisdictionPolicyInstalled ) {
244244
System.err.println("Skipping test for cipher transformation " +
@@ -255,19 +255,31 @@ private String runNewEncryptDecryptTestCase(String cipherXform, int keySize, byt
255255
assertTrue( skey.getAlgorithm().equals(cipherXform.split("/")[0]) );
256256
String cipherAlg = cipherXform.split("/")[0];
257257

258-
System.err.println("Key size of generated encoded key: " + skey.getEncoded().length * 8 + " bits.");
258+
// System.err.println("Key size of generated encoded key: " + skey.getEncoded().length * 8 + " bits.");
259259

260260
// Adjust key size for DES and DESede specific oddities.
261261
// NOTE: Key size that encrypt() method is using is 192 bits!!!
262262
// which is 3 times 64 bits, but DES key size is only 56 bits.
263263
// See 'IMPORTANT NOTE', in JavaEncryptor, near line 376. It's a "feature"!!!
264+
///// This section is causing problems. BC for instance sometimes creates a
265+
///// 192 bit key and then subsequently creates a 128-bit key for 2-key
266+
///// 3DES so adjusing this is futile. THis is a holdover when we were
267+
///// doing an *exact* size comparison in the following assertTrue() though.
268+
///// Since we are no longer doing that, we don't need to "adjust" the size
269+
///// so hopefully all will be well with the world.
270+
/////
271+
///// Delete this comment and the following commented-out code after the
272+
///// official 2.2.0.0 release.
273+
/////
274+
/*
264275
if ( cipherAlg.equals( "DESede" ) ) {
265276
System.err.println("Adjusting requested key size of " + keySize + " bits to 192 bits for DESede");
266277
keySize = 192;
267278
} else if ( cipherAlg.equals( "DES" ) ) {
268279
System.err.println("Adjusting requested key size of " + keySize + " bits to 64 bits for DES");
269280
keySize = 64;
270281
} // Else... use specified keySize.
282+
*/
271283

272284
assertTrue(cipherXform + ": encoded key size of " + skey.getEncoded().length + " shorter than requested key size of: " + (keySize / 8),
273285
skey.getEncoded().length >= (keySize / 8) );
@@ -278,7 +290,7 @@ private String runNewEncryptDecryptTestCase(String cipherXform, int keySize, byt
278290
@SuppressWarnings("deprecation")
279291
String oldCipherXform = ESAPI.securityConfiguration().setCipherTransformation(cipherXform);
280292
if ( ! cipherXform.equals(oldCipherXform) ) {
281-
System.err.println("Cipher xform changed from \"" + oldCipherXform + "\" to \"" + cipherXform + "\"");
293+
// System.err.println("Cipher xform changed from \"" + oldCipherXform + "\" to \"" + cipherXform + "\"");
282294
}
283295

284296
// Get an Encryptor instance with the specified, possibly new, cipher transformation.

0 commit comments

Comments
 (0)