Go bindings to the PC/SC API.
go get -u github.com/ebfe/scard
- Memory layouts/GC/cgo rules needs a thorough review.
Go bindings to the PC/SC API.
License: BSD 2-Clause "Simplified" License
I see you have a .travis.yml file.
Maybe you could add a travis button in the README.md to link to the Travis results?
https://travis-ci.org/ebfe/scard
go get -u github.com/ebfe/scard
../github.com/ebfe/scard/scard_darwin.go:7:11: fatal error: 'PCSC/winscard.h' file not found
#include <PCSC/winscard.h>
GOOS=linux GOARCH=arm GOARM=5 go build -o tag2img-linux
# github.com/ebfe/scard
../../ebfe/scard/scard.go:244:11: undefined: strbuf
I'm using this module via https://github.com/yawn/ykoath/blob/master/ykoath.go and running into something I'd like to implement.
Right now, if I have multiple yubikeys plugged in, they get the same reader name, suffixed with an integer, but the naming is based on insertion order, so it changes depending on which device I plug in first.
As an example:
package main
import (
"fmt"
"github.com/ebfe/scard"
)
func main() {
context, err := scard.EstablishContext()
if err != nil {
panic(err)
}
readers, err := context.ListReaders()
if err != nil {
panic(err)
}
for _, reader := range readers {
fmt.Println(reader)
}
}
❯ go run ./main.go
Yubico YubiKey OTP+FIDO+CCID
Yubico YubiKey OTP+FIDO+CCID 01
I poked around a bit at this library to see if there's a way to pull a unique identifier from the attributes, but this seems like the obly attributes that the yubikey supports (thought supports is a bit of a stretch, given that most of them are blank):
Yubico YubiKey OTP+FIDO+CCID 01: AttrChannelId:
Yubico YubiKey OTP+FIDO+CCID 01: AttrIccPresence:
Yubico YubiKey OTP+FIDO+CCID 01: AttrIccInterfaceStatus:
Yubico YubiKey OTP+FIDO+CCID 01: AttrAtrString: ;��1��s�!�WYubiKey@
Yubico YubiKey OTP+FIDO+CCID 01: AttrMaxinput: �
Yubico YubiKey OTP+FIDO+CCID 01: AttrVendorName: Yubico
Yubico YubiKey OTP+FIDO+CCID 01: AttrVendorIfdVersion: C
Yubico YubiKey OTP+FIDO+CCID 01: AttrVendorIfdSerialNo:
Are you aware of a way I can differentiate between the smartcards in a deterministic way?
There is a lot of overlap between this project and https://github.com/sf1/go-card.
I am currently using this project because I need GetStatusChange
, but sf1/go-card has some nice things too, like the ISO Command APDU factory functions, the Reader
struct with IsCardPresent()
and WaitForCardPresent()
.
How do you feel about merging those features into ebfe/scard?
See also: sf1/go-card#1
Environment: go1.8 , linux
Error during compilation.
Error Message:
cgo-gcc-prolog:198:2: warning: passing argument 3 of ‘SCardGetStatusChange’ from incompatible pointer type [enabled by default]
/usr/include/PCSC/winscard.h:64:16: note: expected ‘LPSCARD_READERSTATE’ but argument is of type ‘struct *’
PCSC_API LONG SCardGetStatusChange(SCARDCONTEXT hContext,
In darwin, the struct SCARD_READERSTATE
is declared as packed with alignment of 1 byte.
type scardReaderState struct {
szReader uintptr
pvUserData uintptr
dwCurrentState uint32
dwEventState uint32
cbAtr uint32
rgbAtr [33]byte
}
Go adds 3 bytes of padding at the end of this struct. So the cast of states
in scard_darwin.go
is invalid, because there are bytes between the elements of the array which shouldn't be there:
func scardGetStatusChange(ctx uintptr, timeout uint32, states []scardReaderState) Error {
r := C.SCardGetStatusChange(C.SCARDCONTEXT(ctx), C.uint32_t(timeout), (C.LPSCARD_READERSTATE_A)(unsafe.Pointer(&states[0])), C.uint32_t(len(states)))
return Error(r)
}
As a result, code using GetStatusChange
in darwin segfaults.
Thanks for this repo, I got example running:
Found 1 readers:
[0] ACS ACR122U PICC Interface
Waiting for a Card
Connecting to card in ACS ACR122U PICC Interface
Card status:
reader: ACS ACR122U PICC Interface
state: 54
active protocol: 2
atr: 3b 80 80 01 01
Transmit:
c-apdu: 00 a4 00 0c 02 3f 00
r-apdu: 6a 82
But wondering, how do I read the NDEF URI tag my device is sending. Is that a call to transmit with some payload or a simpler way?
Hi,
I am using go version go1.11 linux/amd64 on Ubuntu 16.04. When I try to get the code with go get github.com/ebfe/scard I get the following error:
# github.com/ebfe/go.pcsclite/scard
cgo-gcc-prolog: In function ‘_cgo_7cdefc941711_Cfunc_SCardGetStatusChange’:
cgo-gcc-prolog:209:56: warning: passing argument 3 of ‘SCardGetStatusChange’ from incompatible pointer type [-Wincompatible-pointer-types]
In file included from ../../../go/src/github.com/ebfe/go.pcsclite/scard/scard.go:12:0:
/usr/include/PCSC/winscard.h:87:16: note: expected ‘LPSCARD_READERSTATE {aka struct <anonymous> *}’ but argument is of type ‘struct <anonymous> *’
PCSC_API LONG SCardGetStatusChange(SCARDCONTEXT hContext,
^
# github.com/ebfe/go.pcsclite/scard
../../../go/src/github.com/ebfe/go.pcsclite/scard/scard.go:150:31: cannot use _Ctype_LPSCARD_READERSTATE(unsafe.Pointer(&crs[0])) (type Ctype_LPSCARD_READERSTATE) as type *_Ctype_struct___2 in argument to func literal
Any ideas?
Kind Regards,
Antonio
It works well for windows and mac. But when I try to compile for linux I get:
GOOS=linux GOARCH=arm64 go build -o ../bin/card-reader-driver-amd64-linux
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:35:12: undefined: scardEstablishContext
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:45:7: undefined: scardIsValidContext
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:58:7: undefined: scardCancel
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:67:7: undefined: scardReleaseContext
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:76:15: undefined: scardListReaders
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:81:14: undefined: strbuf
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:271:11: undefined: strbuf
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:275:11: undefined: strbuf
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:291:37: undefined: strbuf
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:304:21: undefined: strbuf
../../../../go/pkg/mod/github.com/ebfe/[email protected]/scard.go:81:14: too many errors
Any idea?
Hi,
I am using your go lang bindings to connect to a eid card.
The problem is that i can connect to it and send commands using transmit and get successful status from the card, but i am not able to read the data out of the response just the status code.
Can you please help me with this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.