You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 32 Next »

It is imperative that sensitive data should be protected from eavesdropping and malicious tampering during transit. An Obfuscated Transfer Object [[Steel 2005]] can be used to encrypt data in exchanges that involve multiple business tiers or end user systems. Obfuscation can be achieved, largely, by encrypting the sensitive object (sealing). This design pattern can further be supplemented to provide signature capabilities for guaranteeing object integrity.

Signing and sealing objects is the preferred mechanism to secure data when

  • The data is sensitive but its serialization or transportation is necessary
  • A secure communication channel such as SSL is absent or is a costly alternative for limited transactions
  • Some sensitive data needs to persist over an extended period of time (for example, on an external hard drive)
  • Implementing home-brewed cryptographic algorithms such as in the readObject and writeObject methods can leave the application vulnerable

Noncompliant Code Example

This noncompliant code example is capable of being serialized and transferred across different business tiers. Unfortunately, there are no safeguards against byte stream manipulation attacks while the binary data is in transit. Likewise, anyone can reverse engineer the stream data from its hexadecimal notation to unravel the HashMap containing sensitive social security numbers.

class SimpleObject<E,V> implements Serializable {
  final static long serialVersionUID = -2648720192864531932L;
  private HashMap<E,V> ssnMap;
  
  public SimpleObject() {
    ssnMap = new HashMap<E,V>();
  }

  public Object getdata(E key)  {
    return ssnMap.get(key);
  }

  public void setData(E key, V data)  {
    ssnMap.put(key, data);
  }
}

Compliant Solution

To provide message confidentiality, use the javax.crypto.SealedObject class. This class encapsulates a serialized object and encrypts (or seals) it. A strong cryptographic algorithm that uses a secure cryptographic key and padding scheme must be employed to initialize the Cipher object parameter. The seal and unseal utility methods provide the encryption and decryption facilities respectively.

In addition, use the sign and unsign utility methods when the integrity of the object is to be ensured. The two new arguments passed in to the SignedObject() method to sign the object are Signature and a private key derived from a KeyPair object. To verify the signature, a PublicKey as well as a Signature argument is passed to the SignedObject.verify() method.

class SignSealUtility<E,V> implements Serializable {
  final static long serialVersionUID = 2648720192864531932L;
  private HashMap<E,V> ssnMap;
  private SealedObject sealedSsnMap;
  private SignedObject signedSsnMap;
  
  public SignSealUtility() {
    ssnMap = new HashMap<E,V>();
  }

  public void seal(Cipher cipher) throws Exception {
    sealedSsnMap = new SealedObject(ssnMap, cipher);
    // Now set the Map to null so that original data does not remain in cleartext
    ssnMap = null; 
  }

  public void unseal(Cipher cipher) throws Exception {
    ssnMap = (HashMap<E,V>)sealedSsnMap.getObject(cipher);
  }
  
  public void sign(Signature sig, PrivateKey key) throws Exception {
    signedSsnMap = new SignedObject(ssnMap, key, sig);
    ssnMap = null;
  }

  public void unsign(Signature sig, PublicKey key) throws Exception {
    if(signedSsnMap.verify(key, sig)) {
      ssnMap = (HashMap<E,V>)signedSsnMap.getObject();
    }
  }

  public Object getdata(E key) throws Exception {
    return ssnMap.get(key);
  }
 
  public void setData(E key, V data) throws Exception {
    ssnMap.put(key, data);
  }
}

Finally, refrain from signing encrypted (sealed) data. (See guideline SEC17-J. Create and sign a SignedObject before creating a SealedObject.)

Risk Assessment

Failure to sign and/or seal objects during transit can lead to loss of object integrity or confidentiality.

Guideline

Severity

Likelihood

Remediation Cost

Priority

Level

SEC16-J

medium

probable

high

P4

L3

Automated Detection

TODO

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

[[API 2006]]
[[Steel 2005]] Chapter 10: Securing the Business Tier, Obfuscated Transfer Object
[[Gong 2003]] 9.10 Sealing Objects
[[Harold 1999]] Chapter 11: Object Serialization, Sealed Objects
[[Neward 2004]] Item 64: Use SignedObject to provide integrity of Serialized objects and Item 65: Use SealedObject to provide confidentiality of Serializable objects
[[MITRE 2009]] CWE ID 319 "Cleartext Transmission of Sensitive Information"


SEC15-J. Prefer using SSLSockets over Sockets for secure data exchange      02. Platform Security (SEC)      SEC17-J. Create and sign a SignedObject before creating a SealedObject

  • No labels