wxSecretStore issue
wxSecretStore issue
I'm having some issues with wxSecretStore , its most likely a bug on the wxSecretValue::GetAsString method.
If you go to windows credentials, create a generic one with a string 12345678 as a secret and use the Load function, then get the string you get only the first character, but using the GetSize() you can see that the full data is there (at least the size).
I tried to use GetData() to get it but it doesn't work. I think this is related to the windows credentials being wchar_t and its not converting properly.
Is there a way to use the GetAsString with a different converter so this works? how?
thanks!
If you go to windows credentials, create a generic one with a string 12345678 as a secret and use the Load function, then get the string you get only the first character, but using the GetSize() you can see that the full data is there (at least the size).
I tried to use GetData() to get it but it doesn't work. I think this is related to the windows credentials being wchar_t and its not converting properly.
Is there a way to use the GetAsString with a different converter so this works? how?
thanks!
Re: wxSecretStore issue
Hi,
What Windows version do you use? Are you using localized version of the OS?
What version of wxWidgets are you testing with?
Can you reproduce the behavior in a simplest possible sample?
How did you create a store? Can you explain it?
Thank you.
What Windows version do you use? Are you using localized version of the OS?
What version of wxWidgets are you testing with?
Can you reproduce the behavior in a simplest possible sample?
How did you create a store? Can you explain it?
Thank you.
Re: wxSecretStore issue
its easy to reproduce with the current secretstore sample , just create a credential manually in the windows (go to credential manager and add a new generic credential) and try to load it with the sample.
you get something like this:
PS F:\wxWidgets-3.1.3\samples\secretstore\vc_mswu_x64> .\secretstore.exe load testing1234
Password for testing1234/1234 is 16 bytes long: "1"
this was suposed to be 12345678 (16 bytes)
but it shows just 1.
wxwidgets 3.1.3
windows 10
localized to portuguese
Re: wxSecretStore issue
I also managed to get the correct data with the GetData() , so there is a workaround using it instead of GetAsString..
Re: wxSecretStore issue
Hui,
You didn't answer all other questions - in particular if you are using a localized Windows version.
Thank you.
But since it is reproducible in a sample - you might try to open a ticket at trac.wxwidgets.org with a way of reproducing it.
Please also include the answers to the questions I asked, so that it will be easy for the devs to check.
Thank you.
You didn't answer all other questions - in particular if you are using a localized Windows version.
Thank you.
But since it is reproducible in a sample - you might try to open a ticket at trac.wxwidgets.org with a way of reproducing it.
Please also include the answers to the questions I asked, so that it will be easy for the devs to check.
Thank you.
Re: wxSecretStore issue
This sounds like a string encoding issue. Under Windows a wxString contains UCS-2 (UTF-16) encoded characters, this means 2 bytes per char. Please show the code you use to read the process the string.If you go to windows credentials, create a generic one with a string 12345678 as a secret and use the Load function, then get the string you get only the first character, but using the GetSize() you can see that the full data is there (at least the size).
Use the source, Luke!
Re: wxSecretStore issue
this doesnt work (if you set it manually or with wincred.h)
Code: Select all
bool GetSecretUserPass(wxString &user, wxString &pass, const wxString &service)
{
wxSecretStore store = wxSecretStore::GetDefault();
wxString errmsg;
if (!store.IsOk())
{
wxMessageBox(_("Failed to create default secret store."),
_("Error creating secret store"));
return false;
}
wxSecretValue secret;
if (!store.Load(service, user, secret))
{
user = wxEmptyString;
pass = wxEmptyString;
return true;
}
pass = secret.GetAsString();
return true;
}
Re: wxSecretStore issue
I can confirm the issue and second Doublemax's opinion that it is the character conversion problem (UTF-16 input treated as char) in wxSecretValue::GetAsString().
On MSW with Unicode build it is easy to work around using
However, according to the Microsoft's docs,
On MSW with Unicode build it is easy to work around using
Code: Select all
pass = secret.GetAsString(wxMBConvUTF16());
Is wxSecretStore is supposed to be compatible with the data created with Credential Manager? On MSW wxSecretStore stores the password as UTF-8 encoded.If the Type member is CRED_TYPE_GENERIC, this member is defined by the application.
...
The application defines the byte-endian and alignment of the data in CredentialBlob.
Re: wxSecretStore issue
imo it should be compatible, I "fixed" my problem by using the ms api instead to save and reading using wxMBConvUTF16() .
Also, it would be nice we could set the persistance flag for the msw credential too..
Also, it would be nice we could set the persistance flag for the msw credential too..
Re: wxSecretStore issue
I'm seeing the issue in wxWidgets 3.2.1.
If try to save using wxSecretValue created from wxString or std::string on Windows, it saves the data in UTF8 by default. So then the app can read it only using wxMBConvUTF8.
Unfortunately if to edit the same entry using another tool (Credential Manager), now it's in UTF16LE and can't be read properly.
The problem can be solved using another constructor wxSecretValue(size_t size, const void *data) and put there wide-char data, so then it's read with wxMBConvUTF16LE.
But maybe makes sense to be compatible within the platform and save data by default in TCHAR*...
If try to save using wxSecretValue created from wxString or std::string on Windows, it saves the data in UTF8 by default. So then the app can read it only using wxMBConvUTF8.
Unfortunately if to edit the same entry using another tool (Credential Manager), now it's in UTF16LE and can't be read properly.
The problem can be solved using another constructor wxSecretValue(size_t size, const void *data) and put there wide-char data, so then it's read with wxMBConvUTF16LE.
But maybe makes sense to be compatible within the platform and save data by default in TCHAR*...
Re: wxSecretStore issue
Thanks for the info. Unfortunately this is a user forum, and the wx devs won't see your message here. It would be great if you could open an issue at https://github.com/wxWidgets/wxWidgets/issuesGlFox wrote: ↑Wed Oct 19, 2022 3:01 pm If try to save using wxSecretValue created from wxString or std::string on Windows, it saves the data in UTF8 by default. So then the app can read it only using wxMBConvUTF8.
Unfortunately if to edit the same entry using another tool (Credential Manager), now it's in UTF16LE and can't be read properly.
Use the source, Luke!