Monday, March 10, 2025

Getting Started on a Mac


Having figured this out on Linux, can I do the same thing on a Mac? Everything I have read seems to suggest that things are "basically" the same on MacOS as they are on Linux.

So, I start by checking out the Go project and adding my own launch.json as before:
$ git clone git@github.com:deeper-x/gopcsc.git
Cloning into 'gopcsc'...
remote: Enumerating objects: 289, done.
remote: Counting objects: 100% (31/31), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 289 (delta 23), reused 21 (delta 21), pack-reused 258 (from 1)
Receiving objects: 100% (289/289), 52.37 KiB | 678.00 KiB/s, done.
Resolving deltas: 100% (162/162), done.
I then run the show-atr script, knowing what it should do now:
panic: can't connect to PCSCD


goroutine 1 [running]:
main.main()
        /Users/gareth/Projects/NFC/gopcsc/examples/show-atr/main.go:12 +0x4c5
Process 66467 has exited with status 2
OK, that isn't the best of all possible outcomes, although I'm not entirely surprised that it can't connect to pcscd because on Linux I had to run it by hand and I haven't tried doing that here.

While trying to track down where it might be, I came across /usr/bin/pcsctest, so I decided to give that a go:
$ /usr/bin/pcsctest


MUSCLE PC/SC Lite Test Program


Testing SCardEstablishContext : Command successful.
Testing SCardGetStatusChange
Please insert a working reader : Command successful.
Testing SCardListReaders : Command successful.
Reader 01: ACS ACR1552 1S CL Reader PICC
Reader 02: ACS ACR1552 1S CL Reader SAM
Enter the reader number : 01
Waiting for card insertion
OK, very good. Interestingly, it sees two readers, one for PICC and one for SAM, which I don't think I'd known before (and don't know what it means). I selected #1 at random. Let's flash the same room key I used before at it:
                                 : Command successful.
Testing SCardConnect : Command successful.
Testing SCardStatus : Command successful.
Current Reader Name : ACS ACR1552 1S CL Reader PICC
Current Reader State : 0x54
Current Reader Protocol : 0x1
Current Reader ATR Size : 20 (0x14)
Current Reader ATR Value : 3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A
Testing SCardDisconnect : Command successful.
Testing SCardReleaseContext : Command successful.
Excellent. Well, it seems that all the fundamentals are working and I don't need to update any files to include my specific reader model here.

While this is running, I see that a pcscd is running:
$ ps -ef | grep pcscd
  501 66541 1 0 10:27AM ?? 0:00.02 /System/Library/Frameworks/PCSC.framework/Versions/A/XPCServices/com.apple.ctkpcscd.xpc/Contents/MacOS/com.apple.ctkpcscd
  501 66549 1215 0 10:27AM ttys003 0:00.00 grep pcscd
But my current Go code still cannot connect to it.

Going back and reading the README for the gopcsc project, I see that it says that: "*Note*: macOS isn't and won't be supported, because its modified PCSC-Lite variant can't be accessed without `cgo`."

OK, so scratch that, then. Back to Google!

This references another Go binding with support for MacOS (Darwin) and Linux. So let's try that.

This code looks (and feels) flakier. For a start, it isn't structured into folders. For another, it doesn't have "example commands" but something it styles a "test" which isn't. When I patch those things up, the function "waitUntilCardPresent" doesn't actually wait. If I make sure a card is present, I see this:
$ go test
--- FAIL: TestGetAttrib (0.00s)
    scardtest.go:151: ATTRATR_STRING: 3b 8f 80 01 80 4f 0c a0 00 00 03 06 03 00 01 00 00 00 00 6a
    scard_test.go:156: scard: Feature not supported.
Found 2 readers:
[0] ACS ACR1552 1S CL Reader PICC
[1] ACS ACR1552 1S CL Reader SAM
Waiting for a Card
Connecting to card in ACS ACR1552 1S CL Reader PICC
Card status:
        reader: ACS ACR1552 1S CL Reader PICC
        state: 54
        active protocol: 2
        atr: 3b 8f 80 01 80 4f 0c a0 00 00 03 06 03 00 01 00 00 00 00 6a
Transmit:
        c-apdu: 00 a4 00 0c 02 3f 00
        r-apdu: 6a 81
FAIL
exit status 1
FAIL github.com/ebfe/scard 0.362s
I'm not sure what "Feature not supported" means, but I'm fairly sure that this code is not at the level of stability and reliability I need at the moment, so I'm going to ditch trying to use the Mac and just stick with developing on Linux. But at the very least I know where I'm up to.

Conclusion

While I'm sure it is possible to work with this on a Mac, it's above my pay grade and interest level, so I'm simply not going to. There's a reason I bought a Linux box and it is for this sort of situation.

No comments:

Post a Comment