Path: blob/master/test/jdk/sun/security/smartcardio/TestControl.java
41149 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 6239117 6470320 816885126* @summary test if transmitControlCommand() works27* @author Andreas Sterbenz28* @modules java.smartcardio/javax.smartcardio29* @run main/manual TestControl30* @run main/othervm/manual/java.security.policy==test.policy TestControl31*/3233// This test requires special hardware.3435import javax.smartcardio.Card;36import javax.smartcardio.CardException;37import javax.smartcardio.CardTerminal;3839public class TestControl extends Utils {4041private static final int IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = 0x42000000 + 1;4243public static void main(String[] args) throws Exception {44CardTerminal terminal = getTerminal(args);45if (terminal == null) {46System.out.println("Skipping the test: " +47"no card terminals available");48return;49}5051// establish a connection with the card52Card card = terminal.connect("T=0");53System.out.println("card: " + card);5455byte[] data = new byte[] {2};56// byte[] data = new byte[] {6, 0, 10, 1, 1, 16, 0};5758try {59byte[] resp = card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, data);60System.out.println("Firmware: " + toString(resp));61throw new Exception();62} catch (CardException e) {63// we currently don't know of any control commands that work with64// our readers. call the function just to make sure we don't crash65// or throw the wrong exception66System.out.println("OK: " + e);67e.printStackTrace(System.out);68}69try {70card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, null);71} catch (NullPointerException e) {72System.out.println("OK: " + e);73}7475// disconnect76card.disconnect(true);7778System.out.println("OK.");79}8081}828384