author | wetmore |
Tue, 18 Mar 2014 15:04:59 -0700 | |
changeset 23357 | 7225e28e91dd |
parent 5506 | 202f599c92aa |
child 25656 | 676435b3c625 |
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 6293769 6294527 6309280 |
|
27 |
* @summary test connect() works |
|
28 |
* @author Andreas Sterbenz |
|
29 |
* @run main/manual TestConnect |
|
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 |
|
2 | 34 |
import java.io.*; |
35 |
import java.util.*; |
|
36 |
||
37 |
import javax.smartcardio.*; |
|
38 |
||
39 |
public class TestConnect extends Utils { |
|
40 |
||
41 |
public static void main(String[] args) throws Exception { |
|
42 |
TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null, "SunPCSC"); |
|
43 |
System.out.println(factory); |
|
44 |
||
45 |
List<CardTerminal> terminals = factory.terminals().list(); |
|
46 |
System.out.println("Terminals: " + terminals); |
|
47 |
if (terminals.isEmpty()) { |
|
48 |
throw new Exception("No card terminals available"); |
|
49 |
} |
|
50 |
CardTerminal terminal = terminals.get(0); |
|
51 |
||
52 |
if (terminal.isCardPresent() == false) { |
|
53 |
System.out.println("*** Insert card"); |
|
54 |
if (terminal.waitForCardPresent(20 * 1000) == false) { |
|
55 |
throw new Exception("no card available"); |
|
56 |
} |
|
57 |
} |
|
58 |
System.out.println("card present: " + terminal.isCardPresent()); |
|
59 |
||
60 |
Card card = terminal.connect("*"); |
|
61 |
System.out.println("card: " + card); |
|
62 |
if (card.getProtocol().equals("T=0") == false) { |
|
63 |
throw new Exception("Not T=0 protocol"); |
|
64 |
} |
|
65 |
transmit(card); |
|
66 |
card.disconnect(false); |
|
67 |
||
68 |
try { |
|
69 |
transmit(card); |
|
70 |
throw new Exception("transmitted to disconnected card"); |
|
71 |
} catch (IllegalStateException e) { |
|
72 |
System.out.println("OK: " + e); |
|
73 |
} |
|
74 |
||
75 |
/* ignore: Solaris bug |
|
76 |
try { |
|
77 |
card = terminal.connect("T=1"); |
|
78 |
System.out.println(card); |
|
79 |
throw new Exception("connected via T=1"); |
|
80 |
} catch (CardException e) { |
|
81 |
System.out.println("OK: " + e); |
|
82 |
} |
|
83 |
*/ |
|
84 |
||
85 |
try { |
|
86 |
card = terminal.connect("T=Foo"); |
|
87 |
System.out.println(card); |
|
88 |
throw new Exception("connected via T=Foo"); |
|
89 |
} catch (IllegalArgumentException e) { |
|
90 |
System.out.println("OK: " + e); |
|
91 |
} |
|
92 |
||
93 |
card = terminal.connect("T=0"); |
|
94 |
System.out.println(card); |
|
95 |
if (card.getProtocol().equals("T=0") == false) { |
|
96 |
throw new Exception("Not T=0 protocol"); |
|
97 |
} |
|
98 |
transmit(card); |
|
99 |
card.disconnect(true); |
|
100 |
||
101 |
card = terminal.connect("*"); |
|
102 |
System.out.println("card: " + card); |
|
103 |
if (card.getProtocol().equals("T=0") == false) { |
|
104 |
throw new Exception("Not T=0 protocol"); |
|
105 |
} |
|
106 |
transmit(card); |
|
107 |
card.disconnect(true); |
|
108 |
card.disconnect(true); |
|
109 |
||
110 |
System.out.println("OK."); |
|
111 |
} |
|
112 |
||
113 |
private static void transmit(Card card) throws Exception { |
|
114 |
CardChannel channel = card.getBasicChannel(); |
|
115 |
System.out.println("Transmitting..."); |
|
116 |
transmitTestCommand(channel); |
|
117 |
} |
|
118 |
||
119 |
} |