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/TestChannel.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 test logical channels work
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.CardTerminal;
36
import javax.smartcardio.CommandAPDU;
37
38
public class TestChannel extends Utils {
39
40
static final byte[] c1 = parse("00 A4 04 00 07 A0 00 00 00 62 81 01 00");
41
static final byte[] r1 = parse("07:a0:00:00:00:62:81:01:04:01:00:00:24:05:00:0b:04:b0:55:90:00");
42
// static final byte[] r1 = parse("07 A0 00 00 00 62 81 01 04 01 00 00 24 05 00 0B 04 B0 25 90 00");
43
44
static final byte[] openChannel = parse("00 70 00 00 01");
45
static final byte[] closeChannel = new byte[] {0x01, 0x70, (byte)0x80, 0};
46
47
public static void main(String[] args) throws Exception {
48
CardTerminal terminal = getTerminal(args);
49
if (terminal == null) {
50
System.out.println("Skipping the test: " +
51
"no card terminals available");
52
return;
53
}
54
55
// establish a connection with the card
56
Card card = terminal.connect("T=0");
57
System.out.println("card: " + card);
58
59
CardChannel basicChannel = card.getBasicChannel();
60
61
try {
62
basicChannel.transmit(new CommandAPDU(openChannel));
63
} catch (IllegalArgumentException e) {
64
System.out.println("OK: " + e);
65
}
66
67
try {
68
basicChannel.transmit(new CommandAPDU(closeChannel));
69
} catch (IllegalArgumentException e) {
70
System.out.println("OK: " + e);
71
}
72
73
byte[] atr = card.getATR().getBytes();
74
System.out.println("atr: " + toString(atr));
75
76
// semi-accurate test to see if the card appears to support logical channels
77
boolean supportsChannels = false;
78
for (int i = 0; i < atr.length; i++) {
79
if (atr[i] == 0x73) {
80
supportsChannels = true;
81
break;
82
}
83
}
84
85
if (supportsChannels == false) {
86
System.out.println("Card does not support logical channels, skipping...");
87
} else {
88
CardChannel channel = card.openLogicalChannel();
89
System.out.println("channel: " + channel);
90
91
/*
92
// XXX bug in Oberthur card??
93
System.out.println("Transmitting...");
94
transmitTestCommand(channel);
95
System.out.println("OK");
96
/**/
97
98
channel.close();
99
}
100
101
// disconnect
102
card.disconnect(true);
103
104
System.out.println("OK.");
105
}
106
107
}
108
109