Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/smartcardio/TestControl.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 6239117 647032026* @summary test if transmitControlCommand() works27* @author Andreas Sterbenz28* @ignore requires special hardware29* @run main/manual TestControl30*/3132import javax.smartcardio.Card;33import javax.smartcardio.CardException;34import javax.smartcardio.CardTerminal;3536public class TestControl extends Utils {3738private static final int IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = 0x42000000 + 1;3940public static void main(String[] args) throws Exception {41CardTerminal terminal = getTerminal(args);42if (terminal == null) {43System.out.println("Skipping the test: " +44"no card terminals available");45return;46}4748// establish a connection with the card49Card card = terminal.connect("T=0");50System.out.println("card: " + card);5152byte[] data = new byte[] {2};53// byte[] data = new byte[] {6, 0, 10, 1, 1, 16, 0};5455try {56byte[] resp = card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, data);57System.out.println("Firmware: " + toString(resp));58throw new Exception();59} catch (CardException e) {60// we currently don't know of any control commands that work with61// our readers. call the function just to make sure we don't crash62// or throw the wrong exception63System.out.println("OK: " + e);64e.printStackTrace(System.out);65}66try {67card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, null);68} catch (NullPointerException e) {69System.out.println("OK: " + e);70}7172// disconnect73card.disconnect(true);7475System.out.println("OK.");76}7778}798081