wxSecretStore issue

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
diogom12
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Jun 13, 2020 6:07 am

wxSecretStore issue

Post by diogom12 »

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!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxSecretStore issue

Post by ONEEYEMAN »

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.
diogom12
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Jun 13, 2020 6:07 am

Re: wxSecretStore issue

Post by diogom12 »

ONEEYEMAN wrote: Tue Jun 15, 2021 7:29 pm 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.
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
diogom12
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Jun 13, 2020 6:07 am

Re: wxSecretStore issue

Post by diogom12 »

I also managed to get the correct data with the GetData() , so there is a workaround using it instead of GetAsString..
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxSecretStore issue

Post by ONEEYEMAN »

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.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSecretStore issue

Post by doublemax »

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).
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.
Use the source, Luke!
diogom12
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Jun 13, 2020 6:07 am

Re: wxSecretStore issue

Post by diogom12 »

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;
    }
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxSecretStore issue

Post by PB »

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

Code: Select all

pass = secret.GetAsString(wxMBConvUTF16());
However, according to the Microsoft's docs,
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.
Is wxSecretStore is supposed to be compatible with the data created with Credential Manager? On MSW wxSecretStore stores the password as UTF-8 encoded.
diogom12
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Jun 13, 2020 6:07 am

Re: wxSecretStore issue

Post by diogom12 »

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..
GlFox
In need of some credit
In need of some credit
Posts: 1
Joined: Wed Oct 19, 2022 2:27 pm

Re: wxSecretStore issue

Post by GlFox »

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*...
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSecretStore issue

Post by doublemax »

GlFox 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.
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/issues
Use the source, Luke!
Post Reply