1) XML Encryption test-cases
I have uploaded some test-cases to github to show how to use the new StAX-based API. The tests and setup mirror the XML Signature testcases that I covered in the previous blog post. There are currently three junit tests in this project:
- EncryptionDOMTest - Encrypt + decrypt using the (older) DOM API
- EncryptionStAXTest - Encrypt + decrypt using the new StAX API
- EncryptionInteropTest - Test interop between the two implementations
To see how to configure the new outbound StAX-based XML Encryption functionality, take a look at the "encryptUsingStax" method used by the tests. The streaming XML Security functionality is configured by populating a XMLSecurityProperties Object. You must typically call the following methods for XML Encryption:
- properties.setAction(XMLSecurityConstants.Action) - an "Action" to perform, which for XML Encryption purposes is XMLSecurityConstants.ENCRYPT.
- properties.setEncryptionKey(Key) - The encrypting key. Typically a SecretKey instance.
- properties.setEncryptionSymAlgorithm(String) - Symmetric encryption Algorithm to use. The default is AES 256.
- properties.addEncryptionPart(SecurePart) - Add a SecurePart to encrypt, e.g. encrypt a given QName.
- properties.setEncryptionTransportKey(Key) - The key to use to encrypt the secret key (if desired). Either a SecretKey or PublicKey instance.
- properties.setEncryptionKeyTransportAlgorithm(String) - The encryption key transport algorithm to use, to encrypt the secret key (if desired). Default is RSA OAEP.
- properties.setEncryptionKeyIdentifier(SecurityTokenConstants.KeyIdentifier) - How to reference the encrypting key/cert. The default is SecurityTokenConstants.KeyIdentifier_IssuerSerial.
- SecurityTokenConstants.KeyIdentifier_KeyValue
- SecurityTokenConstants.KeyIdentifier_KeyName
- SecurityTokenConstants.KeyIdentifier_IssuerSerial
- SecurityTokenConstants.KeyIdentifier_SkiKeyIdentifier
- SecurityTokenConstants.KeyIdentifier_X509KeyIdentifier
- SecurityTokenConstants.KeyIdentifier_X509SubjectName
- SecurityTokenConstants.KeyIdentifier_NoKeyInfo
To see how to configure the new inbound StAX-based XML Encryption functionality, take a look at the "decryptUsingStAX" method used by the tests. As with encryption creation, it is necessary to create a XMLSecurityProperties Object, and to tell it what "Action" to perform. In addition you must call the following method:
- properties.setDecryptionKey(Key) - a key to use to decrypt the request.
This comment has been removed by the author.
ReplyDeleteThanks for adding the streaming functionality. This will be really useful. I have some problems figuring out how to sign a document accoriding to XMLDSIG 1.0 using the streaming api and how to control where to insert the signature.
ReplyDeleteWhat I want as a result is something like this:
<foo>
<foobar>text with no meaning</foobar>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod>
<ds:Reference URI="">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform>
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
<ds:DigestValue>VuZTEoupBF8hhaUPVABeG8++fIw=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
....
</ds:Signature>
Hi,
ReplyDeleteRight now it is not possible to control where to insert the signature for the streaming case. See the following JIRA for more information:
https://issues.apache.org/jira/browse/SANTUARIO-324
Colm.