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/TestControl.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 6470320
27
* @summary test if transmitControlCommand() works
28
* @author Andreas Sterbenz
29
* @ignore requires special hardware
30
* @run main/manual TestControl
31
*/
32
33
import javax.smartcardio.Card;
34
import javax.smartcardio.CardException;
35
import javax.smartcardio.CardTerminal;
36
37
public class TestControl extends Utils {
38
39
private static final int IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = 0x42000000 + 1;
40
41
public static void main(String[] args) throws Exception {
42
CardTerminal terminal = getTerminal(args);
43
if (terminal == null) {
44
System.out.println("Skipping the test: " +
45
"no card terminals available");
46
return;
47
}
48
49
// establish a connection with the card
50
Card card = terminal.connect("T=0");
51
System.out.println("card: " + card);
52
53
byte[] data = new byte[] {2};
54
// byte[] data = new byte[] {6, 0, 10, 1, 1, 16, 0};
55
56
try {
57
byte[] resp = card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, data);
58
System.out.println("Firmware: " + toString(resp));
59
throw new Exception();
60
} catch (CardException e) {
61
// we currently don't know of any control commands that work with
62
// our readers. call the function just to make sure we don't crash
63
// or throw the wrong exception
64
System.out.println("OK: " + e);
65
e.printStackTrace(System.out);
66
}
67
try {
68
card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, null);
69
} catch (NullPointerException e) {
70
System.out.println("OK: " + e);
71
}
72
73
// disconnect
74
card.disconnect(true);
75
76
System.out.println("OK.");
77
}
78
79
}
80
81