Philip Helger created WSS-735:
---------------------------------

             Summary: Allow selecting the JCE provider for SwA attachment 
decryption, to enable streaming of large attachments
                 Key: WSS-735
                 URL: https://issues.apache.org/jira/browse/WSS-735
             Project: WSS4J
          Issue Type: Bug
          Components: WSS4J Core
    Affects Versions: 4.0.2
            Reporter: Philip Helger
            Assignee: Colm O hEigeartaigh


Decrypting an AES-GCM SwA attachment needs heap proportional to the attachment 
size with the default provider, even though 
AttachmentUtils.setupAttachmentDecryptionStream is stream based. SunJCE 
deliberately buffers all ciphertext until the tag was verified 
(GaloisCounterMode.GCMDecrypt.doUpdate: "store internally until doFinal"), so 
CipherInputStream returns no data before the end of the stream. For use cases 
that require AES-GCM, such as the Peppol AS4 profile, this limits the 
attachment size by the available heap.

 

 A provider that decrypts incrementally avoids this, but it cannot be selected 
for attachments, because the cipher is created without a provider:
 * EncryptionUtils.decryptAttachment: Cipher.getInstance(jceAlgorithm)
 * EncryptionUtils.decryptXopAttachment: Cipher.getInstance(jceAlgorithm)
 * Encryptor (attachment encryption): Cipher.getInstance(jceAlgorithm)

 

Key transport already handles this through KeyUtils.getCipherInstance, which 
falls back to JCEMapper.getProviderId(). The only workaround is the JVM-wide 
jdk.security.provider.preferred security property, which also affects all other 
users of AES/GCM in the JVM, possibly including TLS.

 

Proposal:
 # Use KeyUtils.getCipherInstance at the three places above, so that 
JCEMapper.setProviderId applies to them as well.
 # Add an API to choose the provider per request, as JCEMapper.setProviderId is 
global and also changes key transport and other cipher use in the same JVM. For 
example, a new property on RequestData such as 
setAttachmentDecryptionProvider(String) that is handed through to 
EncryptionUtils. The exact shape is up to you.

 

Security note: An incremental provider releases plaintext before the tag was 
verified, and a tag mismatch only shows up as an IOException at the end of the 
stream. Callers must read to the end and must not use the data before that. 
This should be mentioned in the Javadoc of the new option.


I'm happy to help with testing.

 



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to