Milestone 5: deliver embedded RDP sessions and lifecycle hardening
This commit is contained in:
50
third_party/FreeRDP/winpr/libwinpr/smartcard/CMakeLists.txt
vendored
Normal file
50
third_party/FreeRDP/winpr/libwinpr/smartcard/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
# WinPR: Windows Portable Runtime
|
||||
# libwinpr-smartcard cmake build script
|
||||
#
|
||||
# Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set(MODULE_PREFIX "WINPR_SMARTCARD")
|
||||
|
||||
if(PCSC_WINPR_FOUND)
|
||||
winpr_definition_add(WITH_WINPR_PCSC)
|
||||
endif()
|
||||
|
||||
option(WITH_SMARTCARD_PCSC "Enable smartcard PCSC backend" ON)
|
||||
|
||||
set(${MODULE_PREFIX}_SRCS smartcard.c smartcard.h)
|
||||
|
||||
if(WITH_SMARTCARD_PCSC)
|
||||
winpr_definition_add(WITH_SMARTCARD_PCSC)
|
||||
list(APPEND ${MODULE_PREFIX}_SRCS smartcard_pcsc.c smartcard_pcsc.h)
|
||||
endif()
|
||||
|
||||
if(WITH_SMARTCARD_INSPECT)
|
||||
winpr_definition_add(WITH_SMARTCARD_INSPECT)
|
||||
list(APPEND ${MODULE_PREFIX}_SRCS smartcard_inspect.c smartcard_inspect.h)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND ${MODULE_PREFIX}_SRCS smartcard_windows.c smartcard_windows.h)
|
||||
endif()
|
||||
|
||||
winpr_module_add(${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
if(PCSC_WINPR_FOUND)
|
||||
winpr_library_add_private(${PCSC_WINPR_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING_INTERNAL OR BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
7
third_party/FreeRDP/winpr/libwinpr/smartcard/ModuleOptions.cmake
vendored
Normal file
7
third_party/FreeRDP/winpr/libwinpr/smartcard/ModuleOptions.cmake
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
set(MINWIN_LAYER "0")
|
||||
set(MINWIN_GROUP "none")
|
||||
set(MINWIN_MAJOR_VERSION "0")
|
||||
set(MINWIN_MINOR_VERSION "0")
|
||||
set(MINWIN_SHORT_NAME "smartcard")
|
||||
set(MINWIN_LONG_NAME "Smart Card API")
|
||||
set(MODULE_LIBRARY_NAME "${MINWIN_SHORT_NAME}")
|
||||
1294
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard.c
vendored
Normal file
1294
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
31
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard.h
vendored
Normal file
31
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard.h
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Smart Card API
|
||||
*
|
||||
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_SMARTCARD_PRIVATE_H
|
||||
#define WINPR_SMARTCARD_PRIVATE_H
|
||||
|
||||
#include <winpr/smartcard.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include "smartcard_pcsc.h"
|
||||
#else
|
||||
#include "smartcard_windows.h"
|
||||
#endif
|
||||
|
||||
#endif /* WINPR_SMARTCARD_PRIVATE_H */
|
||||
1363
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_inspect.c
vendored
Normal file
1363
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_inspect.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
30
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_inspect.h
vendored
Normal file
30
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_inspect.h
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Smart Card API
|
||||
*
|
||||
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
* Copyright 2020 Armin Novak <armin.novak@thincast.com>
|
||||
* Copyright 2020 Thincast Technologies GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_SMARTCARD_INSPECT_PRIVATE_H
|
||||
#define WINPR_SMARTCARD_INSPECT_PRIVATE_H
|
||||
|
||||
#include <winpr/platform.h>
|
||||
#include <winpr/smartcard.h>
|
||||
|
||||
const SCardApiFunctionTable* Inspect_RegisterSCardApi(const SCardApiFunctionTable* pSCardApi);
|
||||
|
||||
#endif /* WINPR_SMARTCARD_INSPECT_PRIVATE_H */
|
||||
3464
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_pcsc.c
vendored
Normal file
3464
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_pcsc.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
175
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_pcsc.h
vendored
Normal file
175
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_pcsc.h
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Smart Card API
|
||||
*
|
||||
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
* Copyright 2020 Armin Novak <armin.novak@thincast.com>
|
||||
* Copyright 2020 Thincast Technologies GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_SMARTCARD_PCSC_PRIVATE_H
|
||||
#define WINPR_SMARTCARD_PCSC_PRIVATE_H
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <winpr/platform.h>
|
||||
#include <winpr/smartcard.h>
|
||||
|
||||
/**
|
||||
* On Windows, DWORD and ULONG are defined to unsigned long.
|
||||
* However, 64-bit Windows uses the LLP64 model which defines
|
||||
* unsigned long as a 4-byte type, while most non-Windows
|
||||
* systems use the LP64 model where unsigned long is 8 bytes.
|
||||
*
|
||||
* WinPR correctly defines DWORD and ULONG to be 4-byte types
|
||||
* regardless of LLP64/LP64, but this has the side effect of
|
||||
* breaking compatibility with the broken pcsc-lite types.
|
||||
*
|
||||
* To make matters worse, pcsc-lite correctly defines
|
||||
* the data types on OS X, but not on other platforms.
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef BYTE
|
||||
typedef uint8_t PCSC_BYTE;
|
||||
#endif
|
||||
typedef uint8_t PCSC_UCHAR;
|
||||
typedef PCSC_UCHAR* PCSC_PUCHAR;
|
||||
typedef uint16_t PCSC_USHORT;
|
||||
|
||||
#ifndef __COREFOUNDATION_CFPLUGINCOM__
|
||||
typedef uint32_t PCSC_ULONG;
|
||||
typedef void* PCSC_LPVOID;
|
||||
typedef int16_t PCSC_BOOL;
|
||||
#endif
|
||||
|
||||
typedef PCSC_ULONG* PCSC_PULONG;
|
||||
typedef const void* PCSC_LPCVOID;
|
||||
typedef uint32_t PCSC_DWORD;
|
||||
typedef PCSC_DWORD* PCSC_PDWORD;
|
||||
typedef uint16_t PCSC_WORD;
|
||||
typedef int32_t PCSC_LONG;
|
||||
typedef const char* PCSC_LPCSTR;
|
||||
typedef const PCSC_BYTE* PCSC_LPCBYTE;
|
||||
typedef PCSC_BYTE* PCSC_LPBYTE;
|
||||
typedef PCSC_DWORD* PCSC_LPDWORD;
|
||||
typedef char* PCSC_LPSTR;
|
||||
|
||||
#else
|
||||
|
||||
#ifndef BYTE
|
||||
typedef unsigned char PCSC_BYTE;
|
||||
#endif
|
||||
typedef unsigned char PCSC_UCHAR;
|
||||
typedef PCSC_UCHAR* PCSC_PUCHAR;
|
||||
typedef unsigned short PCSC_USHORT;
|
||||
|
||||
#ifndef __COREFOUNDATION_CFPLUGINCOM__
|
||||
typedef unsigned long PCSC_ULONG;
|
||||
typedef void* PCSC_LPVOID;
|
||||
#endif
|
||||
|
||||
typedef const void* PCSC_LPCVOID;
|
||||
typedef unsigned long PCSC_DWORD;
|
||||
typedef PCSC_DWORD* PCSC_PDWORD;
|
||||
typedef long PCSC_LONG;
|
||||
typedef const char* PCSC_LPCSTR;
|
||||
typedef const PCSC_BYTE* PCSC_LPCBYTE;
|
||||
typedef PCSC_BYTE* PCSC_LPBYTE;
|
||||
typedef PCSC_DWORD* PCSC_LPDWORD;
|
||||
typedef char* PCSC_LPSTR;
|
||||
|
||||
/* these types were deprecated but still used by old drivers and
|
||||
* applications. So just declare and use them. */
|
||||
typedef PCSC_LPSTR PCSC_LPTSTR;
|
||||
typedef PCSC_LPCSTR PCSC_LPCTSTR;
|
||||
|
||||
/* types unused by pcsc-lite */
|
||||
typedef short PCSC_BOOL;
|
||||
typedef unsigned short PCSC_WORD;
|
||||
typedef PCSC_ULONG* PCSC_PULONG;
|
||||
|
||||
#endif
|
||||
|
||||
#define PCSC_SCARD_UNKNOWN 0x0001
|
||||
#define PCSC_SCARD_ABSENT 0x0002
|
||||
#define PCSC_SCARD_PRESENT 0x0004
|
||||
#define PCSC_SCARD_SWALLOWED 0x0008
|
||||
#define PCSC_SCARD_POWERED 0x0010
|
||||
#define PCSC_SCARD_NEGOTIABLE 0x0020
|
||||
#define PCSC_SCARD_SPECIFIC 0x0040
|
||||
|
||||
#define PCSC_SCARD_PROTOCOL_RAW 0x00000004u
|
||||
#define PCSC_SCARD_PROTOCOL_T15 0x00000008u
|
||||
|
||||
#define PCSC_MAX_BUFFER_SIZE 264
|
||||
#define PCSC_MAX_BUFFER_SIZE_EXTENDED (4 + 3 + (1 << 16) + 3 + 2)
|
||||
|
||||
#define PCSC_MAX_ATR_SIZE 33
|
||||
|
||||
#define PCSC_SCARD_AUTOALLOCATE (PCSC_DWORD)(-1)
|
||||
|
||||
#define PCSC_SCARD_CTL_CODE(code) (0x42000000 + (code))
|
||||
#define PCSC_CM_IOCTL_GET_FEATURE_REQUEST PCSC_SCARD_CTL_CODE(3400)
|
||||
|
||||
/**
|
||||
* pcsc-lite defines SCARD_READERSTATE, SCARD_IO_REQUEST as packed
|
||||
* on Mac OS X only and uses default packing everywhere else.
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LPCSTR szReader;
|
||||
LPVOID pvUserData;
|
||||
PCSC_DWORD dwCurrentState;
|
||||
PCSC_DWORD dwEventState;
|
||||
PCSC_DWORD cbAtr;
|
||||
BYTE rgbAtr[PCSC_MAX_ATR_SIZE]; /* WinSCard: 36, PCSC: 33 */
|
||||
} PCSC_SCARD_READERSTATE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PCSC_DWORD dwProtocol;
|
||||
PCSC_DWORD cbPciLength;
|
||||
} PCSC_SCARD_IO_REQUEST;
|
||||
|
||||
#ifdef __APPLE__
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BYTE tag;
|
||||
BYTE length;
|
||||
UINT32 value;
|
||||
} PCSC_TLV_STRUCTURE;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
int PCSC_InitializeSCardApi(void);
|
||||
const SCardApiFunctionTable* PCSC_GetSCardApiFunctionTable(void);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* WINPR_SMARTCARD_PCSC_PRIVATE_H */
|
||||
126
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_windows.c
vendored
Normal file
126
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_windows.c
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Smart Card API
|
||||
*
|
||||
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/config.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/library.h>
|
||||
#include <winpr/smartcard.h>
|
||||
|
||||
#include "smartcard_windows.h"
|
||||
|
||||
static HMODULE g_WinSCardModule = nullptr;
|
||||
|
||||
static SCardApiFunctionTable Windows_SCardApiFunctionTable = {
|
||||
0, /* dwVersion */
|
||||
0, /* dwFlags */
|
||||
|
||||
nullptr, /* SCardEstablishContext */
|
||||
nullptr, /* SCardReleaseContext */
|
||||
nullptr, /* SCardIsValidContext */
|
||||
nullptr, /* SCardListReaderGroupsA */
|
||||
nullptr, /* SCardListReaderGroupsW */
|
||||
nullptr, /* SCardListReadersA */
|
||||
nullptr, /* SCardListReadersW */
|
||||
nullptr, /* SCardListCardsA */
|
||||
nullptr, /* SCardListCardsW */
|
||||
nullptr, /* SCardListInterfacesA */
|
||||
nullptr, /* SCardListInterfacesW */
|
||||
nullptr, /* SCardGetProviderIdA */
|
||||
nullptr, /* SCardGetProviderIdW */
|
||||
nullptr, /* SCardGetCardTypeProviderNameA */
|
||||
nullptr, /* SCardGetCardTypeProviderNameW */
|
||||
nullptr, /* SCardIntroduceReaderGroupA */
|
||||
nullptr, /* SCardIntroduceReaderGroupW */
|
||||
nullptr, /* SCardForgetReaderGroupA */
|
||||
nullptr, /* SCardForgetReaderGroupW */
|
||||
nullptr, /* SCardIntroduceReaderA */
|
||||
nullptr, /* SCardIntroduceReaderW */
|
||||
nullptr, /* SCardForgetReaderA */
|
||||
nullptr, /* SCardForgetReaderW */
|
||||
nullptr, /* SCardAddReaderToGroupA */
|
||||
nullptr, /* SCardAddReaderToGroupW */
|
||||
nullptr, /* SCardRemoveReaderFromGroupA */
|
||||
nullptr, /* SCardRemoveReaderFromGroupW */
|
||||
nullptr, /* SCardIntroduceCardTypeA */
|
||||
nullptr, /* SCardIntroduceCardTypeW */
|
||||
nullptr, /* SCardSetCardTypeProviderNameA */
|
||||
nullptr, /* SCardSetCardTypeProviderNameW */
|
||||
nullptr, /* SCardForgetCardTypeA */
|
||||
nullptr, /* SCardForgetCardTypeW */
|
||||
nullptr, /* SCardFreeMemory */
|
||||
nullptr, /* SCardAccessStartedEvent */
|
||||
nullptr, /* SCardReleaseStartedEvent */
|
||||
nullptr, /* SCardLocateCardsA */
|
||||
nullptr, /* SCardLocateCardsW */
|
||||
nullptr, /* SCardLocateCardsByATRA */
|
||||
nullptr, /* SCardLocateCardsByATRW */
|
||||
nullptr, /* SCardGetStatusChangeA */
|
||||
nullptr, /* SCardGetStatusChangeW */
|
||||
nullptr, /* SCardCancel */
|
||||
nullptr, /* SCardConnectA */
|
||||
nullptr, /* SCardConnectW */
|
||||
nullptr, /* SCardReconnect */
|
||||
nullptr, /* SCardDisconnect */
|
||||
nullptr, /* SCardBeginTransaction */
|
||||
nullptr, /* SCardEndTransaction */
|
||||
nullptr, /* SCardCancelTransaction */
|
||||
nullptr, /* SCardState */
|
||||
nullptr, /* SCardStatusA */
|
||||
nullptr, /* SCardStatusW */
|
||||
nullptr, /* SCardTransmit */
|
||||
nullptr, /* SCardGetTransmitCount */
|
||||
nullptr, /* SCardControl */
|
||||
nullptr, /* SCardGetAttrib */
|
||||
nullptr, /* SCardSetAttrib */
|
||||
nullptr, /* SCardUIDlgSelectCardA */
|
||||
nullptr, /* SCardUIDlgSelectCardW */
|
||||
nullptr, /* GetOpenCardNameA */
|
||||
nullptr, /* GetOpenCardNameW */
|
||||
nullptr, /* SCardDlgExtendedError */
|
||||
nullptr, /* SCardReadCacheA */
|
||||
nullptr, /* SCardReadCacheW */
|
||||
nullptr, /* SCardWriteCacheA */
|
||||
nullptr, /* SCardWriteCacheW */
|
||||
nullptr, /* SCardGetReaderIconA */
|
||||
nullptr, /* SCardGetReaderIconW */
|
||||
nullptr, /* SCardGetDeviceTypeIdA */
|
||||
nullptr, /* SCardGetDeviceTypeIdW */
|
||||
nullptr, /* SCardGetReaderDeviceInstanceIdA */
|
||||
nullptr, /* SCardGetReaderDeviceInstanceIdW */
|
||||
nullptr, /* SCardListReadersWithDeviceInstanceIdA */
|
||||
nullptr, /* SCardListReadersWithDeviceInstanceIdW */
|
||||
nullptr /* SCardAudit */
|
||||
};
|
||||
|
||||
const SCardApiFunctionTable* Windows_GetSCardApiFunctionTable(void)
|
||||
{
|
||||
return &Windows_SCardApiFunctionTable;
|
||||
}
|
||||
|
||||
int Windows_InitializeSCardApi(void)
|
||||
{
|
||||
g_WinSCardModule = LoadLibraryA("WinSCard.dll");
|
||||
|
||||
if (!g_WinSCardModule)
|
||||
return -1;
|
||||
|
||||
WinSCard_LoadApiTableFunctions(&Windows_SCardApiFunctionTable, g_WinSCardModule);
|
||||
return 1;
|
||||
}
|
||||
28
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_windows.h
vendored
Normal file
28
third_party/FreeRDP/winpr/libwinpr/smartcard/smartcard_windows.h
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Smart Card API
|
||||
*
|
||||
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_SMARTCARD_WINSCARD_PRIVATE_H
|
||||
#define WINPR_SMARTCARD_WINSCARD_PRIVATE_H
|
||||
|
||||
#include <winpr/smartcard.h>
|
||||
|
||||
int Windows_InitializeSCardApi(void);
|
||||
const SCardApiFunctionTable* Windows_GetSCardApiFunctionTable(void);
|
||||
|
||||
#endif /* WINPR_SMARTCARD_WINSCARD_PRIVATE_H */
|
||||
23
third_party/FreeRDP/winpr/libwinpr/smartcard/test/CMakeLists.txt
vendored
Normal file
23
third_party/FreeRDP/winpr/libwinpr/smartcard/test/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
set(MODULE_NAME "TestSmartCard")
|
||||
set(MODULE_PREFIX "TEST_SMARTCARD")
|
||||
|
||||
disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
|
||||
|
||||
set(${MODULE_PREFIX}_TESTS TestSmartCardListReaders.c)
|
||||
|
||||
create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS})
|
||||
|
||||
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
target_link_libraries(${MODULE_NAME} winpr)
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
|
||||
|
||||
foreach(test ${${MODULE_PREFIX}_TESTS})
|
||||
get_filename_component(TestName ${test} NAME_WE)
|
||||
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
|
||||
endforeach()
|
||||
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
|
||||
53
third_party/FreeRDP/winpr/libwinpr/smartcard/test/TestSmartCardListReaders.c
vendored
Normal file
53
third_party/FreeRDP/winpr/libwinpr/smartcard/test/TestSmartCardListReaders.c
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/smartcard.h>
|
||||
|
||||
int TestSmartCardListReaders(int argc, char* argv[])
|
||||
{
|
||||
LONG lStatus = 0;
|
||||
LPSTR pReader = nullptr;
|
||||
SCARDCONTEXT hSC = 0;
|
||||
LPSTR mszReaders = nullptr;
|
||||
DWORD cchReaders = SCARD_AUTOALLOCATE;
|
||||
|
||||
WINPR_UNUSED(argc);
|
||||
WINPR_UNUSED(argv);
|
||||
|
||||
lStatus = SCardEstablishContext(SCARD_SCOPE_USER, nullptr, nullptr, &hSC);
|
||||
|
||||
if (lStatus != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("SCardEstablishContext failure: %s (0x%08" PRIX32 ")\n",
|
||||
SCardGetErrorString(lStatus), lStatus);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lStatus = SCardListReadersA(hSC, nullptr, (LPSTR)&mszReaders, &cchReaders);
|
||||
|
||||
if (lStatus != SCARD_S_SUCCESS)
|
||||
{
|
||||
if (lStatus == SCARD_E_NO_READERS_AVAILABLE)
|
||||
printf("SCARD_E_NO_READERS_AVAILABLE\n");
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pReader = mszReaders;
|
||||
|
||||
while (*pReader)
|
||||
{
|
||||
printf("Reader: %s\n", pReader);
|
||||
pReader = pReader + strlen((CHAR*)pReader) + 1;
|
||||
}
|
||||
|
||||
lStatus = SCardFreeMemory(hSC, mszReaders);
|
||||
|
||||
if (lStatus != SCARD_S_SUCCESS)
|
||||
printf("Failed SCardFreeMemory\n");
|
||||
}
|
||||
|
||||
SCardReleaseContext(hSC);
|
||||
|
||||
return 0;
|
||||
}
|
||||
160
third_party/FreeRDP/winpr/libwinpr/smartcard/test/TestSmartCardStatus.c
vendored
Normal file
160
third_party/FreeRDP/winpr/libwinpr/smartcard/test/TestSmartCardStatus.c
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
// compile against PCSC gcc -o scardtest TestSmartCardStatus.c -DPCSC=1 -I /usr/include/PCSC
|
||||
// -lpcsclite
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(__APPLE__) || defined(PCSC)
|
||||
#include <PCSC/winscard.h>
|
||||
#include <PCSC/wintypes.h>
|
||||
#elif defined(__linux__)
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/smartcard.h>
|
||||
#include <winpr/synch.h>
|
||||
#else
|
||||
#include <winscard.h>
|
||||
#endif
|
||||
|
||||
#if defined(PCSC)
|
||||
int main(int argc, char* argv[])
|
||||
#else
|
||||
int TestSmartCardStatus(int argc, char* argv[])
|
||||
#endif
|
||||
{
|
||||
SCARDCONTEXT hContext;
|
||||
LPSTR mszReaders;
|
||||
DWORD cchReaders = 0;
|
||||
DWORD err;
|
||||
SCARDHANDLE hCard;
|
||||
DWORD dwActiveProtocol;
|
||||
char name[100];
|
||||
char* aname = nullptr;
|
||||
char* aatr = nullptr;
|
||||
DWORD len;
|
||||
BYTE atr[32];
|
||||
DWORD atrlen = 32;
|
||||
DWORD status = 0;
|
||||
DWORD protocol = 0;
|
||||
err = SCardEstablishContext(SCARD_SCOPE_SYSTEM, nullptr, nullptr, &hContext);
|
||||
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("ScardEstablishedContext: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = SCardListReaders(hContext, "SCard$AllReaders", nullptr, &cchReaders);
|
||||
|
||||
if (err != 0)
|
||||
{
|
||||
printf("ScardListReaders: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mszReaders = calloc(cchReaders, sizeof(char));
|
||||
|
||||
if (!mszReaders)
|
||||
{
|
||||
printf("calloc\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = SCardListReaders(hContext, "SCard$AllReaders", mszReaders, &cchReaders);
|
||||
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("ScardListReaders: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Reader: %s\n", mszReaders);
|
||||
err = SCardConnect(hContext, mszReaders, SCARD_SHARE_SHARED,
|
||||
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol);
|
||||
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("ScardConnect: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(mszReaders);
|
||||
|
||||
printf("# test 1 - get reader length\n");
|
||||
err = SCardStatus(hCard, nullptr, &len, nullptr, nullptr, nullptr, nullptr);
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("SCardStatus: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
printf("reader name length: %u\n", len);
|
||||
|
||||
printf("# test 2 - get reader name value\n");
|
||||
err = SCardStatus(hCard, name, &len, nullptr, nullptr, nullptr, nullptr);
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("SCardStatus: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
printf("Reader name: %s (%ld)\n", name, strlen(name));
|
||||
|
||||
printf("# test 3 - get all values - pre allocated\n");
|
||||
err = SCardStatus(hCard, name, &len, &status, &protocol, atr, &atrlen);
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("SCardStatus: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
printf("Reader name: %s (%ld/len %u)\n", name, strlen(name), len);
|
||||
printf("status: 0x%08X\n", status);
|
||||
printf("proto: 0x%08X\n", protocol);
|
||||
printf("atrlen: %u\n", atrlen);
|
||||
|
||||
printf("# test 4 - get all values - auto allocate\n");
|
||||
len = atrlen = SCARD_AUTOALLOCATE;
|
||||
err = SCardStatus(hCard, (LPSTR)&aname, &len, &status, &protocol, (LPBYTE)&aatr, &atrlen);
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("SCardStatus: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
printf("Reader name: %s (%ld/%u)\n", aname, strlen(aname), len);
|
||||
printf("status: 0x%08X\n", status);
|
||||
printf("proto: 0x%08X\n", protocol);
|
||||
printf("atrlen: %u\n", atrlen);
|
||||
SCardFreeMemory(hContext, aname);
|
||||
SCardFreeMemory(hContext, aatr);
|
||||
|
||||
printf("# test 5 - get status and protocol only\n");
|
||||
err = SCardStatus(hCard, nullptr, nullptr, &status, &protocol, nullptr, nullptr);
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("SCardStatus: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
printf("status: 0x%08X\n", status);
|
||||
printf("proto: 0x%08X\n", protocol);
|
||||
|
||||
printf("# test 6 - get atr only auto allocated\n");
|
||||
atrlen = SCARD_AUTOALLOCATE;
|
||||
err = SCardStatus(hCard, nullptr, nullptr, nullptr, nullptr, (LPBYTE)&aatr, &atrlen);
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("SCardStatus: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
printf("atrlen: %u\n", atrlen);
|
||||
SCardFreeMemory(hContext, aatr);
|
||||
|
||||
printf("# test 7 - get atr only pre allocated\n");
|
||||
atrlen = 32;
|
||||
err = SCardStatus(hCard, nullptr, nullptr, nullptr, nullptr, atr, &atrlen);
|
||||
if (err != SCARD_S_SUCCESS)
|
||||
{
|
||||
printf("SCardStatus: 0x%08x\n", err);
|
||||
return -1;
|
||||
}
|
||||
printf("atrlen: %u\n", atrlen);
|
||||
SCardDisconnect(hCard, SCARD_LEAVE_CARD);
|
||||
SCardReleaseContext(hContext);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user