author | igerasim |
Fri, 18 Jul 2014 17:04:10 +0400 | |
changeset 25656 | 676435b3c625 |
parent 23357 | 7225e28e91dd |
child 35778 | e2a3c03097de |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23357
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2005, 2014, 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 |
|
23357
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
29 |
* @run main/manual TestChannel |
2 | 30 |
*/ |
31 |
||
23357
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
32 |
// This test requires special hardware. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
33 |
|
25656
676435b3c625
8050893: (smartcardio) Invert reset argument in tests in sun/security/smartcardio
igerasim
parents:
23357
diff
changeset
|
34 |
import javax.smartcardio.Card; |
676435b3c625
8050893: (smartcardio) Invert reset argument in tests in sun/security/smartcardio
igerasim
parents:
23357
diff
changeset
|
35 |
import javax.smartcardio.CardChannel; |
676435b3c625
8050893: (smartcardio) Invert reset argument in tests in sun/security/smartcardio
igerasim
parents:
23357
diff
changeset
|
36 |
import javax.smartcardio.CardTerminal; |
676435b3c625
8050893: (smartcardio) Invert reset argument in tests in sun/security/smartcardio
igerasim
parents:
23357
diff
changeset
|
37 |
import javax.smartcardio.CommandAPDU; |
2 | 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(); |
|
70 |
System.out.println("atr: " + toString(atr)); |
|
71 |
||
72 |
// semi-accurate test to see if the card appears to support logical channels |
|
73 |
boolean supportsChannels = false; |
|
74 |
for (int i = 0; i < atr.length; i++) { |
|
75 |
if (atr[i] == 0x73) { |
|
76 |
supportsChannels = true; |
|
77 |
break; |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
if (supportsChannels == false) { |
|
82 |
System.out.println("Card does not support logical channels, skipping..."); |
|
83 |
} else { |
|
84 |
CardChannel channel = card.openLogicalChannel(); |
|
85 |
System.out.println("channel: " + channel); |
|
86 |
||
87 |
/* |
|
88 |
// XXX bug in Oberthur card?? |
|
89 |
System.out.println("Transmitting..."); |
|
90 |
transmitTestCommand(channel); |
|
91 |
System.out.println("OK"); |
|
92 |
/**/ |
|
93 |
||
94 |
channel.close(); |
|
95 |
} |
|
96 |
||
97 |
// disconnect |
|
25656
676435b3c625
8050893: (smartcardio) Invert reset argument in tests in sun/security/smartcardio
igerasim
parents:
23357
diff
changeset
|
98 |
card.disconnect(true); |
2 | 99 |
|
100 |
System.out.println("OK."); |
|
101 |
} |
|
102 |
||
103 |
} |