-
Notifications
You must be signed in to change notification settings - Fork 93
Description
Issue Title: Authentication Failure (potential "bad decrypt" or silent failure) due to unavailable sodium functions (aes_cbc_*, random_bytes)
Issue Body:
Hi shinymanager team,
I'm experiencing persistent authentication issues with shinymanager in my specific environment. Despite careful configuration, login fails, sometimes showing "You are not authorized for this application" or, during tests with simple passphrases, "bad decrypt" errors. The most notable characteristic is that the auth_info_rv$user reactiveValue does not update after a login attempt, suggesting a very early failure in the check_credentials process.
Environment:
Operating System: Windows 11 Pro
R Version: RStudio 2023.12.0+369 "Ocean Storm" Release (33206f75bd14d07d84753f965eaa24756eda97b7, 2023-12-17) for windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.12.0+369 Chrome/116.0.5845.190 Electron/26.2.4 Safari/537.36
Package Versions:
shinymanager: 1.0.410 (from CRAN) and also tested with 1.0.510 (dev version from GitHub datastorm-open/shinymanager@HEAD)
sodium: 1.4.0 (from CRAN)
RSQLite: 2.3.11 (from CRAN)
DBI: 1.2.3 (from CRAN)
(Managed with renv 1.0.7)
Problem Description:
Authentication consistently fails.
The database.sqlite is created correctly using shinymanager::create_db() with a passphrase and an admin user (admin = TRUE, applications = "").
The Shiny application (both a minimal test app and the main application) starts, and the passphrase in check_credentials() matches the one used to create the database.
When attempting to log in with the correct credentials, the UI displays "You are not authorized for this application."
Crucially, the auth_info_rv reactiveValue (returned by secure_server) shows no updates to its fields (user, admin, authorized) after the login attempt. An observer on these values does not trigger post-login.
In earlier tests with a very simple passphrase ("test"), an explicit error was observed: OpenSSL error: ... bad decrypt ... ciphercommon_block.c:124:.
Investigation Steps and Key Findings:
After extensive debugging, we have identified the following:
The passphrase matches between DB creation and its use in the application.
The database is created correctly and contains the admin user entry.
The issue persists in a minimal, self-contained Shiny application that first creates the DB and then attempts authentication.
Main Finding: An inspection of my sodium package installation (v1.4.0 on Windows) using ls("package:sodium") reveals that it does NOT export the functions aes_cbc_encrypt, aes_cbc_decrypt, or random_bytes under those exact names.
The list of functions exported by my sodium includes data_encrypt, data_decrypt, and random.
A direct, isolated test using sodium::data_encrypt() and sodium::data_decrypt() (with the same "test" passphrase and a key derived using sodium::sha256()) works perfectly on my system, correctly encrypting and decrypting test data.
The hypothesis is that shinymanager is internally attempting to call sodium's aes_cbc_* or random_bytes functions. As these are not available in my specific build of sodium for Windows/R 4.3, the decryption process within shinymanager fails, leading to the observed "bad decrypt" error or the silent failure.
List of functions exported by ls("package:sodium") on my system:
[1] "argon2" "auth_decrypt" "auth_encrypt" "bin2hex"
[5] "chacha20" "data_decrypt" "data_encrypt" "data_tag"
[9] "diffie_hellman" "hash" "hex2bin" "keygen"
[13] "password_store" "password_verify" "pubkey" "random"
[17] "salsa20" "scrypt" "sha256" "sha512"
[21] "shorthash" "sig_keygen" "sig_pubkey" "sig_sign"
[25] "sig_verify" "simple_decrypt" "simple_encrypt" "xchacha20"
[29] "xsalsa20"
Suggestion / Question for Developers:
Would it be possible for shinymanager to check for the availability of aes_cbc_encrypt/decrypt and random_bytes functions in the user's sodium environment and, if they are not available, fall back to using more general and robust alternatives like data_encrypt/data_decrypt (which handle nonces internally) and random?
Alternatively, are there specific system dependencies or compilation flags for sodium on Windows that users should ensure are met to guarantee all sodium functions expected by shinymanager are present?
Thank you for your time and any assistance you can provide. This incompatibility is currently blocking the use of shinymanager with passphrase encryption in my environment.
Best regards,
Bismarck Bejarano