Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/smartcardio/TestChannel.java
38840 views
/*1* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 623911726* @summary test logical channels work27* @author Andreas Sterbenz28* @ignore requires special hardware29* @run main/manual TestExclusive30*/3132import javax.smartcardio.Card;33import javax.smartcardio.CardChannel;34import javax.smartcardio.CardTerminal;35import javax.smartcardio.CommandAPDU;3637public class TestChannel extends Utils {3839static final byte[] c1 = parse("00 A4 04 00 07 A0 00 00 00 62 81 01 00");40static 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");41// 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");4243static final byte[] openChannel = parse("00 70 00 00 01");44static final byte[] closeChannel = new byte[] {0x01, 0x70, (byte)0x80, 0};4546public static void main(String[] args) throws Exception {47CardTerminal terminal = getTerminal(args);48if (terminal == null) {49System.out.println("Skipping the test: " +50"no card terminals available");51return;52}5354// establish a connection with the card55Card card = terminal.connect("T=0");56System.out.println("card: " + card);5758CardChannel basicChannel = card.getBasicChannel();5960try {61basicChannel.transmit(new CommandAPDU(openChannel));62} catch (IllegalArgumentException e) {63System.out.println("OK: " + e);64}6566try {67basicChannel.transmit(new CommandAPDU(closeChannel));68} catch (IllegalArgumentException e) {69System.out.println("OK: " + e);70}7172byte[] atr = card.getATR().getBytes();73System.out.println("atr: " + toString(atr));7475// semi-accurate test to see if the card appears to support logical channels76boolean supportsChannels = false;77for (int i = 0; i < atr.length; i++) {78if (atr[i] == 0x73) {79supportsChannels = true;80break;81}82}8384if (supportsChannels == false) {85System.out.println("Card does not support logical channels, skipping...");86} else {87CardChannel channel = card.openLogicalChannel();88System.out.println("channel: " + channel);8990/*91// XXX bug in Oberthur card??92System.out.println("Transmitting...");93transmitTestCommand(channel);94System.out.println("OK");95/**/9697channel.close();98}99100// disconnect101card.disconnect(true);102103System.out.println("OK.");104}105106}107108109