Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smartcard implementation with PCSCLITE_CSOCK_NAME #1825

Open
wants to merge 11 commits into
base: devel
Choose a base branch
from
2 changes: 2 additions & 0 deletions common/xrdp_sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define CHANSRV_API_BASE_STR "xrdpapi_%d"
#define XRDP_X11RDP_BASE_STR "xrdp_display_%d"
#define XRDP_DISCONNECT_BASE_STR "xrdp_disconnect_display_%d"
#define XRDP_PCSC_BASE_STR "xrdp_pcsc_socket_%d"

/* fullpath of sockets */
#define XRDP_CHANSRV_STR XRDP_SOCKET_PATH "/" XRDP_CHANSRV_BASE_STR
Expand All @@ -36,5 +37,6 @@
#define CHANSRV_API_STR XRDP_SOCKET_PATH "/" CHANSRV_API_BASE_STR
#define XRDP_X11RDP_STR XRDP_SOCKET_PATH "/" XRDP_X11RDP_BASE_STR
#define XRDP_DISCONNECT_STR XRDP_SOCKET_PATH "/" XRDP_DISCONNECT_BASE_STR
#define XRDP_PCSC_STR XRDP_SOCKET_PATH "/" XRDP_PCSC_BASE_STR

#endif
45 changes: 27 additions & 18 deletions sesman/chansrv/smartcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void scard_send_IsContextValid(IRP *irp,
static void scard_send_ListReaders(IRP *irp,
char *context, int context_bytes,
char *groups, int cchReaders,
int wide);
int wide, int mszReadersIsNULL);
static void scard_send_GetStatusChange(IRP *irp,
char *context, int context_bytes,
int wide,
Expand All @@ -161,7 +161,8 @@ static void scard_send_EndTransaction(IRP *irp,
static void scard_send_Status(IRP *irp, int wide,
char *context, int context_bytes,
char *card, int card_bytes,
int cchReaderLen, int cbAtrLen);
int cchReaderLen, int cbAtrLen,
int reader_name_is_null);
static void scard_send_Disconnect(IRP *irp,
char *context, int context_bytes,
char *card, int card_bytes,
Expand All @@ -172,7 +173,8 @@ static int scard_send_Transmit(IRP *irp,
char *send_data, int send_bytes,
int recv_bytes,
struct xrdp_scard_io_request *send_ior,
struct xrdp_scard_io_request *recv_ior);
struct xrdp_scard_io_request *recv_ior,
int recv_ior_is_null, int recv_is_null);
static int scard_send_Control(IRP *irp, char *context, int context_bytes,
char *card, int card_bytes,
char *send_data, int send_bytes,
Expand Down Expand Up @@ -414,7 +416,8 @@ scard_send_is_valid_context(void *user_data, char *context, int context_bytes)
*****************************************************************************/
int
scard_send_list_readers(void *user_data, char *context, int context_bytes,
char *groups, int cchReaders, int wide)
char *groups, int cchReaders, int wide,
int mszReadersIsNULL)
{
IRP *irp;

Expand All @@ -432,7 +435,7 @@ scard_send_list_readers(void *user_data, char *context, int context_bytes,

/* send IRP to client */
scard_send_ListReaders(irp, context, context_bytes, groups,
cchReaders, wide);
cchReaders, wide, mszReadersIsNULL);

return 0;
}
Expand Down Expand Up @@ -614,7 +617,7 @@ scard_send_end_transaction(void *user_data, char *context, int context_bytes,
int
scard_send_status(void *user_data, int wide, char *context, int context_bytes,
char *card, int card_bytes,
int cchReaderLen, int cbAtrLen)
int cchReaderLen, int cbAtrLen, int reader_name_is_null)
{
IRP *irp;

Expand All @@ -633,7 +636,7 @@ scard_send_status(void *user_data, int wide, char *context, int context_bytes,

/* send IRP to client */
scard_send_Status(irp, wide, context, context_bytes, card, card_bytes,
cchReaderLen, cbAtrLen);
cchReaderLen, cbAtrLen, reader_name_is_null);

return 0;
}
Expand Down Expand Up @@ -679,7 +682,8 @@ scard_send_transmit(void *user_data, char *context, int context_bytes,
char *card, int card_bytes,
char *send_data, int send_bytes, int recv_bytes,
struct xrdp_scard_io_request *send_ior,
struct xrdp_scard_io_request *recv_ior)
struct xrdp_scard_io_request *recv_ior,
int recv_ior_is_null, int recv_is_null)
{
IRP *irp;

Expand All @@ -699,7 +703,8 @@ scard_send_transmit(void *user_data, char *context, int context_bytes,
/* send IRP to client */
scard_send_Transmit(irp, context, context_bytes, card, card_bytes,
send_data, send_bytes,
recv_bytes, send_ior, recv_ior);
recv_bytes, send_ior, recv_ior,
recv_ior_is_null, recv_is_null);

return 0;
}
Expand Down Expand Up @@ -1083,7 +1088,8 @@ scard_send_IsContextValid(IRP *irp, char *context, int context_bytes)
*****************************************************************************/
static void
scard_send_ListReaders(IRP *irp, char *context, int context_bytes,
char *groups, int cchReaders, int wide)
char *groups, int cchReaders, int wide,
int mszReadersIsNULL)
{
/* see [MS-RDPESC] 2.2.2.4 */

Expand Down Expand Up @@ -1133,7 +1139,7 @@ scard_send_ListReaders(IRP *irp, char *context, int context_bytes,
out_uint32_le(s, 0x00020000);
out_uint32_le(s, bytes_groups);
out_uint32_le(s, val);
out_uint32_le(s, 0x00000000);
out_uint32_le(s, mszReadersIsNULL);
out_uint32_le(s, cchReaders);

/* insert context */
Expand Down Expand Up @@ -1643,7 +1649,7 @@ scard_send_EndTransaction(IRP *irp, char *context, int context_bytes,
static void
scard_send_Status(IRP *irp, int wide, char *context, int context_bytes,
char *card, int card_bytes,
int cchReaderLen, int cbAtrLen)
int cchReaderLen, int cbAtrLen, int reader_name_is_null)
{
/* see [MS-RDPESC] 2.2.2.18 */

Expand Down Expand Up @@ -1686,7 +1692,7 @@ scard_send_Status(IRP *irp, int wide, char *context, int context_bytes,
out_uint32_le(s, 0x00020000);
out_uint32_le(s, card_bytes);
out_uint32_le(s, 0x00020004);
out_uint32_le(s, 0x00000001);
out_uint32_le(s, reader_name_is_null);
out_uint32_le(s, cchReaderLen); /* readerLen, see [MS-RDPESC] 4.11 */
out_uint32_le(s, cbAtrLen); /* atrLen, see [MS-RDPESC] 4.11 */

Expand Down Expand Up @@ -1797,7 +1803,8 @@ scard_send_Transmit(IRP *irp, char *context, int context_bytes,
char *card, int card_bytes, char *send_data,
int send_bytes, int recv_bytes,
struct xrdp_scard_io_request *send_ior,
struct xrdp_scard_io_request *recv_ior)
struct xrdp_scard_io_request *recv_ior,
int recv_ior_is_null, int recv_is_null)
{
/* see [MS-RDPESC] 2.2.2.19 */

Expand Down Expand Up @@ -1911,14 +1918,15 @@ scard_send_Transmit(IRP *irp, char *context, int context_bytes,

out_uint32_le(s, send_bytes);

val = send_bytes > 0 ? 0x00020008 : 0;
val = send_bytes > 0 ? 0x00020008 : 0; /* 0x00020008 : pointer to data after Transmit_Call struct : 0x00020000 + offset * 4 : map3 */
out_uint32_le(s, val); /* map3 */

val = recv_ior->cbPciLength > 0 ? 0x0002000c : 0;
val = recv_ior_is_null ? 0 : 0x00020008; /* 0x00020008 : pointer to data after Transmit_Call struct : 0x00020000 + offset * 4 : map4 */
out_uint32_le(s, val); /* map 4 */

out_uint32_le(s, 0); // map5
out_uint32_le(s, recv_is_null); // map5
out_uint32_le(s, recv_bytes);
/* end of Transmit_Call struct */

/* map0 */
out_uint32_le(s, context_bytes);
Expand All @@ -1936,12 +1944,13 @@ scard_send_Transmit(IRP *irp, char *context, int context_bytes,

if (send_bytes > 0)
{
/* map3 */
out_uint32_le(s, send_bytes);
out_uint8a(s, send_data, send_bytes);
align_s(s, 4);
}

if (recv_ior->cbPciLength > 0)
if (recv_ior_is_null == 0)
{
/* map4 */
out_uint32_le(s, recv_ior->dwProtocol);
Expand Down
15 changes: 12 additions & 3 deletions sesman/chansrv/smartcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
#define SCARD_RESET_CARD 0x00000001 /* reset smart card */
#define SCARD_UNPOWER_CARD 0x00000002 /* turn off and reset card */

/* see [MS-RDPESC] 2.2.5 protocol return code */
#define SCARD_S_SUCCESS 0x00000000
#define SCARD_F_INTERNAL_ERROR 0x80100001
#define SCARD_E_UNSUPPORTED_FEATURE 0x8010001F
#define SCARD_E_TIMEOUT 0x8010000A

struct xrdp_scard_io_request
{
tui32 dwProtocol;
Expand Down Expand Up @@ -117,7 +123,8 @@ int scard_send_is_valid_context(void *user_data,
char *context, int context_bytes);
int scard_send_list_readers(void *user_data,
char *context, int context_bytes,
char *groups, int cchReaders, int wide);
char *groups, int cchReaders, int wide,
int mszReadersIsNULL);

int scard_send_get_status_change(void *user_data,
char *context, int context_bytes,
Expand All @@ -143,7 +150,8 @@ int scard_send_end_transaction(void *user_data,
int scard_send_status(void *user_data, int wide,
char *context, int context_bytes,
char *card, int card_bytes,
int cchReaderLen, int cbAtrLen);
int cchReaderLen, int cbAtrLen,
int reader_name_is_null);
int scard_send_disconnect(void *user_data,
char *context, int context_bytes,
char *card, int card_bytes,
Expand All @@ -154,7 +162,8 @@ int scard_send_transmit(void *user_data,
char *card, int card_bytes,
char *send_data, int send_bytes, int recv_bytes,
struct xrdp_scard_io_request *send_ior,
struct xrdp_scard_io_request *recv_ior);
struct xrdp_scard_io_request *recv_ior,
int recv_ior_is_null, int recv_is_null);

int scard_send_control(void *user_data,
char *context, int context_bytes,
Expand Down
Loading