Categorygithub.com/gballet/go-libpcsclite
modulepackage
0.0.0-20191108122812-4678299bea08
Repository: https://github.com/gballet/go-libpcsclite.git
Documentation: pkg.go.dev

# README

go-libpcsclite

A golang implementation of the libpcpsclite client. It connects to the pcscd daemon over sockets.

Purpose

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.

Example

func main() {
	client, err := EstablishContext(2)
	if err != nil {
    fmt.Printf("Error establishing context: %v\n", err)
    os.Exit(1)
	}

	_, 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})

	card.Disconnect(LeaveCard)
}

TODO

  • Finish this README
  • Lock context
  • implement missing functions

License

BSD 3-Clause License

Copyright (c) 2019, Guillaume Ballet All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 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.

# Functions

EstablishContext asks the PCSC daemon to create a context handle for further communication with connected cards and readers.

# Constants

see SCardFreeMemory() */.
get the readers state */.
stop waiting for a reader state change */.
get the client/server protocol version */.
wait for a reader state change */.
Eject on close */.
There was an error trying to set the smart card file object pointer.
The action was cancelled by an SCardCancel request.
The user pressed "Cancel" on a Smart Card Selection Dialog.
The system could not dispose of the media in the requested manner.
No PIN was presented to the smart card.
The smart card does not meet minimal requirements for support.
The requested certificate could not be obtained.
The card cannot be accessed because the maximum number of PIN entry attempts has been reached.
A communications error with the smart card has been detected.
An internal communications error has been detected.
The identified directory does not exist in the smart card.
The reader driver did not produce a unique reader name.
The end of the smart card file has been reached.
The identified file does not exist in the smart card.
The requested order of object creation is not supported.
No primary provider can be found for the smart card.
The data buffer to receive returned data is too small for the returned data.
An internal consistency check failed.
An ATR obtained from the registry is not a valid ATR string.
The supplied PIN is incorrect.
The supplied handle was invalid.
One or more of the supplied parameters could not be properly interpreted.
Registry startup information is missing or invalid.
One or more of the supplied parameters values could not be properly interpreted.
Access is denied to this file.
The supplied path does not represent a smart card directory.
The supplied path does not represent a smart card file.
The requested key container does not exist on the smart card.
Not enough memory available to complete this command.
Cannot find a smart card reader.
The Smart card resource manager is not running.
The operation requires a Smart Card, but no Smart Card is currently in the device.
The requested certificate does not exist.
The reader or smart card is not ready to accept commands.
An attempt was made to end a non-existent transaction.
The PCI Receive buffer was too small.
The requested protocols are incompatible with the protocol currently in use with the smart card.
The specified reader is not currently available for use.
The reader driver does not meet minimal requirements for support.
The smart card has been removed, so further communication is not possible.
The smart card has been reset, so any shared state information is invalid.
Access was denied because of a security violation.
The Smart Card Resource Manager is too busy to complete this operation.
The Smart card resource manager has shut down.
The smart card cannot be accessed because of other connections outstanding.
The operation has been aborted to allow the server application to exit.
The action was cancelled by the system, presumably to log off or shut down.
The user-specified timeout value has expired.
An unexpected card error has occurred.
The specified smart card name is not recognized.
An internal error has been detected, but the source is unknown.
The specified reader name is not recognized.
An unrecognized error code was returned from a layered component.
Power has been removed from the smart card, so that further communication is not possible.
The smart card is not responding to a reset.
The reader cannot communicate with the card, due to ATR string configuration conflicts.
This smart card does not support the requested feature.
An internal consistency timer has expired.
The smart card does not have enough memory to store the information.
The card cannot be accessed because the wrong PIN was presented.
Do nothing on close */.
Constants related to the reader state structure.
No description provided by the author
IFD determines prot.
Raw active protocol.
T=0 active protocol.
T=1 active protocol.
T=15 protocol.
protocol not set */.
backward compat */.
IPC major */.
IPC minor */.
NOTE: ATR is 32-byte aligned in the C version, which means it's actually 36 byte long and not 33.
Constants related to the reader state structure.
Constants related to the reader state structure.
Reset on close */.
Card is absent */.
used by SCardBeginTransaction() */.
used by SCardCancel() */.
not used */.
used by SCardConnect() */.
Offsets into the Connect request/response packet.
Offsets into the Connect request/response packet.
Offsets into the Connect request/response packet.
Offsets into the Connect request/response packet.
used by SCardControl() */.
used by SCardDisconnect() */.
used by SCardEndTransaction() */.
used by SCardEstablishContext() */.
used by SCardGetAttrib() */.
not used */.
used by SCardListReaders() */.
Ready for PTS */.
Card is powered */.
Card is present */.
used by SCardReconnect() */.
used by SCardReleaseContext() */.
used by SCardSetAttrib() */.
PTS has been set */.
used by SCardStatus() */.
No error was encountered.
Card not powered */.
used by SCardTransmit() */.
Unknown state */.
Scope is global */.
Scope in system */.
Scope in terminal */.
Scope in user space */.
Raw mode only */.
Exclusive mode only */.
Shared mode only */.
No description provided by the author
Power down on close */.

# Structs

Card represents the connection to a card.
Client contains all the information needed to establish and maintain a connection to the deamon/card.
ReaderState represent the state of a single reader, as reported by the PCSC daemon.
SCardIoRequest contains the info needed for performing an IO request.

# Type aliases

No description provided by the author