- Debian 13 (Trixie) compatibility: - Build uw-imap c-client from source (removed from trixie) - Fix OpenSSL 3 include paths for c-client - Split libnginx-mod-http-brotli package name - Add -lgomp and -std=c++17 to PHP CXXFLAGS - Fix Dovecot 2.4 config syntax in setup - Use 127.0.0.1 for DB (works in FPM chroot) - PHP version updates: - Add PHP 8.5.4 and 8.4.19 - Remove PHP 8.1 (EOL) - Update igbinary to master, imagick to 3.8.1, brotli to 0.18.3 - Remove php-rar (unmaintained, incompatible with 8.4+) - setup.php uses DEFAULT_PHP_VERSION for FPM sockets - Users can switch PHP version from dashboard - Security hardening: - CSRF tokens use bin2hex(random_bytes(32)) - Admin password uses password_hash/password_verify - Session regeneration on login - All output escaped with htmlspecialchars - Nginx rewrite rules validated (flag whitelist, reject injection) - Path traversal protection in FileManager - SQL injection fix in password change - Security headers (CSP script-src:none, X-Frame-Options, etc) - Onion private keys encrypted at rest (libsodium) - SFTP password encrypted in session with expiry - Admin brute-force rate limiting - CSRF token on login form - Zero JavaScript - all pages work without JS - mt_rand replaced with random_int - Cookie secure flag precedence fix - PDO ERRMODE_EXCEPTION - Generic login error messages (no username enumeration) - FileManager rename validation - Self-bootstrapping install.sh: - Auto-clones repo if run standalone (curl | bash support) - Interactive prompts or --non-interactive flag - Optional vanity .onion generation via mkp224o - Password generation or custom input - Credentials saved to /root/hosting-credentials.txt
81 lines
3.2 KiB
PHP
81 lines
3.2 KiB
PHP
<?php
|
|
require('../common.php');
|
|
$user=check_login();
|
|
print_header(_('PGP 2FA'));
|
|
dashboard_menu($user, 'pgp.php');
|
|
if($_SERVER['REQUEST_METHOD']==='POST'){
|
|
if($error=check_csrf_error()){
|
|
die($error);
|
|
}
|
|
if(isset($_POST['pgp_key'])){
|
|
$pgp_key = trim($_POST['pgp_key']);
|
|
$gpg = gnupg_init();
|
|
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
|
gnupg_setarmor($gpg, 1);
|
|
$imported_key = gnupg_import($gpg, $pgp_key);
|
|
if(!$imported_key){
|
|
echo '<p role="alert" style="color:red">'._('There was an error importing the key').'</p>';
|
|
}else{
|
|
$db = get_db_instance();
|
|
$stmt = $db->prepare('UPDATE users SET pgp_key = ?, tfa = 0, pgp_verified = 0 WHERE id = ?;');
|
|
$stmt->execute([$pgp_key, $user['id']]);
|
|
$user['pgp_key'] = $pgp_key;
|
|
}
|
|
}
|
|
if(isset($_POST['enable_2fa_code'])){
|
|
if($_POST['enable_2fa_code'] !== $_SESSION['enable_2fa_code']){
|
|
echo '<p role="alert" style="color:red">'._('Sorry, the code was incorrect').'</p>';
|
|
} else {
|
|
$db = get_db_instance();
|
|
$stmt = $db->prepare('UPDATE users SET tfa = 1, pgp_verified = 1 WHERE id = ?;');
|
|
$stmt->execute([$user['id']]);
|
|
$user['tfa'] = 1;
|
|
}
|
|
}
|
|
}
|
|
if(!empty($user['pgp_key'])){
|
|
if($user['tfa'] == '1'){
|
|
echo '<p role="alert" style="color:green">'._('Yay, PGP based 2FA is enabled!').'</p>';
|
|
} else {
|
|
$gpg = gnupg_init();
|
|
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
|
|
gnupg_setarmor($gpg, 1);
|
|
$imported_key = gnupg_import($gpg, $user['pgp_key']);
|
|
if($imported_key){
|
|
$key_info = gnupg_keyinfo($gpg, $imported_key['fingerprint']);
|
|
foreach($key_info as $key){
|
|
if(!$key['can_encrypt']){
|
|
echo '<p>'._("Sorry, this key can't be used to encrypt a message to you. Your key may have expired or has been revoked.").'</p>';
|
|
}else{
|
|
foreach($key['subkeys'] as $subkey){
|
|
gnupg_addencryptkey($gpg, $subkey['fingerprint']);
|
|
}
|
|
}
|
|
}
|
|
$_SESSION['enable_2fa_code'] = bin2hex(random_bytes(3));
|
|
if($encrypted = gnupg_encrypt($gpg, _('To enable 2FA, please enter the following code to confirm ownership of your key:')."\n\n$_SESSION[enable_2fa_code]\n")){
|
|
echo '<p>'._('To enable 2FA using your PGP key, please decrypt the following PGP encrypted message and confirm the code:').'</p>';
|
|
echo '<textarea readonly="readonly" rows="10" cols="70">'.htmlspecialchars($encrypted, ENT_QUOTES, 'UTF-8').'</textarea>';
|
|
?>
|
|
<form action="pgp.php" method="post"><input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
|
|
<table border="1">
|
|
<tr><td><input type="text" name="enable_2fa_code"></td><td><button type="submit"><?php echo _('Confirm'); ?></button></td></tr>
|
|
</table></form>
|
|
<hr>
|
|
<?php
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<p><?php echo _('Add your PGP key for more security features like 2FA:'); ?></p>
|
|
<form action="pgp.php" method="post">
|
|
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
|
|
<table border="1">
|
|
<tr><td><textarea name="pgp_key" rows="10" cols="70"><?php echo htmlspecialchars($user['pgp_key'], ENT_QUOTES, 'UTF-8'); ?></textarea></td></tr>
|
|
<tr><td><button type="submit"><?php echo _('Update PGP key'); ?></button></td></tr>
|
|
</table>
|
|
</form>
|
|
<p><a href="home.php"><?php echo _('Go back to dashboard'); ?></a></p>
|
|
</body></html>
|