aboutsummaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorGuillaume Ballet <gballet@gmail.com>2019-03-23 02:51:05 +0800
committerGuillaume Ballet <gballet@gmail.com>2019-04-08 19:21:22 +0800
commit2625057fe35cd3c72aa749e36a7f6d33d6dc072c (patch)
treec4cc53923c7a76c8a9ff585b6c075661113763c5 /vendor
parent189a0329876329f1d67969a2657ec4b1776fbb24 (diff)
downloadgo-tangerine-2625057fe35cd3c72aa749e36a7f6d33d6dc072c.tar
go-tangerine-2625057fe35cd3c72aa749e36a7f6d33d6dc072c.tar.gz
go-tangerine-2625057fe35cd3c72aa749e36a7f6d33d6dc072c.tar.bz2
go-tangerine-2625057fe35cd3c72aa749e36a7f6d33d6dc072c.tar.lz
go-tangerine-2625057fe35cd3c72aa749e36a7f6d33d6dc072c.tar.xz
go-tangerine-2625057fe35cd3c72aa749e36a7f6d33d6dc072c.tar.zst
go-tangerine-2625057fe35cd3c72aa749e36a7f6d33d6dc072c.zip
Achieve full transaction signature+sending
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/gballet/go-libpcsclite/winscard.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/vendor/github.com/gballet/go-libpcsclite/winscard.go b/vendor/github.com/gballet/go-libpcsclite/winscard.go
index 5eb9ce430..8c6f65d28 100644
--- a/vendor/github.com/gballet/go-libpcsclite/winscard.go
+++ b/vendor/github.com/gballet/go-libpcsclite/winscard.go
@@ -34,6 +34,7 @@ import (
"encoding/binary"
"fmt"
"net"
+ "sync"
"unsafe"
)
@@ -47,6 +48,8 @@ type Client struct {
ctx uint32
+ mutex sync.Mutex
+
readerStateDescriptors [MaxReaderStateDescriptors]ReaderState
}
@@ -117,6 +120,9 @@ func EstablishContext(scope uint32) (*Client, error) {
// ReleaseContext tells the daemon that the client will no longer
// need the context.
func (client *Client) ReleaseContext() error {
+ client.mutex.Lock()
+ defer client.mutex.Unlock()
+
data := [8]byte{}
binary.LittleEndian.PutUint32(data[:], client.ctx)
binary.LittleEndian.PutUint32(data[4:], SCardSuccess)
@@ -183,6 +189,9 @@ func getReaderState(data []byte) (ReaderState, error) {
// ListReaders gets the list of readers from the daemon
func (client *Client) ListReaders() ([]string, error) {
+ client.mutex.Lock()
+ defer client.mutex.Unlock()
+
err := messageSendWithHeader(CommandGetReaderState, client.conn, []byte{})
if err != nil {
return nil, err
@@ -230,6 +239,9 @@ type Card struct {
// Connect asks the daemon to connect to the card
func (client *Client) Connect(name string, shareMode uint32, preferredProtocol uint32) (*Card, error) {
+ client.mutex.Lock()
+ defer client.mutex.Unlock()
+
request := make([]byte, ReaderStateNameLength+4*6)
binary.LittleEndian.PutUint32(request, client.ctx)
copy(request[SCardConnectReaderNameOffset:], []byte(name))
@@ -289,6 +301,9 @@ const (
// Transmit sends request data to a card and returns the response
func (card *Card) Transmit(adpu []byte) ([]byte, *SCardIoRequest, error) {
+ card.client.mutex.Lock()
+ defer card.client.mutex.Unlock()
+
request := [TransmitRequestLength]byte{}
binary.LittleEndian.PutUint32(request[:], card.handle)
binary.LittleEndian.PutUint32(request[4:] /*card.activeProto*/, 2)
@@ -346,6 +361,9 @@ func (card *Card) Transmit(adpu []byte) ([]byte, *SCardIoRequest, error) {
// Disconnect tells the PCSC daemon that the client is no longer
// interested in communicating with the card.
func (card *Card) Disconnect(disposition uint32) error {
+ card.client.mutex.Lock()
+ defer card.client.mutex.Unlock()
+
data := [12]byte{}
binary.LittleEndian.PutUint32(data[:], card.handle)
binary.LittleEndian.PutUint32(data[4:], disposition)