Fix identity provider gaps: a required provider is decided before any password or mail password is checked and the sign-in page says the same whatever was typed, account or not; required beats IMAP on the same domain; after five wrong passwords for an address in ten minutes its mail server isn't asked; Google signs in only Workspace accounts and Nextcloud has to say the address is verified; client secrets are sealed with the install key, with RMM's sealing moved to shared secretSeal and secretOpen; an IMAP server is tried when saved or turned on and Required waits for a first sign-in; joining, Forgot password, password links and welcome emails follow mail-password and required domains; Turn Off says who goes back to a password; 26.12.3 changelog entries

This commit is contained in:
johnnyq
2026-11-30 01:36:20 -05:00
parent 8ce7ad0789
commit adbd8866c2
18 changed files with 499 additions and 142 deletions

View File

@@ -228,6 +228,47 @@ function generateUserSessionKey($site_encryption_master_key) {
}
}
/*
* A secret an integration keeps - an RMM's API key, an identity provider's client secret - sealed
* with this install's key (backupEncryptionKey(), in config.php), so the database alone doesn't
* give it away and a backup restored with the key reads it. AES-256-GCM, 'enc1:' then base64 of
* IV, tag and ciphertext; $purpose keeps each kind's key apart. '' when the install has no key
* and config.php can't be written to make one.
*/
function secretSeal(#[\SensitiveParameter] string $plain, string $purpose): string
{
$key = secretSealKey($purpose);
if ($key === '' || $plain === '') {
return '';
}
$iv = random_bytes(12);
$tag = '';
$cipher = openssl_encrypt($plain, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $iv, $tag, '', 16);
return $cipher === false ? '' : 'enc1:' . base64_encode($iv . $tag . $cipher);
}
/** A secret as typed, from what secretSeal() kept - one saved before it was sealed is read as it is. '' when it can't be read: config.php's key was changed. */
function secretOpen(string $stored, string $purpose): string
{
if (!str_starts_with($stored, 'enc1:')) {
return $stored;
}
$raw = base64_decode(substr($stored, 5), true);
$key = secretSealKey($purpose);
if ($raw === false || strlen($raw) < 29 || $key === '') {
return '';
}
$plain = openssl_decrypt(substr($raw, 28), 'aes-256-gcm', $key, OPENSSL_RAW_DATA, substr($raw, 0, 12), substr($raw, 12, 16));
return $plain === false ? '' : $plain;
}
/** The key secretSeal() uses for $purpose - from this install's key. */
function secretSealKey(string $purpose): string
{
$install = function_exists('backupEncryptionKey') ? backupEncryptionKey() : '';
return $install === '' ? '' : hash('sha256', "itflow-$purpose-secrets|$install", true);
}
// Decrypts an encrypted password (website/asset credentials), returns it as a string
function decryptCredentialEntry($credential_password_ciphertext) {