FreeRDP/FreeRDP — pull request #1778 by awakecoding (2014-04-09 04:09:28+00:00)
Title: Smart Card Complete Overhaul

This is the pull request you've all been waiting for: a complete overhaul of smart card support in FreeRDP, and yes, it's getting pretty good.

Here's a (quite summarized) list of things I did:

* Add new libwinpr-smartcard module which exposes a proper WinSCard implementation and wraps under the hood either the original WinSCard API on Windows or pcsc-lite on non-Windows.
* Removed (yes, removed!) the link-time dependency on pcsc-lite. libwinpr-smartcard simply loads libpcsclite.so dynamically on Linux, the PCSC framework library on OS X, and winscard.dll on Windows.
* Implemented many of the WinSCard APIs which are not implemented by pcsc-lite, especially all the unicode functions.
* New heavily hardened NDR encoding and decoding functions have been written for *all* the RDP smartcard data structures. For some reason Microsoft thought it was a great idea to use NDR for those, which is the same nightmare involved in MSRPC for TS Gateway.
* Added tons of strict checks and debug warnings on the first unexpected byte in those NDR data structures so we can very quickly see when it goes wrong and what goes wrong.
* Refactored all smartcard code to use proper definitions and WinSCard API from libwinpr-smartcard, which means no more custom definitions and #ifdef WITH_PCSC everywhere.
* Restructured smartcard channel code to use more common functions and strict error checking.
* Implemented proper unicode and ascii equivalents of smartcard channel calls along with equivalent WinSCard APIs.

For testing, I have been using the Athena Starter Kit, which comes with an Athena V3C USB reader and an IDProtect Key. The code is exactly the same on Windows, Linux and Mac OS X. I confirm it works fine with more than one readers connected at the same time. mythos and ntwerdochlib on IRC have also been testing as I have been working on this with positive results so far.

While I did port the code to Mac OS X, I may need some help with testing as there is apparently a problem with driver support and mavericks for my Athena smartcard readers.