Skip to content
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

Secure credentials encoding issue on Mac #9

Open
snowbagoly opened this issue Jan 2, 2024 · 0 comments · May be fixed by #24
Open

Secure credentials encoding issue on Mac #9

snowbagoly opened this issue Jan 2, 2024 · 0 comments · May be fixed by #24

Comments

@snowbagoly
Copy link

snowbagoly commented Jan 2, 2024

Thanks for implementing this library, it's really useful! 🎉

I have bumped into a small issue while using it on Mac: if the username or the password contains any special characters, they are not stored and retrieved correctly. E.g. if I store the username "täst", it retrieves this string: 0x74C3A47374 "t\303\244st

My macOS version is Sonoma 14.0.

Here is the code that I use to store the credentials:

fun storeAccount(accountKey: String, urlKey: String, settings: ServerConfiguration) {
    val credentialStorage = StorageProvider.getCredentialStorage(true, StorageProvider.SecureOption.REQUIRED)
    val storedSettings = Settings()

    if (settings.url.isEmpty()) {
        storedSettings.remove(urlKey)
        credentialStorage.delete(accountKey)
        return
    }

    storedSettings.putString(urlKey, settings.url)
    if (settings.username.isEmpty()) {
        credentialStorage.delete(accountKey)
        return
    }

    val credentialsToStore = StoredCredential(settings.username, settings.password.toCharArray())
    credentialStorage.add(accountKey, credentialsToStore)
}

This is used to load them:

fun getAccount(accountKey: String, urlKey: String): ServerConfiguration {
    val storedSettings = Settings()
    val url = storedSettings.getString(urlKey, "")
    val credentialStorage = StorageProvider.getCredentialStorage(true, StorageProvider.SecureOption.REQUIRED)
    val credential: StoredCredential? = credentialStorage.get(accountKey)
    val username = credential?.username ?: ""
    val password = (credential?.password ?: CharArray(0)).joinToString("")
    return ServerConfiguration(url, username, password)
}

I also tested on Windows and there it worked without issues. (Not sure about Linux as I didn't manage to get it running at all due to some strange NPEs, I'm still looking into that.)

@snowbagoly snowbagoly changed the title Encoding issue on Mac Secure credentials encoding issue on Mac Jan 2, 2024
@abyss638 abyss638 linked a pull request Sep 17, 2024 that will close this issue
@abyss638 abyss638 linked a pull request Sep 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant