You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by Henri Muurimaa <he...@itmill.com> on 2003/05/27 15:55:21 UTC

ArrayOutOfBoundsException with RSA key

Hello,

When I do something like this:

   XMLSignature sig = new 
XMLSignature(srcDocument,"",XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);

   <transform code snipped, should work>

   sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
			
   sig.sign(getPrivateKey());

I get an ArrayOutOfBoundsException at sign(). Stack trace below.

The key I obtain from the windows keystore with the Assembla JCE 
provider, and it should be fine since I can use it to sign other data 
using the Assembla signature classes.

Any thoughts about this? The key is the one Windows creates for all 
users for file system encryption. However, since I can use it with the 
Assembla signature classes, I should be able to use it with XMLSignature 
too, right? Or am I just missing something?

The exception stack trace:

java.lang.ArrayIndexOutOfBoundsException
	at com.sun.rsasign.al.a(DashoA6275)
	at com.sun.rsasign.al.b(DashoA6275)
	at com.sun.rsasign.al.a(DashoA6275)
	at com.sun.rsajca.JSA_RSAKeyFactory.engineTranslateKey(DashoA6275)
	at java.security.KeyFactory.translateKey(Unknown Source)
	at com.sun.rsajca.JS_Signature.engineInitSign(DashoA6275)
	at java.security.Signature$Delegate.engineInitSign(Unknown Source)
	at java.security.Signature.initSign(Unknown Source)
	at 
org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.engineInitSign(SignatureBaseRSA.java:254)
	at 
org.apache.xml.security.algorithms.SignatureAlgorithm.initSign(SignatureAlgorithm.java:296)
	at 
org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:524)
	<etc>


-- 
Henri Muurimaa


Re: ArrayOutOfBoundsException with RSA key

Posted by Henri Muurimaa <he...@itmill.com>.
Thanks for quick replies.

I'm using JRE 1.4 btw.

Anyway, I tried reordering providers but to no avail.

security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider

Ie. other providers commented out OR if I have:

security.provider.1=com.sun.net.ssl.internal.ssl.Provider
security.provider.2=sun.security.provider.Sun
security.provider.3=com.sun.rsajca.Provider

I get:

org.apache.xml.security.signature.XMLSignatureException: 
java.lang.NegativeArraySizeException
Original Exception was 
org.apache.xml.security.signature.XMLSignatureException: 
java.lang.NegativeArraySizeException
Original Exception was java.security.SignatureException: 
java.lang.NegativeArraySizeException
	at 
org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:549)
	at <my code>
Original Exception was java.security.SignatureException: 
java.lang.NegativeArraySizeException
	at 
org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.engineSign(SignatureBaseRSA.java:203)
	at 
org.apache.xml.security.algorithms.SignatureAlgorithm.sign(SignatureAlgorithm.java:230)
	at 
org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:537)
	at <my code>
java.security.SignatureException: java.lang.NegativeArraySizeException
	at 
org.bouncycastle.jce.provider.JDKDigestSignature.engineSign(JDKDigestSignature.java:100)
	at java.security.Signature.sign(Signature.java:397)
	at 
org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.engineSign(SignatureBaseRSA.java:201)
	at 
org.apache.xml.security.algorithms.SignatureAlgorithm.sign(SignatureAlgorithm.java:230)
	at 
org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:537)
	at <my code>

However, if I have other providers in there with bouncy castle like this:

security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider
security.provider.2=sun.security.provider.Sun
security.provider.3=com.sun.rsajca.Provider

I get:

java.lang.NullPointerException
	at 
org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.engineInitSign(SignatureBaseRSA.java:245)
	at 
org.apache.xml.security.algorithms.SignatureAlgorithm.initSign(SignatureAlgorithm.java:296)
	at 
org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:524)
	at <my code>

Any ideas?? By the way, I get identical behaviour with Windows-generated 
keys (for the encrypted file system) and with a key I generated myself 
using keytool. Has anyone else been able to use RSA keys with XMLSignature?


Husni Salka wrote:
> Change the RSA provider. It will work.
> 
> This looks suspiciously similar to bug 4430686, which was
> fixed in 1.4.
> 
> A workaround to try is to reorder the providers
> (in JRE/lib/security/java.security) so that the JSSE
> provider is configured before the SunRSASign provider, since
> the bug may not exist in the JSSE provider's RSA implementation.
> 
> I tried the work-around and it worked in 1.3.1_03 and 1.3.1_07
> 
> security.provider.1=com.sun.net.ssl.internal.ssl.Provider
> security.provider.2=sun.security.provider.Sun
> security.provider.3=com.sun.rsajca.Provider
> 
> You also may use bouncy castle and it will work as well.
> 
> Husni Salka
> Java Architect
> Sun Microsystems
> 
> 
> Christian Geuer-Pollmann wrote:
> 
> 
>>The Exception is not thrown by org.apache.xml.security.something but by
>>com.sun.rsasign.something, so I assume that the problem is with your key
>>material and SUN's RSA provider.
>>
>>Do the following to find out: Instantiate a java.security.Signature and
>>enforce that the SUN/RSA provider is used. Then sign some stuff with the
>>key in question. Then you'll know whether it is in Apache XML-Security or
>>not...
>>
>>Christian
>>
>>--On Dienstag, 27. Mai 2003 16:55 +0300 Henri Muurimaa
>><he...@itmill.com> wrote:
>>
>>
>>>Hello,
>>>
>>>When I do something like this:
>>>
>>>   XMLSignature sig = new
>>>XMLSignature(srcDocument,"",XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);
>>>
>>>   <transform code snipped, should work>
>>>
>>>   sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
>>>
>>>   sig.sign(getPrivateKey());
>>>
>>>I get an ArrayOutOfBoundsException at sign(). Stack trace below.
>>>
>>>The key I obtain from the windows keystore with the Assembla JCE
>>>provider, and it should be fine since I can use it to sign other data
>>>using the Assembla signature classes.
>>>
>>>Any thoughts about this? The key is the one Windows creates for all users
>>>for file system encryption. However, since I can use it with the Assembla
>>>signature classes, I should be able to use it with XMLSignature too,
>>>right? Or am I just missing something?
>>>
>>>The exception stack trace:
>>>
>>>java.lang.ArrayIndexOutOfBoundsException
>>>      at com.sun.rsasign.al.a(DashoA6275)
>>>      at com.sun.rsasign.al.b(DashoA6275)
>>>      at com.sun.rsasign.al.a(DashoA6275)
>>>      at com.sun.rsajca.JSA_RSAKeyFactory.engineTranslateKey(DashoA6275)
>>>      at java.security.KeyFactory.translateKey(Unknown Source)
>>>      at com.sun.rsajca.JS_Signature.engineInitSign(DashoA6275)
>>>      at java.security.Signature$Delegate.engineInitSign(Unknown Source)
>>>      at java.security.Signature.initSign(Unknown Source)
>>>      at
>>>org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.engin
>>>eInitSign(SignatureBaseRSA.java:254)  at
>>>org.apache.xml.security.algorithms.SignatureAlgorithm.initSign(SignatureA
>>>lgorithm.java:296)    at
>>>org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:524)
>>>      <etc>
>>>
>>>
>>>--
>>>Henri Muurimaa
>>>

-- 
Henri Muurimaa - +358 400 474 778 - IT Mill Oy - www.itmill.com


Re: ArrayOutOfBoundsException with RSA key

Posted by Husni Salka <Hu...@Sun.COM>.
Change the RSA provider. It will work.

This looks suspiciously similar to bug 4430686, which was
fixed in 1.4.

A workaround to try is to reorder the providers
(in JRE/lib/security/java.security) so that the JSSE
provider is configured before the SunRSASign provider, since
the bug may not exist in the JSSE provider's RSA implementation.

I tried the work-around and it worked in 1.3.1_03 and 1.3.1_07

security.provider.1=com.sun.net.ssl.internal.ssl.Provider
security.provider.2=sun.security.provider.Sun
security.provider.3=com.sun.rsajca.Provider

You also may use bouncy castle and it will work as well.

Husni Salka
Java Architect
Sun Microsystems


Christian Geuer-Pollmann wrote:

> The Exception is not thrown by org.apache.xml.security.something but by
> com.sun.rsasign.something, so I assume that the problem is with your key
> material and SUN's RSA provider.
>
> Do the following to find out: Instantiate a java.security.Signature and
> enforce that the SUN/RSA provider is used. Then sign some stuff with the
> key in question. Then you'll know whether it is in Apache XML-Security or
> not...
>
> Christian
>
> --On Dienstag, 27. Mai 2003 16:55 +0300 Henri Muurimaa
> <he...@itmill.com> wrote:
>
> > Hello,
> >
> > When I do something like this:
> >
> >    XMLSignature sig = new
> > XMLSignature(srcDocument,"",XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);
> >
> >    <transform code snipped, should work>
> >
> >    sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
> >
> >    sig.sign(getPrivateKey());
> >
> > I get an ArrayOutOfBoundsException at sign(). Stack trace below.
> >
> > The key I obtain from the windows keystore with the Assembla JCE
> > provider, and it should be fine since I can use it to sign other data
> > using the Assembla signature classes.
> >
> > Any thoughts about this? The key is the one Windows creates for all users
> > for file system encryption. However, since I can use it with the Assembla
> > signature classes, I should be able to use it with XMLSignature too,
> > right? Or am I just missing something?
> >
> > The exception stack trace:
> >
> > java.lang.ArrayIndexOutOfBoundsException
> >       at com.sun.rsasign.al.a(DashoA6275)
> >       at com.sun.rsasign.al.b(DashoA6275)
> >       at com.sun.rsasign.al.a(DashoA6275)
> >       at com.sun.rsajca.JSA_RSAKeyFactory.engineTranslateKey(DashoA6275)
> >       at java.security.KeyFactory.translateKey(Unknown Source)
> >       at com.sun.rsajca.JS_Signature.engineInitSign(DashoA6275)
> >       at java.security.Signature$Delegate.engineInitSign(Unknown Source)
> >       at java.security.Signature.initSign(Unknown Source)
> >       at
> > org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.engin
> > eInitSign(SignatureBaseRSA.java:254)  at
> > org.apache.xml.security.algorithms.SignatureAlgorithm.initSign(SignatureA
> > lgorithm.java:296)    at
> > org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:524)
> >       <etc>
> >
> >
> > --
> > Henri Muurimaa
> >

Re: ArrayOutOfBoundsException with RSA key

Posted by Christian Geuer-Pollmann <ge...@nue.et-inf.uni-siegen.de>.
The Exception is not thrown by org.apache.xml.security.something but by 
com.sun.rsasign.something, so I assume that the problem is with your key 
material and SUN's RSA provider.

Do the following to find out: Instantiate a java.security.Signature and 
enforce that the SUN/RSA provider is used. Then sign some stuff with the 
key in question. Then you'll know whether it is in Apache XML-Security or 
not...

Christian

--On Dienstag, 27. Mai 2003 16:55 +0300 Henri Muurimaa 
<he...@itmill.com> wrote:

> Hello,
>
> When I do something like this:
>
>    XMLSignature sig = new
> XMLSignature(srcDocument,"",XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);
>
>    <transform code snipped, should work>
>
>    sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
> 			
>    sig.sign(getPrivateKey());
>
> I get an ArrayOutOfBoundsException at sign(). Stack trace below.
>
> The key I obtain from the windows keystore with the Assembla JCE
> provider, and it should be fine since I can use it to sign other data
> using the Assembla signature classes.
>
> Any thoughts about this? The key is the one Windows creates for all users
> for file system encryption. However, since I can use it with the Assembla
> signature classes, I should be able to use it with XMLSignature too,
> right? Or am I just missing something?
>
> The exception stack trace:
>
> java.lang.ArrayIndexOutOfBoundsException
> 	at com.sun.rsasign.al.a(DashoA6275)
> 	at com.sun.rsasign.al.b(DashoA6275)
> 	at com.sun.rsasign.al.a(DashoA6275)
> 	at com.sun.rsajca.JSA_RSAKeyFactory.engineTranslateKey(DashoA6275)
> 	at java.security.KeyFactory.translateKey(Unknown Source)
> 	at com.sun.rsajca.JS_Signature.engineInitSign(DashoA6275)
> 	at java.security.Signature$Delegate.engineInitSign(Unknown Source)
> 	at java.security.Signature.initSign(Unknown Source)
> 	at
> org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.engin
> eInitSign(SignatureBaseRSA.java:254) 	at
> org.apache.xml.security.algorithms.SignatureAlgorithm.initSign(SignatureA
> lgorithm.java:296) 	at
> org.apache.xml.security.signature.XMLSignature.sign(XMLSignature.java:524)
> 	<etc>
>
>
> --
> Henri Muurimaa
>