Handle expired keys
This commit is contained in:
1 file changed
+17
-4
+17
-4
@@ -270,20 +270,32 @@ $gpg = gnupg_init();
|
||||
gnupg_seterrormode( $gpg, GNUPG_ERROR_WARNING );
|
||||
gnupg_setarmor( $gpg, 1 );
|
||||
$imported_key = gnupg_import( $gpg, $_SESSION[ 'pgp_key' ] );
|
||||
$key_valid = false;
|
||||
if ( $imported_key ){
|
||||
$key_info = gnupg_keyinfo( $gpg, $imported_key[ 'fingerprint' ] );
|
||||
foreach ( $key_info as $key ) {
|
||||
if ( $key[ 'can_encrypt' ] ) {
|
||||
foreach ( is_array( $key_info ) ? $key_info : [] as $key ) {
|
||||
if ( $key[ 'can_encrypt' ] && ! $key['expired'] && ! $key['revoked'] ) {
|
||||
foreach ( $key[ 'subkeys' ] as $subkey ) {
|
||||
gnupg_addencryptkey( $gpg, $subkey[ 'fingerprint' ] );
|
||||
if( $subkey[ 'can_encrypt' ] && ! $subkey['expired'] && ! $subkey['revoked'] ) {
|
||||
if(gnupg_addencryptkey( $gpg, $subkey[ 'fingerprint' ] )){
|
||||
$key_valid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$encrypted = gnupg_encrypt( $gpg, _('To login, please enter the following code to confirm ownership of your key:')."\n\n" . $_SESSION[ '2fa_code' ] . "\n" );
|
||||
}
|
||||
if ( ! $key_valid || ! $encrypted ) {
|
||||
unset( $_SESSION[ '2fa_code' ] );
|
||||
unset( $_SESSION[ 'pgp_key' ] );
|
||||
$msg .= '<div class="red" role="alert">'.htmlspecialchars(_('Your PGP key has expired, so PGP two-factor authentication was skipped for this login. Update your PGP key to restore PGP two-factor authentication.')).'</div>';
|
||||
} else {
|
||||
echo $msg;
|
||||
echo '<p>'.htmlspecialchars(_('To login, please decrypt the following PGP encrypted message and confirm the code:')).'</p>';
|
||||
echo "<pre>$encrypted</pre>";
|
||||
echo '<pre>'.htmlspecialchars( $encrypted ).'</pre>';
|
||||
?>
|
||||
<?php if ( $encrypted ) { ?>
|
||||
<form class="form_limit" action="manage_account.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION[ 'csrf_token' ]; ?>">
|
||||
<div class="row">
|
||||
@@ -293,6 +305,7 @@ echo "<pre>$encrypted</pre>";
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<?php } ?>
|
||||
</main></body>
|
||||
</html>
|
||||
<?php
|
||||
|
||||
Reference in new issue
Block a user