Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/smartcardio/TestExclusive.java
38840 views
1
/*
2
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 6239117
27
* @summary verify that beginExclusive()/endExclusive() works
28
* @author Andreas Sterbenz
29
* @ignore requires special hardware
30
* @run main/manual TestExclusive
31
*/
32
33
import javax.smartcardio.Card;
34
import javax.smartcardio.CardChannel;
35
import javax.smartcardio.CardException;
36
import javax.smartcardio.CardTerminal;
37
import javax.smartcardio.CommandAPDU;
38
39
public class TestExclusive extends Utils {
40
41
static volatile boolean exclusive;
42
43
static volatile boolean otherOK;
44
45
public static void main(String[] args) throws Exception {
46
CardTerminal terminal = getTerminal(args);
47
if (terminal == null) {
48
System.out.println("Skipping the test: " +
49
"no card terminals available");
50
return;
51
}
52
53
// establish a connection with the card
54
Card card = terminal.connect("T=0");
55
System.out.println("card: " + card);
56
57
Thread thread = new Thread(new OtherThread(card));
58
thread.setDaemon(true);
59
thread.start();
60
61
card.beginExclusive();
62
exclusive = true;
63
64
Thread.sleep(1000);
65
System.out.println("=1=resuming...");
66
67
CardChannel channel = card.getBasicChannel();
68
69
System.out.println("=1=Transmitting...");
70
transmitTestCommand(channel);
71
System.out.println("=1=OK");
72
73
try {
74
card.beginExclusive();
75
} catch (CardException e) {
76
System.out.println("=1=OK: " + e);
77
}
78
79
card.endExclusive();
80
81
try {
82
card.endExclusive();
83
} catch (IllegalStateException e) {
84
System.out.println("=1=OK: " + e);
85
}
86
87
exclusive = false;
88
89
Thread.sleep(1000);
90
91
// disconnect
92
card.disconnect(true);
93
94
if (! otherOK) {
95
throw new Exception("Secondary thread failed");
96
}
97
98
System.out.println("=1=OK.");
99
}
100
101
private static class OtherThread implements Runnable {
102
private final Card card;
103
OtherThread(Card card) {
104
this.card = card;
105
}
106
107
public void run() {
108
try {
109
while (exclusive == false) {
110
Thread.sleep(100);
111
}
112
113
System.out.println("=2=trying endexclusive...");
114
try {
115
card.endExclusive();
116
} catch (IllegalStateException e) {
117
System.out.println("=2=OK: " + e);
118
}
119
120
System.out.println("=2=trying beginexclusive...");
121
try {
122
card.beginExclusive();
123
} catch (CardException e) {
124
System.out.println("=2=OK: " + e);
125
}
126
127
System.out.println("=2=trying to transmit...");
128
CardChannel channel = card.getBasicChannel();
129
try {
130
channel.transmit(new CommandAPDU(C1));
131
} catch (CardException e) {
132
System.out.println("=2=OK: " + e);
133
}
134
135
while (exclusive) {
136
Thread.sleep(100);
137
}
138
139
System.out.println("=2=transmitting...");
140
transmitTestCommand(channel);
141
System.out.println("=2=OK...");
142
143
System.out.println("=2=setting ok");
144
otherOK = true;
145
} catch (Exception e) {
146
e.printStackTrace();
147
}
148
}
149
}
150
151
}
152
153