Skip to content

Commit ef642c8

Browse files
committed
Added reprodcuer for race condition in nssadapter in fips
1 parent d9a75d2 commit ef642c8

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* @test
2+
@bug 6664545
3+
@summary nssadapter should not use a single PKCS #11 session for multi-thread operations
4+
@run shell Main.sh
5+
*/
6+
import javax.crypto.Cipher;
7+
import javax.crypto.KeyGenerator;
8+
import javax.crypto.spec.SecretKeySpec;
9+
import java.util.concurrent.ExecutorService;
10+
import java.util.concurrent.Executors;
11+
12+
public final class Main {
13+
private static final int PARALLELISM = 10;
14+
private static final String ALGORITHM = "AES";
15+
private static final SecretKeySpec KEY_SPEC = new SecretKeySpec(
16+
"12345678901234567890123456789012".getBytes(), ALGORITHM);
17+
18+
private static void importSecretKey() {
19+
try {
20+
Cipher c = Cipher.getInstance(ALGORITHM);
21+
c.init(Cipher.ENCRYPT_MODE, KEY_SPEC);
22+
} catch (Throwable t) {
23+
t.printStackTrace();
24+
System.exit(1);
25+
}
26+
}
27+
28+
private static void exportSecretKey() {
29+
try {
30+
KeyGenerator kg = KeyGenerator.getInstance(ALGORITHM);
31+
kg.generateKey().getEncoded();
32+
} catch (Throwable t) {
33+
t.printStackTrace();
34+
System.exit(1);
35+
}
36+
}
37+
38+
public static void main(String[] args) {
39+
try (ExecutorService pool = Executors.newFixedThreadPool(PARALLELISM)) {
40+
for (int t = 0; t < PARALLELISM * 100; t++) {
41+
pool.submit(Main::importSecretKey);
42+
pool.submit(Main::exportSecretKey);
43+
}
44+
}
45+
}
46+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set -exuo pipefail
2+
echo $PWD
3+
ls
4+
5+
FS="/"
6+
JAVAC=${TESTJAVA}${FS}bin${FS}javac
7+
JAVA=${TESTJAVA}${FS}bin${FS}java
8+
9+
$JAVAC -d . $TESTSRC/Main.java
10+
for x in `seq 10` ; do
11+
$JAVA Main
12+
done
13+
14+

0 commit comments

Comments
 (0)