Sensitive data must be protected from eavesdropping and malicious tampering. An obfuscated transfer object \[ [Steel 2005|AA. References#Steel 05] \] that is strongly encrypted can protect data. This approach is known as _sealing_ the object. To guarantee object integrity, apply a digital signature to the sealed object. Wiki Markup
Sealing and signing objects is the preferred mechanism to secure data when
...
This noncompliant code example uses the java.security.SignedObject
class to sign an object when the integrity of the object must 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.
This noncompliant code example signs the object as well as seals it. According to Abadi and Needham \ [[Abadi 1996|AA. References#Abadi 96]\], Wiki Markup
When a principal signs material that has already been encrypted, it should not be inferred that the principal knows the content of the message. On the other hand, it is proper to infer that the principal that signs a message and then encrypts it for privacy knows the content of the message.
Any malicious party can intercept the originally signed encrypted message from the originator, strip the signature, and add its own signature to the encrypted message. Both the malicious party and the receiver have no information about the contents of the original message as it is encrypted and then signed (it can be decrypted only after verifying the signature). The receiver has no way of confirming the sender's identity unless the legitimate sender's public key is obtained over a secure channel. One of the three Internal Telegraph and Telephone Consultative Committee (CCITT) X.509 standard protocols was susceptible to such an attack \[ [CCITT 1988|AA. References#CCITT 88]\]. Wiki Markup
Because the signing occurs after the sealing, it cannot be assumed that the signer is the true originator of the object.
...
Code Block | ||
---|---|---|
| ||
public static void main(String[] args) throws IOException, GeneralSecurityException, ClassNotFoundException { // Build map SerializableMap<String, Integer> map = buildMap(); // Generate signing public/private key pair & sign map KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA"); KeyPair kp = kpg.generateKeyPair(); Signature sig = Signature.getInstance("SHA1withDSA"); SignedObject signedMap = new SignedObject(map, kp.getPrivate(), sig); // Generate sealing key & seal map KeyGenerator generator; generator = KeyGenerator.getInstance("AES"); generator.init(new SecureRandom()); Key key = generator.generateKey(); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); SealedObject sealedMap = new SealedObject(signedMap, cipher); // Serialize map ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("data")); out.writeObject(sealedMap); out.close(); // Deserialize map ObjectInputStream in = new ObjectInputStream(new FileInputStream("data")); sealedMap = (SealedObject) in.readObject(); in.close(); // Unseal map cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, key); signedMap = (SignedObject) sealedMap.getObject(cipher); // Verify signature and retrieve map if (!signedMap.verify(kp.getPublic(), sig)) { throw new GeneralSecurityException("Map failed verification"); } map = (SerializableMap<String, Integer>) signedMap.getObject(); // Inspect map InspectMap(map); } |
Exceptions
...
*SER02-EX0:* A reasonable use for signing a sealed object is to certify the authenticity of a sealed object passed from elsewhere. This represents a commitment _about the sealed object itself_ rather than about its content \[ [Abadi 1996|AA. References#Abadi 96]\].
SER02-EX1: Signing and sealing is required only for objects that must cross a trust boundary. Objects that never leave the trust boundary need not be signed or sealed. For example, when an entire network is contained within a trust boundary, objects that never leave that network need not be signed or sealed. Another example would be objects that are only sent down a signed binary stream.
...
Bibliography
[API 2006] |
| |||
9.10, Sealing Objects | ||||
Chapter 11, Object serialization, sealed objects | ||||
Item 64, Use | ||||
| Item 65, Use | |||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0f748a1d-219d-4885-a83e-2263e50b534f"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. References#API 06]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="73a24642-3c24-4d27-b6c6-a161b36d02d8"><ac:plain-text-body><![CDATA[ | [[Gong 2003 | AA. References#Gong 03]] | 9.10, Sealing Objects | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="3ba7f4fd-9e0b-4efb-918b-316a9004af5a"><ac:plain-text-body><![CDATA[ | [[Harold 1999 | AA. References#Harold 99]] | Chapter 11, Object serialization, sealed objects | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2e037aed-d516-4e36-b763-99a8fd4d05b1"><ac:plain-text-body><![CDATA[ | [[Neward 2004 | AA. References#Neward 04]] | Item 64, Use | ]]></ac:plain-text-body></ac:structured-macro> |
| Item 65, Use | |||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="cc911854-e0d1-4029-be9f-f8c93a6a5721"><ac:plain-text-body><![CDATA[ | [[Steel 2005 | AA. References#Steel 05]] | Chapter 10, Securing the Business Tier, Obfuscated Transfer Object ]]></ac:plain-text-body></ac:structured-macro> |
...
13. Serialization (SER) SER03-J. Do not serialize unencrypted, sensitive data