Commit cf1a6d7c authored by Guillaume Ballet's avatar Guillaume Ballet Committed by Péter Szilágyi

vendor: upgrade go-libpcsclite (#19420)

* vendor: remove leftover trace

* Upgrade go-libpcsclite to the latest version
parent 33d28f37
......@@ -6,18 +6,38 @@ A golang implementation of the [libpcpsclite](http://github.com/LudovicRousseau/
The goal is for major open source projects to distribute a single binary that doesn't depend on `libpcsclite`. It provides an extra function `CheckPCSCDaemon` that will tell the user if `pcscd` is running.
## Building
## Example
TODO
```golang
func main() {
client, err := EstablishContext(2)
if err != nil {
fmt.Printf("Error establishing context: %v\n", err)
os.Exit(1)
}
## Example
_, err = client.ListReaders()
if err != nil {
fmt.Printf("Error getting the list of readers: %v\n", err)
os.Exit(1)
}
card, err := client.Connect(client.readerStateDescriptors[0].Name, ShareShared, ProtocolT0|ProtocolT1)
if err != nil {
fmt.Printf("Error connecting: %v\n", err)
os.Exit(1)
}
resp, _, err := card.Transmit([]byte{0, 0xa4, 4, 0, 0xA0, 0, 0, 8, 4, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0})
TODO
card.Disconnect(LeaveCard)
}
```
## TODO
- [ ] Finish this README
- [ ] Lock context
- [x] Finish this README
- [x] Lock context
- [ ] implement missing functions
## License
......@@ -50,4 +70,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
......@@ -31,8 +31,6 @@
package pcsc
const (
SCardSuccess = 0x00000000 /* No error was encountered. */
AutoAllocate = -1 /* see SCardFreeMemory() */
ScopeUser = 0x0000 /* Scope in user space */
ScopeTerminal = 0x0001 /* Scope in terminal */
......@@ -94,6 +92,6 @@ const (
// Protocol information
const (
ProtocolVersionMajor = 4 /* IPC major */
ProtocolVersionMinor = 3 /* IPC minor */
ProtocolVersionMajor = uint32(4) /* IPC major */
ProtocolVersionMinor = uint32(3) /* IPC minor */
)
This diff is collapsed.
......@@ -65,43 +65,56 @@ func EstablishContext(scope uint32) (*Client, error) {
}
client.conn = conn
/* Exchange version information */
payload := make([]byte, 12)
binary.LittleEndian.PutUint32(payload, ProtocolVersionMajor)
binary.LittleEndian.PutUint32(payload[4:], ProtocolVersionMinor)
binary.LittleEndian.PutUint32(payload[8:], SCardSuccess)
err = messageSendWithHeader(CommandVersion, conn, payload)
if err != nil {
return nil, err
}
response := make([]byte, 12)
n, err := conn.Read(response)
if err != nil {
return nil, err
}
if n != len(response) {
return nil, fmt.Errorf("invalid response length: expected %d, got %d", len(response), n)
var code uint32
var minor uint32
for minor = ProtocolVersionMinor; minor <= ProtocolVersionMinor+1; minor++ {
/* Exchange version information */
binary.LittleEndian.PutUint32(payload, ProtocolVersionMajor)
binary.LittleEndian.PutUint32(payload[4:], minor)
binary.LittleEndian.PutUint32(payload[8:], SCardSuccess.Code())
err = messageSendWithHeader(CommandVersion, conn, payload)
if err != nil {
return nil, err
}
n, err := conn.Read(response)
if err != nil {
return nil, err
}
if n != len(response) {
return nil, fmt.Errorf("invalid response length: expected %d, got %d", len(response), n)
}
code = binary.LittleEndian.Uint32(response[8:])
if code != SCardSuccess.Code() {
continue
}
client.major = binary.LittleEndian.Uint32(response)
client.minor = binary.LittleEndian.Uint32(response[4:])
if client.major != ProtocolVersionMajor || client.minor != minor {
continue
}
break
}
code := binary.LittleEndian.Uint32(response[8:])
if code != SCardSuccess {
return nil, fmt.Errorf("invalid response code: expected %d, got %d", SCardSuccess, code)
if code != SCardSuccess.Code() {
return nil, fmt.Errorf("invalid response code: expected %d, got %d (%v)", SCardSuccess, code, ErrorCode(code).Error())
}
client.major = binary.LittleEndian.Uint32(response)
client.minor = binary.LittleEndian.Uint32(response[4:])
if client.major != ProtocolVersionMajor || client.minor != ProtocolVersionMinor {
if client.major != ProtocolVersionMajor || (client.minor != minor && client.minor+1 != minor) {
return nil, fmt.Errorf("invalid version found: expected %d.%d, got %d.%d", ProtocolVersionMajor, ProtocolVersionMinor, client.major, client.minor)
}
/* Establish the context proper */
binary.LittleEndian.PutUint32(payload, scope)
binary.LittleEndian.PutUint32(payload[4:], 0)
binary.LittleEndian.PutUint32(payload[8:], SCardSuccess)
binary.LittleEndian.PutUint32(payload[8:], SCardSuccess.Code())
err = messageSendWithHeader(SCardEstablishContext, conn, payload)
if err != nil {
return nil, err
}
response = make([]byte, 12)
n, err = conn.Read(response)
n, err := conn.Read(response)
if err != nil {
return nil, err
}
......@@ -109,8 +122,8 @@ func EstablishContext(scope uint32) (*Client, error) {
return nil, fmt.Errorf("invalid response length: expected %d, got %d", len(response), n)
}
code = binary.LittleEndian.Uint32(response[8:])
if code != SCardSuccess {
return nil, fmt.Errorf("invalid response code: expected %d, got %d", SCardSuccess, code)
if code != SCardSuccess.Code() {
return nil, fmt.Errorf("invalid response code: expected %d, got %d (%v)", SCardSuccess, code, ErrorCode(code).Error())
}
client.ctx = binary.LittleEndian.Uint32(response[4:])
......@@ -125,7 +138,7 @@ func (client *Client) ReleaseContext() error {
data := [8]byte{}
binary.LittleEndian.PutUint32(data[:], client.ctx)
binary.LittleEndian.PutUint32(data[4:], SCardSuccess)
binary.LittleEndian.PutUint32(data[4:], SCardSuccess.Code())
err := messageSendWithHeader(SCardReleaseContext, client.conn, data[:])
if err != nil {
return err
......@@ -139,8 +152,8 @@ func (client *Client) ReleaseContext() error {
total += n
}
code := binary.LittleEndian.Uint32(data[4:])
if code != SCardSuccess {
return fmt.Errorf("invalid return code: %x", code)
if code != SCardSuccess.Code() {
return fmt.Errorf("invalid return code: %x, %v", code, ErrorCode(code).Error())
}
return nil
......@@ -247,7 +260,7 @@ func (client *Client) Connect(name string, shareMode uint32, preferredProtocol u
copy(request[SCardConnectReaderNameOffset:], []byte(name))
binary.LittleEndian.PutUint32(request[SCardConnectShareModeOffset:], shareMode)
binary.LittleEndian.PutUint32(request[SCardConnectPreferredProtocolOffset:], preferredProtocol)
binary.LittleEndian.PutUint32(request[SCardConnectReturnValueOffset:], SCardSuccess)
binary.LittleEndian.PutUint32(request[SCardConnectReturnValueOffset:], SCardSuccess.Code())
err := messageSendWithHeader(SCardConnect, client.conn, request)
if err != nil {
......@@ -260,12 +273,12 @@ func (client *Client) Connect(name string, shareMode uint32, preferredProtocol u
if err != nil {
return nil, err
}
fmt.Println("total, n", total, n, response)
// fmt.Println("total, n", total, n, response)
total += n
}
code := binary.LittleEndian.Uint32(response[148:])
if code != SCardSuccess {
return nil, fmt.Errorf("invalid return code: %x", code)
if code != SCardSuccess.Code() {
return nil, fmt.Errorf("invalid return code: %x (%v)", code, ErrorCode(code).Error())
}
handle := binary.LittleEndian.Uint32(response[140:])
active := binary.LittleEndian.Uint32(response[SCardConnectPreferredProtocolOffset:])
......@@ -312,7 +325,7 @@ func (card *Card) Transmit(adpu []byte) ([]byte, *SCardIoRequest, error) {
binary.LittleEndian.PutUint32(request[16:], 0)
binary.LittleEndian.PutUint32(request[20:], 0)
binary.LittleEndian.PutUint32(request[24:], 0x10000)
binary.LittleEndian.PutUint32(request[28:], SCardSuccess)
binary.LittleEndian.PutUint32(request[28:], SCardSuccess.Code())
err := messageSendWithHeader(SCardTransmit, card.client.conn, request[:])
if err != nil {
return nil, nil, err
......@@ -336,8 +349,8 @@ func (card *Card) Transmit(adpu []byte) ([]byte, *SCardIoRequest, error) {
}
code := binary.LittleEndian.Uint32(response[28:])
if code != SCardSuccess {
return nil, nil, fmt.Errorf("invalid return code: %x", code)
if code != SCardSuccess.Code() {
return nil, nil, fmt.Errorf("invalid return code: %x (%v)", code, ErrorCode(code).Error())
}
// Recover the response data
......@@ -367,7 +380,7 @@ func (card *Card) Disconnect(disposition uint32) error {
data := [12]byte{}
binary.LittleEndian.PutUint32(data[:], card.handle)
binary.LittleEndian.PutUint32(data[4:], disposition)
binary.LittleEndian.PutUint32(data[8:], SCardSuccess)
binary.LittleEndian.PutUint32(data[8:], SCardSuccess.Code())
err := messageSendWithHeader(SCardDisConnect, card.client.conn, data[:])
if err != nil {
return err
......@@ -381,8 +394,8 @@ func (card *Card) Disconnect(disposition uint32) error {
total += n
}
code := binary.LittleEndian.Uint32(data[8:])
if code != SCardSuccess {
return fmt.Errorf("invalid return code: %x", code)
if code != SCardSuccess.Code() {
return fmt.Errorf("invalid return code: %x (%v)", code, ErrorCode(code).Error())
}
return nil
......
......@@ -140,10 +140,10 @@
"revisionTime": "2018-04-18T12:24:29Z"
},
{
"checksumSHA1": "GnNfMrYs/4m+HCtDBF7HpPUFFVw=",
"checksumSHA1": "GXqHzd0XkPLX/iulpOncaxbxzZo=",
"path": "github.com/gballet/go-libpcsclite",
"revision": "95b81846253cd854b8bb8f2fd9cc6056d0681ac4",
"revisionTime": "2019-03-13T11:40:44Z"
"revision": "312b5175032f98274685a4dd81935a92ad2412a5",
"revisionTime": "2019-04-03T18:15:18Z"
},
{
"checksumSHA1": "gxV/cPPLkByTdY8y172t7v4qcZA=",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment