Return-Path: X-Original-To: apmail-santuario-dev-archive@www.apache.org Delivered-To: apmail-santuario-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0B92911F17 for ; Thu, 22 May 2014 00:05:03 +0000 (UTC) Received: (qmail 69947 invoked by uid 500); 22 May 2014 00:05:02 -0000 Delivered-To: apmail-santuario-dev-archive@santuario.apache.org Received: (qmail 69914 invoked by uid 500); 22 May 2014 00:05:02 -0000 Mailing-List: contact dev-help@santuario.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@santuario.apache.org Delivered-To: mailing list dev@santuario.apache.org Received: (qmail 69907 invoked by uid 99); 22 May 2014 00:05:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 May 2014 00:05:02 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of putmanb@georgetown.edu designates 209.85.220.45 as permitted sender) Received: from [209.85.220.45] (HELO mail-pa0-f45.google.com) (209.85.220.45) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 May 2014 00:04:57 +0000 Received: by mail-pa0-f45.google.com with SMTP id ey11so1884696pad.18 for ; Wed, 21 May 2014 17:04:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:content-type; bh=hCABCBgnH4xjWulbVYYBFMnCDQOe4sLBA+h1ULjz6k4=; b=QwCNQ+GwoN5P4v2kNTaJcE9a2JBnOtimy3HjnPkgl/0w419nOOrFbHAEVYwHowTpKm ggYWVOIjL97TGmY5CUlWGgtv2aKW2C3yl+/0VuDz+BOsJdK1RZsolL18xhtpg2Voybp/ GiPgdb8OD7zbVjW/2B/Io4/RBEPKv/l3LWkZefGi+VNGulUmOouy6IsqhtYHWGiVcJv8 bpXqISx9YIk4UEPWeiF+KIz8Q7l3F5S9L4jYPeeHDNgTgbeyCBfTktmVz2SvsK4p7m0D Yqp2kOV7pM3LujK38ARIDd7RNG3Ped0Ge3+3GMLju/aaLz2+JwLBV5UlcWqHSsHLP4PK 4FFg== X-Gm-Message-State: ALoCoQm72GYx5rXPj+9NdhLLwR+ViddJ0QzWY/2/pMSKuklQFajG/9mplWXFHWpHcG+UEJn9rzff X-Received: by 10.66.65.138 with SMTP id x10mr63064957pas.17.1400717076855; Wed, 21 May 2014 17:04:36 -0700 (PDT) Received: from Brent-Putmans-Mac-Pro.local ([162.211.160.162]) by mx.google.com with ESMTPSA id no9sm9931380pbc.83.2014.05.21.17.04.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 21 May 2014 17:04:35 -0700 (PDT) Message-ID: <537D3F12.4080903@georgetown.edu> Date: Wed, 21 May 2014 20:04:34 -0400 From: Brent Putman User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: dev@santuario.apache.org Subject: AES GCM and Java 8 Content-Type: multipart/alternative; boundary="------------040000020309000600090700" X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. --------------040000020309000600090700 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi, For our next major release of OpenSAML, we were doing some testing around the use of AES GCM for XML encryption. It seems to work ok using the Bouncy Castle provider. We were also hoping to be able to support this in Java 8 without BC, since at least Oracle's provider now supports AES GCM out-of-the-box. Avoiding the need to install BC is seen as desirable for our OpenSAML and Shibboleth deployers. However we have uncovered a problem with the use of Java 8. The current XMLCipher code unconditionally passes an instance of javax.crypto.spec.IvParameterSpec to the Cipher instance used. BC seems to like and want this. However, Oracle's provider fails with: java.security.InvalidAlgorithmParameterException: Unsupported parameter: javax.crypto.spec.IvParameterSpec@15bbf42f at com.sun.crypto.provider.CipherCore.init(CipherCore.java:509) at com.sun.crypto.provider.AESCipher.engineInit(AESCipher.java:339) at javax.crypto.Cipher.implInit(Cipher.java:801) at javax.crypto.Cipher.chooseProvider(Cipher.java:859) at javax.crypto.Cipher.init(Cipher.java:1370) at javax.crypto.Cipher.init(Cipher.java:1301) at org.apache.xml.security.encryption.XMLCipher.encryptData(XMLCipher.java:1129) at org.apache.xml.security.encryption.XMLCipher.encryptData(XMLCipher.java:1081) at org.apache.xml.security.encryption.XMLCipher.encryptData(XMLCipher.java:1012) Some more research showed that Oracle's provider seems to want the new javax.crypto.spec.GCMParameterSpec introduced in Java 7, for the AES GCM modes. I was preparing to submit a Jira issue and patch for this to XMLCipher, which conditionally detects whether the algorithm URI was one of the GCM ones, and produces an instance of GCMParameterSpec instead. BC claims that they now support this as Cipher input as of their 1.50 release [1]: > The JDK 1.5+ provider will now recognise and use GCMParameterSpec if > it is run in a 1.7 JVM. The actual BC crypto ops seem to work ok. However I think they have a bug around this: when used with GCMParameterSpec, after encryption their Cipher#getIV() returns null. This is used by XMLCipher to get the IV to concat with the encrypted bytes (see around line 1172). The null here causes an NPE. So this currently doesn't just transparently work as it should. Aside from this BC issue, it seems to me that use of GCMParameterSpec is the new "official" provider-independent way this is supposed to work in Java 7+, and that XMLCipher should support its use. Before I spend more time delving into this, I just wanted to see if this was on anyone's radar. I don't see anything in Jira about it currently. Thanks, Brent [1] http://www.bouncycastle.org/releasenotes.html --------------040000020309000600090700 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi,
For our next major release of OpenSAML, we were doing some testing around the use of AES GCM for XML encryption.  It seems to work ok using the Bouncy Castle provider.

We were also hoping to be able to support this in Java 8 without BC, since at least Oracle's provider now supports AES GCM out-of-the-box.  Avoiding the need to install BC is seen as desirable for our OpenSAML and Shibboleth deployers.

However we have uncovered a problem with the use of Java 8.  The current XMLCipher code unconditionally passes an instance of javax.crypto.spec.IvParameterSpec to the Cipher instance used.  BC seems to like and want this.  However, Oracle's provider fails with:

java.security.InvalidAlgorithmParameterException: Unsupported parameter: javax.crypto.spec.IvParameterSpec@15bbf42f
    at com.sun.crypto.provider.CipherCore.init(CipherCore.java:509)
    at com.sun.crypto.provider.AESCipher.engineInit(AESCipher.java:339)
    at javax.crypto.Cipher.implInit(Cipher.java:801)
    at javax.crypto.Cipher.chooseProvider(Cipher.java:859)
    at javax.crypto.Cipher.init(Cipher.java:1370)
    at javax.crypto.Cipher.init(Cipher.java:1301)
    at org.apache.xml.security.encryption.XMLCipher.encryptData(XMLCipher.java:1129)
    at org.apache.xml.security.encryption.XMLCipher.encryptData(XMLCipher.java:1081)
    at org.apache.xml.security.encryption.XMLCipher.encryptData(XMLCipher.java:1012)



Some more research showed that Oracle's provider seems to want the new javax.crypto.spec.GCMParameterSpec introduced in Java 7, for the AES GCM modes.

I was preparing to submit a Jira issue and patch for this to XMLCipher, which conditionally detects whether the algorithm URI was one of the GCM ones, and produces an instance of GCMParameterSpec instead.  BC claims that they now support this as Cipher input as of their 1.50 release [1]:
The JDK 1.5+ provider will now recognise and use GCMParameterSpec if it is run in a 1.7 JVM.

The actual BC crypto ops seem to work ok.  However I think they have a bug around this: when used with GCMParameterSpec, after encryption their Cipher#getIV() returns null.  This is used by XMLCipher to get the IV to concat with the encrypted bytes (see around line 1172). The null here causes an NPE.  So this currently doesn't just transparently work as it should.

Aside from this BC issue, it seems to me that use of GCMParameterSpec is the new "official" provider-independent way this is supposed to work in Java 7+, and that XMLCipher should support its use. 

Before I spend more time delving into this, I just wanted to see if this was on anyone's radar.  I don't see anything in Jira about it currently.

Thanks,
Brent


[1] http://www.bouncycastle.org/releasenotes.html
--------------040000020309000600090700--