D
Daniel
Hi,
I've just run into some really strange behavior with the Sun JVM
(using Java 1.4.2 on Windows). If I have a few threads performing
certain security or JCE operations simultaneously (e.g. generating key
pairs), and if one or more of those threads' state is "interrupted",
then I receive an InterruptedException out of the blue! I'm not sure
if this problem is limited to the JCA/JCE or not.. it doesn't seem to
be cryptography-related to me. The following short program illustrates
the problem:
import java.security.KeyPairGenerator;
public class GenerateKeyTest extends Thread
{
public void run()
{
try
{
interrupt(); // Comment out this line and it works OK
System.out.println("About to generate keys");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
kpg.generateKeyPair();
System.out.println("Keys successfully generated");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
for (int i = 0; i < 5; i++)
new GenerateKeyTest().start();
}
}
It simply generates 5 key pairs "simultaneously" in 5 different
threads. It works fine if the threads are not interrupted, but if you
call interrupt() before doing the operation (as in the above program),
the following exception stack trace results:
java.lang.InterruptedException
at COM.rsa.jsafe.SunJSSE_df.j(DashoA6275)
at COM.rsa.jsafe.SunJSSE_df.c(DashoA6275)
at com.sun.net.ssl.internal.ssl.JS_KeyPairGenerator.generateKeyPair(DashoA6275)
at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:475)
at GenerateKeyTest.run(GenerateKeyTest.java:13)
My two main questions are:
1) Has anyone run into this before, or does anyone have any idea what
can possibly be going on here?
2) Can such behavior even "legally" happen in Java?
InterruptedException is a checked exception (i.e. not a
RuntimeException or an Error) so how can it possibly be thrown and
propogate all the way up to my run() method? If any of the methods in
the stack trace threw an InterruptedException, they would have to
declare it in a "throws" clause, and I would be forced to catch it.
If no one has any further insights, I'll file a bug report. Thanks in
advance for any help,
Daniel
P.S. This happens with other JCE calls as well (e.g. Getting a key
factory while performing asymmetric decryption) and possibly in other
scenarios too. It also occurs when using the Bouncy Castle provider
instead of the SunJCE provider.
I've just run into some really strange behavior with the Sun JVM
(using Java 1.4.2 on Windows). If I have a few threads performing
certain security or JCE operations simultaneously (e.g. generating key
pairs), and if one or more of those threads' state is "interrupted",
then I receive an InterruptedException out of the blue! I'm not sure
if this problem is limited to the JCA/JCE or not.. it doesn't seem to
be cryptography-related to me. The following short program illustrates
the problem:
import java.security.KeyPairGenerator;
public class GenerateKeyTest extends Thread
{
public void run()
{
try
{
interrupt(); // Comment out this line and it works OK
System.out.println("About to generate keys");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
kpg.generateKeyPair();
System.out.println("Keys successfully generated");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
for (int i = 0; i < 5; i++)
new GenerateKeyTest().start();
}
}
It simply generates 5 key pairs "simultaneously" in 5 different
threads. It works fine if the threads are not interrupted, but if you
call interrupt() before doing the operation (as in the above program),
the following exception stack trace results:
java.lang.InterruptedException
at COM.rsa.jsafe.SunJSSE_df.j(DashoA6275)
at COM.rsa.jsafe.SunJSSE_df.c(DashoA6275)
at com.sun.net.ssl.internal.ssl.JS_KeyPairGenerator.generateKeyPair(DashoA6275)
at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:475)
at GenerateKeyTest.run(GenerateKeyTest.java:13)
My two main questions are:
1) Has anyone run into this before, or does anyone have any idea what
can possibly be going on here?
2) Can such behavior even "legally" happen in Java?
InterruptedException is a checked exception (i.e. not a
RuntimeException or an Error) so how can it possibly be thrown and
propogate all the way up to my run() method? If any of the methods in
the stack trace threw an InterruptedException, they would have to
declare it in a "throws" clause, and I would be forced to catch it.
If no one has any further insights, I'll file a bug report. Thanks in
advance for any help,
Daniel
P.S. This happens with other JCE calls as well (e.g. Getting a key
factory while performing asymmetric decryption) and possibly in other
scenarios too. It also occurs when using the Bouncy Castle provider
instead of the SunJCE provider.