Skip to content

Add secondary user locale (region) to string lookup #18

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions AuthenticatorChooser/I18N.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum Key {

private const uint MUI_LANGUAGE_NAME = 8;

public static string userLocaleName { get; } = CultureInfo.CurrentUICulture.Name;
public static string userLocaleName { get; } = CultureInfo.CurrentCulture.Name;
public static string userUiLocaleName { get; } = CultureInfo.CurrentUICulture.Name;
public static string systemLocaleName { get; } = getCurrentSystemLocaleName();
private static CultureInfo systemCulture { get; } = CultureInfo.GetCultureInfo(systemLocaleName);

Expand All @@ -32,22 +33,27 @@ static I18N() {
StringTableResource.Register();

string systemRoot = Environment.GetEnvironmentVariable("SystemRoot") ?? "C:\\Windows";
// #2: CredentialUIBroker.exe runs as the current user
IList<string?> fidoCredProvStrings = getPeFileStrings(Path.Combine(systemRoot, "System32", userLocaleName, "fidocredprov.dll.mui"), [
IList<(int stringTableId, int stringTableEntryId)> queries = [
(15, 230), // Security key
(15, 231), // Smartphone; also appears in webauthn.dll.mui string table 4 entries 50 and 56
(15, 232) // Windows
]);
];

// #2: CredentialUIBroker.exe runs as the current user
IList<string?> fidoCredProvStringsUiLocale = getPeFileStrings(Path.Combine(systemRoot, "System32", userUiLocaleName, "fidocredprov.dll.mui"), queries);

// User might have configured a second locale
IList<string?> fidoCredProvStringsLocale = getPeFileStrings(Path.Combine(systemRoot, "System32", userLocaleName, "fidocredprov.dll.mui"), queries);

// #2: CryptSvc runs as NETWORK SERVICE
IList<string?> webauthnStrings = getPeFileStrings(Path.Combine(systemRoot, "System32", systemLocaleName, "webauthn.dll.mui"), [
(4, 53) // Sign In With Your Passkey title; entry 63 has the same value, not sure which one is used
]);

STRINGS = new Dictionary<Key, IList<string>> {
[Key.SECURITY_KEY] = getUniqueNonNullStrings(Strings.securityKey, fidoCredProvStrings[0]),
[Key.SMARTPHONE] = getUniqueNonNullStrings(Strings.smartphone, fidoCredProvStrings[1]),
[Key.WINDOWS] = getUniqueNonNullStrings(Strings.windows, fidoCredProvStrings[2]),
[Key.SECURITY_KEY] = getUniqueNonNullStrings(Strings.securityKey, fidoCredProvStringsUiLocale[0], fidoCredProvStringsLocale[0]),
[Key.SMARTPHONE] = getUniqueNonNullStrings(Strings.smartphone, fidoCredProvStringsUiLocale[1], fidoCredProvStringsLocale[1]),
[Key.WINDOWS] = getUniqueNonNullStrings(Strings.windows, fidoCredProvStringsUiLocale[2], fidoCredProvStringsLocale[2]),
[Key.SIGN_IN_WITH_YOUR_PASSKEY] = getUniqueNonNullStrings(Strings.ResourceManager.GetString(nameof(Strings.signInWithYourPasskey), systemCulture),
webauthnStrings[0]),
}.ToFrozenDictionary();
Expand Down
2 changes: 1 addition & 1 deletion AuthenticatorChooser/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public int OnExecute() {
logger.Info("{name} {version} starting", PROGRAM_NAME, PROGRAM_VERSION);
(string name, string marketingVersion, Version version, string arch) os = getOsVersion();
logger.Info("Operating system is {name} {marketingVersion} {version} {arch}", os.name, os.marketingVersion, os.version, os.arch);
logger.Info("Locales are {userLocale} (user) and {systemLocale} (system)", I18N.userLocaleName, I18N.systemLocaleName);
logger.Info("Locales are {userUiLocale} (user UI), {userLocale} (user) and {systemLocale} (system)", I18N.userUiLocaleName, I18N.userLocaleName, I18N.systemLocaleName);

using WindowOpeningListener windowOpeningListener = new WindowOpeningListenerImpl();
windowOpeningListener.windowOpened += (_, window) => SecurityKeyChooser.chooseUsbSecurityKey(window);
Expand Down