Skip to content

Commit d973b5b

Browse files
Merge branch 'develop' into java-8
2 parents 0b0da0c + a9bdaab commit d973b5b

14 files changed

+200
-322
lines changed

configuration/esapi/ESAPI.properties

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ Encryptor.cipher_modes.combined_modes=GCM,CCM,IAPM,EAX,OCB,CWC
194194
# Additional cipher modes allowed for ESAPI 2.0 encryption. These
195195
# cipher modes are in _addition_ to those specified by the property
196196
# 'Encryptor.cipher_modes.combined_modes'.
197-
# Note: We will add support for streaming modes like CFB & OFB once
198-
# we add support for 'specified' to the property 'Encryptor.ChooseIVMethod'
199-
# (probably in ESAPI 2.1).
200197
# DISCUSS: Better name?
201198
Encryptor.cipher_modes.additional_allowed=CBC
202199

@@ -223,37 +220,27 @@ Encryptor.EncryptionKeyLength=128
223220
Encryptor.MinEncryptionKeyLength=128
224221

225222
# Because 2.x uses CBC mode by default, it requires an initialization vector (IV).
226-
# (All cipher modes except ECB require an IV.) There are two choices: we can either
227-
# use a fixed IV known to both parties or allow ESAPI to choose a random IV. While
228-
# the IV does not need to be hidden from adversaries, it is important that the
229-
# adversary not be allowed to choose it. Also, random IVs are generally much more
230-
# secure than fixed IVs. (In fact, it is essential that feed-back cipher modes
231-
# such as CFB and OFB use a different IV for each encryption with a given key so
232-
# in such cases, random IVs are much preferred. By default, ESAPI 2.0 uses random
233-
# IVs. If you wish to use 'fixed' IVs, set 'Encryptor.ChooseIVMethod=fixed' and
234-
# uncomment the Encryptor.fixedIV.
235-
#
236-
# Valid values: random|fixed|specified 'specified' not yet implemented; planned for 2.3
237-
# 'fixed' is deprecated as of 2.2
238-
# and will be removed in 2.3.
223+
# (All cipher modes except ECB require an IV.) Previously there were two choices: we can either
224+
# use a fixed IV known to both parties or allow ESAPI to choose a random IV. The
225+
# former was deprecated in ESAPI 2.2 and removed in ESAPI 2.3. It was not secure
226+
# because the Encryptor (as are all the other major ESAPI components) is a
227+
# singleton and thus the same IV would get reused each time. It was not a
228+
# well-thought out plan. (To do it correctly means we need to add a setIV() method
229+
# and get rid of the Encryptor singleton, thus it will not happen until 3.0.)
230+
# However, while the IV does not need to be hidden from adversaries, it is important that the
231+
# adversary not be allowed to choose it. Thus for now, ESAPI just chooses a random IV.
232+
# Originally there was plans to allow a developer to provide a class and method
233+
# name to define a custom static method to generate an IV, but that is just
234+
# trouble waiting to happen. Thus in effect, the ONLY acceptable property value
235+
# for this property is "random". In the not too distant future (possibly the
236+
# next release), I will be removing it, but for now I am leaving this and
237+
# checking for it so a ConfigurationException can be thrown if anyone using
238+
# ESAPI ignored the deprecation warning message and still has it set to "fixed".
239+
#
240+
# Valid values: random
239241
Encryptor.ChooseIVMethod=random
240242

241243

242-
# If you choose to use a fixed IV, then you must place a fixed IV here that
243-
# is known to all others who are sharing your secret key. The format should
244-
# be a hex string that is the same length as the cipher block size for the
245-
# cipher algorithm that you are using. The following is an *example* for AES
246-
# from an AES test vector for AES-128/CBC as described in:
247-
# NIST Special Publication 800-38A (2001 Edition)
248-
# "Recommendation for Block Cipher Modes of Operation".
249-
# (Note that the block size for AES is 16 bytes == 128 bits.)
250-
#
251-
# @Deprecated -- fixed IVs are deprecated as of the 2.2 release and support
252-
# will be removed in the next release (tentatively, 2.3).
253-
# If you MUST use this, at least replace this IV with one
254-
# that your legacy application was using.
255-
Encryptor.fixedIV=0x000102030405060708090a0b0c0d0e0f
256-
257244
# Whether or not CipherText should use a message authentication code (MAC) with it.
258245
# This prevents an adversary from altering the IV as well as allowing a more
259246
# fool-proof way of determining the decryption failed because of an incorrect

documentation/esapi4java-core-2.0-symmetric-crypto-user-guide.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ <H2>ESAPI.properties Properties Relevant to Symmetric Encryption</H2>
149149
compatibility with legacy or third party software. If set to
150150
“fixed”, then the property Encryptor.fixedIV must also be
151151
set to hex-encoded specific IV that you need to use.
152-
<B>NOTE:</B> "fixed" is deprecated and will be removed by
153-
release 2.3.
152+
<B>NOTE:</B> "fixed" had been deprecated since 2.2.0.0 and finally
153+
was removed for release 2.3.0.0. Using it in versions 2.3.0.0 or
154+
later will result in a <code>ConfigurationException</code> being thrown.
154155
</FONT></P><P><FONT SIZE=2>
155156
<B>CAUTION:</B> While it is not required that the IV be kept
156157
secret, encryption relying on fixed IVs can lead to a known

src/main/java/org/owasp/esapi/SecurityConfiguration.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -389,35 +389,22 @@ public interface SecurityConfiguration extends EsapiPropertyLoader {
389389
* fixed IVs, but the use of non-random IVs is inherently insecure,
390390
* especially for any supported cipher mode that is considered a streaming mode
391391
* (which is basically anything except CBC for modes that support require an IV).
392-
* For this reason, 'fixed' is considered <b>deprecated</b> and will be
393-
* removed during the next ESAPI point release (tentatively, 2.3).
394-
* However, note that if a "fixed" IV is chosen, then the
395-
* the value of this fixed IV must be specified as the property
396-
* {@code Encryptor.fixedIV} and be of the appropriate length.
392+
* For this reason, 'fixed' has now been removed (it was considered <b>deprecated</b>
393+
* since release 2.2.0.0). An <b>ESAPI.properties</b> value of {@Code fixed} for the property
394+
* {@Code Encryptor.ChooseIVMethod} will now result in a {@Code ConfigurationException}
395+
* being thrown.
397396
*
398-
* @return A string specifying the IV type. Should be "random" or "fixed" (dereprected).
397+
* @return A string specifying the IV type. Should be "random". Anything
398+
* else should fail with a {@Code ConfigurationException} being thrown.
399399
*
400400
* @see #getFixedIV()
401401
* @deprecated Use SecurityConfiguration.getStringProp("appropriate_esapi_prop_name") instead.
402+
* This method will be removed in a future release as it is now moot since
403+
* it can only legitimately have the single value of "random".
402404
*/
403405
@Deprecated
404406
String getIVType();
405407

406-
/**
407-
* If a "fixed" (i.e., static) Initialization Vector (IV) is to be used,
408-
* this will return the IV value as a hex-encoded string.
409-
* @return The fixed IV as a hex-encoded string.
410-
* @deprecated Short term: use SecurityConfiguration.getByteArrayProp("appropriate_esapi_prop_name")
411-
* instead. Longer term: There will be a more general method in JavaEncryptor
412-
* to explicitly set an IV. This whole concept of a single fixed IV has
413-
* always been a kludge at best, as a concession to those who have used
414-
* a single fixed IV in the past to support legacy applications. This method will be
415-
* killed off in the next ESAPI point release (likely 2.3). It's time to put it to death
416-
* as it was never intended for production in the first place.
417-
*/
418-
@Deprecated
419-
String getFixedIV();
420-
421408
/**
422409
* Return a {@code List} of strings of combined cipher modes that support
423410
* <b>both</b> confidentiality and authenticity. These would be preferred

src/main/java/org/owasp/esapi/crypto/CipherText.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,10 @@ public int getRawCipherTextByteLength() {
320320
* base64-encoding is performed.
321321
* <p>
322322
* If there is a need to store an encrypted value, say in a database, this
323-
* is <i>not</i> the method you should use unless you are using a <i>fixed</i>
324-
* IV or are planning on retrieving the IV and storing it somewhere separately
325-
* (e.g., a different database column). If you are <i>not</i> using a fixed IV
326-
* (which is <strong>highly</strong> discouraged), you should normally use
327-
* {@link #getEncodedIVCipherText()} instead.
323+
* is <i>not</i> the method you should use unless you are using are storing the
324+
* IV separately (i.e., in a separate DB column), which doesn't make a lot of sense.
325+
* Normally, you should prefer the method {@link #getEncodedIVCipherText()} instead as
326+
* it will return the IV prepended to the ciphertext.
328327
* </p>
329328
* @see #getEncodedIVCipherText()
330329
*/
@@ -338,11 +337,6 @@ public String getBase64EncodedRawCipherText() {
338337
* base64-encoding. If an IV is not used, then this method returns the same
339338
* value as {@link #getBase64EncodedRawCipherText()}.
340339
* <p>
341-
* Generally, this is the method that you should use unless you only
342-
* are using a fixed IV and a storing that IV separately, in which case
343-
* using {@link #getBase64EncodedRawCipherText()} can reduce the storage
344-
* overhead.
345-
* </p>
346340
* @return The base64-encoded ciphertext or base64-encoded IV + ciphertext.
347341
* @see #getBase64EncodedRawCipherText()
348342
*/
@@ -591,8 +585,8 @@ public void setIVandCiphertext(byte[] iv, byte[] ciphertext)
591585
// TODO: FIXME: As per email from Jeff Walton to Kevin Wall dated 12/03/2013,
592586
// this is not always true. E.g., for CCM, the IV length is supposed
593587
// to be 7, 8, 7, 8, 9, 10, 11, 12, or 13 octets because of
594-
// it's formatting function, the restof the octets used by the
595-
// nonce/counter.
588+
// it's formatting function, the rest of the octets are used by the
589+
// nonce/counter. E.g., see RFCs 4309, 8750, and related RFCs.
596590
throw new EncryptionException("Encryption failed -- bad parameters passed to encrypt", // DISCUSS - also log? See below.
597591
"IV length does not match cipher block size of " + getBlockSize());
598592
}

src/main/java/org/owasp/esapi/reference/DefaultSecurityConfiguration.java

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ public static SecurityConfiguration getInstance() {
121121
public static final String CIPHER_TRANSFORMATION_IMPLEMENTATION = "Encryptor.CipherTransformation";
122122
public static final String CIPHERTEXT_USE_MAC = "Encryptor.CipherText.useMAC";
123123
public static final String PLAINTEXT_OVERWRITE = "Encryptor.PlainText.overwrite";
124-
public static final String IV_TYPE = "Encryptor.ChooseIVMethod";
125124

126125
@Deprecated
127-
public static final String FIXED_IV = "Encryptor.fixedIV";
126+
public static final String IV_TYPE = "Encryptor.ChooseIVMethod"; // Will be removed in future release.
128127

129128
public static final String COMBINED_CIPHER_MODES = "Encryptor.cipher_modes.combined_modes";
130129
public static final String ADDITIONAL_ALLOWED_CIPHER_MODES = "Encryptor.cipher_modes.additional_allowed";
@@ -251,6 +250,13 @@ public static SecurityConfiguration getInstance() {
251250
*/
252251
public DefaultSecurityConfiguration(Properties properties) {
253252
resourceFile = DEFAULT_RESOURCE_FILE;
253+
try {
254+
this.esapiPropertyManager = new EsapiPropertyManager();
255+
// Do NOT call loadConfiguration() here!
256+
} catch( IOException e ) {
257+
logSpecial("Failed to load security configuration", e );
258+
throw new ConfigurationException("Failed to load security configuration", e);
259+
}
254260
this.properties = properties;
255261
this.setCipherXProperties();
256262
}
@@ -265,7 +271,7 @@ private void setCipherXProperties() {
265271
// TODO: FUTURE: Replace by future CryptoControls class???
266272
// See SecurityConfiguration.setCipherTransformation() for
267273
// explanation of this.
268-
// (Propose this in 2.1 via future email to ESAPI-DEV list.)
274+
// (Propose this in a future 2.x release via future email to ESAPI-DEV list.)
269275
cipherXformFromESAPIProp =
270276
getESAPIProperty(CIPHER_TRANSFORMATION_IMPLEMENTATION,
271277
"AES/CBC/PKCS5Padding");
@@ -832,49 +838,26 @@ public boolean overwritePlainText() {
832838
/**
833839
* {@inheritDoc}
834840
*/
841+
@Deprecated
835842
public String getIVType() {
836843
String value = getESAPIProperty(IV_TYPE, "random");
837844
if ( value.equalsIgnoreCase("random") ) {
838845
return value;
839846
} else if ( value.equalsIgnoreCase("fixed") ) {
840-
logSpecial("WARNING: Property '" + IV_TYPE + "=fixed' is DEPRECATED. It was intended to support legacy applications, but is inherently insecure, especially with any streaming mode. Support for this will be completed dropped next ESAPI minor release (probably 2.3");
841-
return value;
847+
logSpecial("WARNING: Property '" + IV_TYPE + "=fixed' is no longer supported AT ALL!!! It had been deprecated since 2.2.0.0 and back then, was announced it would be removed in release 2.3.0.0. It was originally intended to support legacy applications, but is inherently insecure, especially with any streaming mode.");
848+
throw new ConfigurationException("'" + IV_TYPE + "=fixed' is no longer supported AT ALL. It has been deprecated since release 2.2 and has been removed since 2.3.");
842849
} else if ( value.equalsIgnoreCase("specified") ) {
843-
// This is planned for future implementation where setting
844-
// Encryptor.ChooseIVMethod=specified will require setting some
845-
// other TBD property that will specify an implementation class that
846-
// will generate appropriate IVs. The intent of this would be to use
847-
// such a class with various feedback modes where it is imperative
848-
// that for a given key, any particular IV is *NEVER* reused. For
849-
// now, we will assume that generating a random IV is usually going
850-
// to be sufficient to prevent this.
851-
throw new ConfigurationException("'" + IV_TYPE + "=specified' is not yet implemented. Use 'random' for now.");
852-
} else {
853-
// TODO: Once 'specified' is legal, adjust exception msg, below.
854-
// DISCUSS: Could just log this and then silently return "random" instead.
855-
throw new ConfigurationException(value + " is illegal value for " + IV_TYPE +
856-
". Use 'random'.");
857-
}
858-
}
859-
860-
/**
861-
* {@inheritDoc}
862-
*/
863-
@Deprecated
864-
public String getFixedIV() {
865-
if ( getIVType().equalsIgnoreCase("fixed") ) {
866-
String ivAsHex = getESAPIProperty(FIXED_IV, ""); // No default
867-
if ( ivAsHex == null || ivAsHex.trim().equals("") ) {
868-
throw new ConfigurationException("Fixed IV requires property " +
869-
FIXED_IV + " to be set, but it is not.");
870-
}
871-
return ivAsHex; // We do no further checks here as we have no context.
850+
// Originally, this was planned for future implementation where setting
851+
// Encryptor.ChooseIVMethod=specified
852+
// would have allowed a dev to write their own static method to be
853+
// invoked in a future TBD property, but that is a recipe for
854+
// disaster. So, it's not going to happen. Ever.
855+
throw new ConfigurationException("Contrary to previous internal comments, '" + IV_TYPE + "=specified' is not going to be supported -- ever.");
872856
} else {
873-
// DISCUSS: Should we just log a warning here and return null instead?
874-
// If so, may cause NullPointException somewhere later.
875-
throw new ConfigurationException("IV type not 'fixed' [which is DEPRECATED!] (set to '" +
876-
getIVType() + "'), so no fixed IV applicable.");
857+
logSpecial("WARNING: '" + value + "' is illegal value for " + IV_TYPE +
858+
". Using 'random' for the IV type.");
877859
}
860+
return "random";
878861
}
879862

880863
/**

src/main/java/org/owasp/esapi/reference/crypto/JavaEncryptor.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -464,25 +464,10 @@ public CipherText encrypt(SecretKey key, PlainText plain)
464464
IvParameterSpec ivSpec = null;
465465
if ( ivType.equalsIgnoreCase("random") ) {
466466
ivBytes = ESAPI.randomizer().getRandomBytes(encrypter.getBlockSize());
467-
} else if ( ivType.equalsIgnoreCase("fixed") ) {
468-
String fixedIVAsHex = ESAPI.securityConfiguration().getFixedIV();
469-
ivBytes = Hex.decode(fixedIVAsHex);
470-
/* FUTURE } else if ( ivType.equalsIgnoreCase("specified")) {
471-
// FUTURE - TODO - Create instance of specified class to use for IV generation and
472-
// use it to create the ivBytes. (The intent is to make sure that
473-
// 1) IVs are never repeated for cipher modes like OFB and CFB, and
474-
// 2) to screen for weak IVs for the particular cipher algorithm.
475-
// In meantime, use 'random' for block cipher in feedback mode. Unlikely they will
476-
// be repeated unless you are salting SecureRandom with same value each time. Anything
477-
// monotonically increasing should be suitable, like a counter, but need to remember
478-
// it across JVM restarts. Was thinking of using System.currentTimeMillis(). While
479-
// it's not perfect it probably is good enough. Could even all (advanced) developers
480-
// to define their own class to create a unique IV to allow them some choice, but
481-
// definitely need to provide a safe, default implementation.
482-
*/
483467
} else {
484-
// TODO: Update to add 'specified' once that is supported and added above.
485-
throw new ConfigurationException("Property Encryptor.ChooseIVMethod must be set to 'random' or 'fixed'");
468+
// This really shouldn't happen here. Show catch it a few
469+
// lines above.
470+
throw new ConfigurationException("Property Encryptor.ChooseIVMethod must be set to 'random'.");
486471
}
487472
ivSpec = new IvParameterSpec(ivBytes);
488473
cipherSpec.setIV(ivBytes);

src/test/java/org/owasp/esapi/SecurityConfigurationWrapper.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,6 @@ public String getIVType()
291291
return wrapped.getIVType();
292292
}
293293

294-
/**
295-
* {@inheritDoc}
296-
*/
297-
// @Override
298-
public String getFixedIV()
299-
{
300-
return wrapped.getFixedIV();
301-
}
302294

303295
/**
304296
* {@inheritDoc}

src/test/java/org/owasp/esapi/crypto/CipherSpecTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public class CipherSpecTest extends TestCase {
2929
private byte[] myIV = null;
3030

3131
@Before public void setUp() throws Exception {
32-
// This will throw ConfigurationException if IV type is not set to
33-
// 'fixed', which it's not. (We have it set to 'random'.)
34-
// myIV = Hex.decode( ESAPI.securityConfiguration().getFixedIV() );
35-
myIV = Hex.decode( "0x000102030405060708090a0b0c0d0e0f" );
32+
myIV = Hex.decode( "0x000102030405060708090a0b0c0d0e0f" ); // Any IV to test w/ will do.
3633

3734
dfltAESCipher = Cipher.getInstance("AES");
3835
dfltECBCipher = Cipher.getInstance("AES/ECB/NoPadding");

0 commit comments

Comments
 (0)