Skip to content

Commit

Permalink
WebAuthN: Disable EdDSA/Ed25519 for key registrations (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
dd32 authored May 22, 2023
1 parent d3aa77c commit 6a95fb3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions class-wporg-webauthn-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public function _add_filters() {
// Disable the admin UI if it needs revalidation.
add_action( 'show_user_security_settings', [ $this, '_show_user_security_settings' ], -1 );

// Disable EdDSA support for keys, to enable Android NFC to work with modern keys.
add_action( 'wp_ajax_webauthn_preregister', [ $this, '_remove_eddsa_alg' ], 1 );

// Extend the session revalidation after registering a new key.
add_action( 'wp_ajax_webauthn_register', [ $this, '_extend_revalidation' ], 1 );
}
Expand Down Expand Up @@ -125,6 +128,33 @@ public function _extend_revalidation() {
} );
}

/**
* Resolve Android NFC Security Key issues when a newer key is registered through a desktop client.
*
* This disables EdDSA (aka. ES25519) support, which Android NFC appears to lack.
*
* @see https://github.com/sjinks/wp-two-factor-provider-webauthn/issues/221#issuecomment-1539543124
*/
public function _remove_eddsa_alg() {
ob_start( function( $output ) {
$json = json_decode( $output );

if ( $json && ! empty( $json->data->options->pubKeyCredParams ) ) {
$json->data->options->pubKeyCredParams = array_values(
wp_list_filter(
$json->data->options->pubKeyCredParams,
[ 'alg' => -8 ],
'NOT'
)
);

$output = wp_json_encode( $json );
}

return $output;
} );
}

public function _clear_cache() {
wp_cache_delete( 'webauthn:' . get_current_user_id(), 'users' );
}
Expand Down
2 changes: 1 addition & 1 deletion wporg-two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function user_requires_2fa( $user ) : bool {
return false;
}
}
// @codeCoverageIgnoreEnd
// @codeCoverageIgnoreEnd

$required = false;

Expand Down

0 comments on commit 6a95fb3

Please sign in to comment.