equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package sun.security.smartcardio; |
26 package sun.security.smartcardio; |
27 |
27 |
28 import java.nio.ByteBuffer; |
28 import java.nio.ByteBuffer; |
29 |
29 import java.security.AccessController; |
|
30 import java.security.PrivilegedAction; |
30 import javax.smartcardio.*; |
31 import javax.smartcardio.*; |
31 |
|
32 import static sun.security.smartcardio.PCSC.*; |
32 import static sun.security.smartcardio.PCSC.*; |
33 |
33 |
34 /** |
34 /** |
35 * Card implementation. |
35 * Card implementation. |
36 * |
36 * |
59 // state of this card connection |
59 // state of this card connection |
60 private volatile State state; |
60 private volatile State state; |
61 |
61 |
62 // thread holding exclusive access to the card, or null |
62 // thread holding exclusive access to the card, or null |
63 private volatile Thread exclusiveThread; |
63 private volatile Thread exclusiveThread; |
|
64 |
|
65 // used for platform specific logic |
|
66 private static final boolean isWindows; |
|
67 |
|
68 static { |
|
69 final String osName = AccessController.doPrivileged( |
|
70 (PrivilegedAction<String>) () -> System.getProperty("os.name")); |
|
71 isWindows = osName.startsWith("Windows"); |
|
72 } |
64 |
73 |
65 CardImpl(TerminalImpl terminal, String protocol) throws PCSCException { |
74 CardImpl(TerminalImpl terminal, String protocol) throws PCSCException { |
66 this.terminal = terminal; |
75 this.terminal = terminal; |
67 int sharingMode = SCARD_SHARE_SHARED; |
76 int sharingMode = SCARD_SHARE_SHARED; |
68 int connectProtocol; |
77 int connectProtocol; |
72 connectProtocol = SCARD_PROTOCOL_T0; |
81 connectProtocol = SCARD_PROTOCOL_T0; |
73 } else if (protocol.equalsIgnoreCase("T=1")) { |
82 } else if (protocol.equalsIgnoreCase("T=1")) { |
74 connectProtocol = SCARD_PROTOCOL_T1; |
83 connectProtocol = SCARD_PROTOCOL_T1; |
75 } else if (protocol.equalsIgnoreCase("direct")) { |
84 } else if (protocol.equalsIgnoreCase("direct")) { |
76 // testing |
85 // testing |
77 connectProtocol = 0; |
86 |
|
87 // MSDN states that the preferred protocol can be zero, but doesn't |
|
88 // specify whether other values are allowed. |
|
89 // pcsc-lite implementation expects the preferred protocol to be non zero. |
|
90 connectProtocol = isWindows ? 0 : SCARD_PROTOCOL_RAW; |
|
91 |
78 sharingMode = SCARD_SHARE_DIRECT; |
92 sharingMode = SCARD_SHARE_DIRECT; |
79 } else { |
93 } else { |
80 throw new IllegalArgumentException("Unsupported protocol " + protocol); |
94 throw new IllegalArgumentException("Unsupported protocol " + protocol); |
81 } |
95 } |
82 cardId = SCardConnect(terminal.contextId, terminal.name, |
96 cardId = SCardConnect(terminal.contextId, terminal.name, |