< prev index next >

test/sun/security/smartcardio/TestChannel.java

Print this page
rev 13550 : imported patch 8059212-Modify-smartcardio-manual-regression-tests-so-that-they-do-not-just-fail-if-no-cardreader-found
   1 /*
   2  * Copyright (c) 2005, 2014, 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  */


  30  */
  31 
  32 // This test requires special hardware.
  33 
  34 import javax.smartcardio.Card;
  35 import javax.smartcardio.CardChannel;
  36 import javax.smartcardio.CardTerminal;
  37 import javax.smartcardio.CommandAPDU;
  38 
  39 public class TestChannel extends Utils {
  40 
  41     static final byte[] c1 = parse("00 A4 04 00 07 A0 00 00 00 62 81 01 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:55:90:00");
  43 //    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");
  44 
  45     static final byte[] openChannel = parse("00 70 00 00 01");
  46     static final byte[] closeChannel = new byte[] {0x01, 0x70, (byte)0x80, 0};
  47 
  48     public static void main(String[] args) throws Exception {
  49         CardTerminal terminal = getTerminal(args);





  50 
  51         // establish a connection with the card
  52         Card card = terminal.connect("T=0");
  53         System.out.println("card: " + card);
  54 
  55         CardChannel basicChannel = card.getBasicChannel();
  56 
  57         try {
  58             basicChannel.transmit(new CommandAPDU(openChannel));
  59         } catch (IllegalArgumentException e) {
  60             System.out.println("OK: " + e);
  61         }
  62 
  63         try {
  64             basicChannel.transmit(new CommandAPDU(closeChannel));
  65         } catch (IllegalArgumentException e) {
  66             System.out.println("OK: " + e);
  67         }
  68 
  69         byte[] atr = card.getATR().getBytes();


   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  */


  30  */
  31 
  32 // This test requires special hardware.
  33 
  34 import javax.smartcardio.Card;
  35 import javax.smartcardio.CardChannel;
  36 import javax.smartcardio.CardTerminal;
  37 import javax.smartcardio.CommandAPDU;
  38 
  39 public class TestChannel extends Utils {
  40 
  41     static final byte[] c1 = parse("00 A4 04 00 07 A0 00 00 00 62 81 01 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:55:90:00");
  43 //    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");
  44 
  45     static final byte[] openChannel = parse("00 70 00 00 01");
  46     static final byte[] closeChannel = new byte[] {0x01, 0x70, (byte)0x80, 0};
  47 
  48     public static void main(String[] args) throws Exception {
  49         CardTerminal terminal = getTerminal(args);
  50         if (terminal == null) {
  51             System.out.println("Skipping the test: " +
  52                     "no card terminals available");
  53             return;
  54         }
  55 
  56         // establish a connection with the card
  57         Card card = terminal.connect("T=0");
  58         System.out.println("card: " + card);
  59 
  60         CardChannel basicChannel = card.getBasicChannel();
  61 
  62         try {
  63             basicChannel.transmit(new CommandAPDU(openChannel));
  64         } catch (IllegalArgumentException e) {
  65             System.out.println("OK: " + e);
  66         }
  67 
  68         try {
  69             basicChannel.transmit(new CommandAPDU(closeChannel));
  70         } catch (IllegalArgumentException e) {
  71             System.out.println("OK: " + e);
  72         }
  73 
  74         byte[] atr = card.getATR().getBytes();


< prev index next >