forked from FreeRDP/FreeRDP
-
Notifications
You must be signed in to change notification settings - Fork 10
Add smart card support #45
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
Draft
thecristidima
wants to merge
1
commit into
chore/fix_cherrypick_conflicts_3.16
Choose a base branch
from
feature/smartcard_support
base: chore/fix_cherrypick_conflicts_3.16
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,10 @@ | |
| #pragma warning(disable : 4324 4201 4245 4996) | ||
| #include <freerdp/freerdp.h> | ||
| #include <freerdp/cache/cache.h> | ||
| #include <freerdp/addin.h> | ||
| #include <freerdp/client/channels.h> | ||
| #include <freerdp/channels/rdpsnd.h> | ||
| #include <freerdp/channels/rdpdr.h> | ||
| #pragma warning(default : 4324 4201 4245 4996) | ||
| #pragma once | ||
| using namespace Logging; | ||
|
|
@@ -20,6 +24,21 @@ namespace FreeRdpClient | |
| return _strdup(convToUTF8.to_bytes(source).c_str()); | ||
| } | ||
|
|
||
| wchar_t* ConvToUtf16(const char* source) | ||
| { | ||
| if (!source) // Handle null input | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; | ||
| std::wstring wideString = converter.from_bytes(source); | ||
|
|
||
| wchar_t* wstr = new wchar_t[wideString.size() + 1]; | ||
| std::wmemcpy(wstr, wideString.c_str(), wideString.size() + 1); | ||
| return wstr; | ||
| } | ||
|
|
||
| class instance_data | ||
| { | ||
| public: | ||
|
|
@@ -98,7 +117,110 @@ namespace FreeRdpClient | |
| return instance; | ||
| } | ||
|
|
||
| void PrepareRdpContext(rdpContext* context, const ConnectOptions* rdpOptions) | ||
| static BOOL LoadStaticChannelAddin(rdpChannels* channels, | ||
| rdpSettings* settings, const char* name, | ||
| void* data) | ||
| { | ||
| PVIRTUALCHANNELENTRY entry = NULL; | ||
| PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry( | ||
| name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC | FREERDP_ADDIN_CHANNEL_ENTRYEX); | ||
| PVIRTUALCHANNELENTRYEX pvceex = WINPR_FUNC_PTR_CAST(pvce, PVIRTUALCHANNELENTRYEX); | ||
|
|
||
| if (!pvceex) | ||
| entry = | ||
| freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC); | ||
|
|
||
| if (pvceex) | ||
| { | ||
| if (freerdp_channels_client_load_ex(channels, settings, pvceex, data) == 0) | ||
| { | ||
| DT_TRACE(L"loading channelEx %s", name); | ||
| return TRUE; | ||
| } | ||
| } | ||
| else if (entry) | ||
| { | ||
| if (freerdp_channels_client_load(channels, settings, entry, data) == 0) | ||
| { | ||
| DT_TRACE(L"loading channel %s", name); | ||
| return TRUE; | ||
| } | ||
| } | ||
|
|
||
| return FALSE; | ||
| } | ||
|
|
||
| BOOL AddStaticChannel(rdpSettings* settings, size_t count, const char* const* params) | ||
| { | ||
| ADDIN_ARGV* _args = NULL; | ||
|
|
||
| if (!settings || !params || !params[0] || (count > INT_MAX)) | ||
| return FALSE; | ||
|
|
||
| if (freerdp_static_channel_collection_find(settings, params[0])) | ||
| return TRUE; | ||
|
|
||
| _args = freerdp_addin_argv_new(count, params); | ||
|
|
||
| if (!_args) | ||
| return FALSE; | ||
|
|
||
| if (!freerdp_static_channel_collection_add(settings, _args)) | ||
| { | ||
| freerdp_addin_argv_free(_args); | ||
| return FALSE; | ||
| } | ||
|
|
||
| return TRUE; | ||
| } | ||
|
|
||
| static BOOL LoadChannels(rdpChannels* channels, rdpSettings* settings) | ||
| { | ||
| if (!LoadStaticChannelAddin(channels, settings, RDPDR_SVC_CHANNEL_NAME, | ||
| settings)) | ||
| return FALSE; | ||
|
|
||
| if (!freerdp_static_channel_collection_find(settings, RDPSND_CHANNEL_NAME)) | ||
| { | ||
| const char* const params[] = { RDPSND_CHANNEL_NAME, "sys:fake" }; | ||
|
|
||
| if (!AddStaticChannel(settings, ARRAYSIZE(params), params)) | ||
| return FALSE; | ||
| } | ||
|
|
||
| if (freerdp_settings_get_bool(settings, FreeRDP_RedirectSmartCards)) | ||
| { | ||
| if (!freerdp_device_collection_find_type(settings, RDPDR_DTYP_SMARTCARD)) | ||
| { | ||
| RDPDR_DEVICE* smartcard = freerdp_device_new(RDPDR_DTYP_SMARTCARD, 0, NULL); | ||
|
|
||
| if (!smartcard) | ||
| return FALSE; | ||
|
|
||
| if (!freerdp_device_collection_add(settings, smartcard)) | ||
| { | ||
| freerdp_device_free(smartcard); | ||
| return FALSE; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for (UINT32 i = 0; i < freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount); i++) | ||
| { | ||
| ADDIN_ARGV* _args = static_cast<ADDIN_ARGV*>(freerdp_settings_get_pointer_array_writable(settings, | ||
| FreeRDP_StaticChannelArray, i)); | ||
|
|
||
| if (!LoadStaticChannelAddin(channels, settings, _args->argv[0], _args)) | ||
| return FALSE; | ||
| } | ||
| } | ||
|
|
||
| BOOL LoadChannelsCore(freerdp* instance) | ||
| { | ||
| return LoadChannels(instance->context->channels, instance->context->settings); | ||
| } | ||
|
|
||
| BOOL PrepareRdpContext(rdpContext* context, const ConnectOptions* rdpOptions) | ||
| { | ||
| context->settings->ServerHostname = ConvToUtf8(rdpOptions->HostName); | ||
|
|
||
|
|
@@ -140,6 +262,51 @@ namespace FreeRdpClient | |
| context->settings->ColorDepth = rdpOptions->Depth; | ||
|
|
||
| context->settings->AllowFontSmoothing = rdpOptions->FontSmoothing; | ||
|
|
||
| if (rdpOptions->smartcardSettings.IsSmartCardLogon) | ||
| { | ||
| context->settings->SmartcardLogon = TRUE; | ||
| context->settings->PasswordIsSmartcardPin = TRUE; | ||
| context->settings->RedirectSmartCards = TRUE; | ||
| context->settings->DeviceRedirection = TRUE; | ||
| context->settings->KeySpec = 1; | ||
|
|
||
| context->settings->ReaderName = ConvToUtf8(rdpOptions->smartcardSettings.ReaderName); | ||
| context->settings->CspName = ConvToUtf8(rdpOptions->smartcardSettings.CspName); | ||
| context->settings->ContainerName = ConvToUtf8(rdpOptions->smartcardSettings.ContainerName); | ||
|
|
||
| context->instance->LoadChannels = LoadChannelsCore; | ||
|
|
||
| // Only called if multiple certificates are available for the same user | ||
| context->instance->ChooseSmartcard = [](freerdp* instance, | ||
| SmartcardCertInfo** cert_list, DWORD count, | ||
| DWORD* choice, BOOL gateway) -> BOOL | ||
| { | ||
| auto res = false; | ||
| auto containerName = ConvToUtf16(instance->context->settings->ContainerName); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just note, rdpOptions->smartcardSettings.ContainerName is already utf16 |
||
|
|
||
| for (DWORD idx = 0; idx < count; idx++) | ||
| { | ||
| if (wcscmp(cert_list[idx]->containerName, containerName) != 0) | ||
| continue; | ||
|
|
||
| *choice = idx; | ||
| res = true; | ||
| break; | ||
| } | ||
|
|
||
| delete[] containerName; | ||
| return res; | ||
| }; | ||
|
|
||
| if (freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0) != CHANNEL_RC_OK) | ||
| { | ||
| DT_ERROR(L"Failed to register addin provider"); | ||
| return FALSE; | ||
| } | ||
| } | ||
|
|
||
| return TRUE; | ||
| } | ||
|
|
||
| DWORD ReleaseAll(instance_data* instanceData) | ||
|
|
@@ -276,10 +443,9 @@ namespace FreeRdpClient | |
| return E_OUTOFMEMORY; | ||
|
|
||
| rdpContext* context = instance->context; | ||
| PrepareRdpContext(context, rdpOptions); | ||
|
|
||
| auto connectResult = freerdp_connect(instance); | ||
| if (connectResult) | ||
| if (PrepareRdpContext(context, rdpOptions) | ||
| && freerdp_connect(instance)) | ||
| { | ||
| _bstr_t eventName; | ||
| if (transport_start(context, rdpOptions, eventName)) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed when it is localhost?