2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
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 java.io.*;
|
|
34 |
import java.util.*;
|
|
35 |
|
|
36 |
import javax.smartcardio.*;
|
|
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 |
|
|
50 |
// establish a connection with the card
|
|
51 |
Card card = terminal.connect("T=0");
|
|
52 |
System.out.println("card: " + card);
|
|
53 |
|
|
54 |
CardChannel basicChannel = card.getBasicChannel();
|
|
55 |
|
|
56 |
try {
|
|
57 |
basicChannel.transmit(new CommandAPDU(openChannel));
|
|
58 |
} catch (IllegalArgumentException e) {
|
|
59 |
System.out.println("OK: " + e);
|
|
60 |
}
|
|
61 |
|
|
62 |
try {
|
|
63 |
basicChannel.transmit(new CommandAPDU(closeChannel));
|
|
64 |
} catch (IllegalArgumentException e) {
|
|
65 |
System.out.println("OK: " + e);
|
|
66 |
}
|
|
67 |
|
|
68 |
byte[] atr = card.getATR().getBytes();
|
|
69 |
System.out.println("atr: " + toString(atr));
|
|
70 |
|
|
71 |
// semi-accurate test to see if the card appears to support logical channels
|
|
72 |
boolean supportsChannels = false;
|
|
73 |
for (int i = 0; i < atr.length; i++) {
|
|
74 |
if (atr[i] == 0x73) {
|
|
75 |
supportsChannels = true;
|
|
76 |
break;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
if (supportsChannels == false) {
|
|
81 |
System.out.println("Card does not support logical channels, skipping...");
|
|
82 |
} else {
|
|
83 |
CardChannel channel = card.openLogicalChannel();
|
|
84 |
System.out.println("channel: " + channel);
|
|
85 |
|
|
86 |
/*
|
|
87 |
// XXX bug in Oberthur card??
|
|
88 |
System.out.println("Transmitting...");
|
|
89 |
transmitTestCommand(channel);
|
|
90 |
System.out.println("OK");
|
|
91 |
/**/
|
|
92 |
|
|
93 |
channel.close();
|
|
94 |
}
|
|
95 |
|
|
96 |
// disconnect
|
|
97 |
card.disconnect(false);
|
|
98 |
|
|
99 |
System.out.println("OK.");
|
|
100 |
}
|
|
101 |
|
|
102 |
}
|