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/TestConnect.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 6293769 6294527 6309280
27
* @summary test connect() works
28
* @author Andreas Sterbenz
29
* @ignore requires special hardware
30
* @run main/manual TestConnect
31
*/
32
33
import java.util.List;
34
import javax.smartcardio.TerminalFactory;
35
import javax.smartcardio.Card;
36
import javax.smartcardio.CardChannel;
37
import javax.smartcardio.CardTerminal;
38
39
public class TestConnect extends Utils {
40
41
public static void main(String[] args) throws Exception {
42
CardTerminal terminal = getTerminal(args, "SunPCSC");
43
if (terminal == null) {
44
System.out.println("Skipping the test: " +
45
"no card terminals available");
46
return;
47
}
48
49
Card card = terminal.connect("*");
50
System.out.println("card: " + card);
51
if (card.getProtocol().equals("T=0") == false) {
52
throw new Exception("Not T=0 protocol");
53
}
54
transmit(card);
55
card.disconnect(true);
56
57
try {
58
transmit(card);
59
throw new Exception("transmitted to disconnected card");
60
} catch (IllegalStateException e) {
61
System.out.println("OK: " + e);
62
}
63
64
/* ignore: Solaris bug
65
try {
66
card = terminal.connect("T=1");
67
System.out.println(card);
68
throw new Exception("connected via T=1");
69
} catch (CardException e) {
70
System.out.println("OK: " + e);
71
}
72
*/
73
74
try {
75
card = terminal.connect("T=Foo");
76
System.out.println(card);
77
throw new Exception("connected via T=Foo");
78
} catch (IllegalArgumentException e) {
79
System.out.println("OK: " + e);
80
}
81
82
card = terminal.connect("T=0");
83
System.out.println(card);
84
if (card.getProtocol().equals("T=0") == false) {
85
throw new Exception("Not T=0 protocol");
86
}
87
transmit(card);
88
card.disconnect(false);
89
90
card = terminal.connect("*");
91
System.out.println("card: " + card);
92
if (card.getProtocol().equals("T=0") == false) {
93
throw new Exception("Not T=0 protocol");
94
}
95
transmit(card);
96
card.disconnect(true);
97
98
System.out.println("OK.");
99
}
100
101
private static void transmit(Card card) throws Exception {
102
CardChannel channel = card.getBasicChannel();
103
System.out.println("Transmitting...");
104
transmitTestCommand(channel);
105
}
106
107
}
108
109