From 2625057fe35cd3c72aa749e36a7f6d33d6dc072c Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Fri, 22 Mar 2019 19:51:05 +0100 Subject: [PATCH] Achieve full transaction signature+sending --- .../gballet/go-libpcsclite/winscard.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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)