Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| WebAuthnAuthenticationRequest | |
0.00% |
0 / 32 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| describeCredentials | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getFieldInfo | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
6 | |||
| loadFromSubmission | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getSubmittedData | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | namespace MediaWiki\Extension\OATHAuth\Auth; |
| 7 | |
| 8 | use MediaWiki\Auth\AuthenticationRequest; |
| 9 | use MediaWiki\Language\RawMessage; |
| 10 | |
| 11 | class WebAuthnAuthenticationRequest extends AuthenticationRequest { |
| 12 | |
| 13 | public string $credential; |
| 14 | |
| 15 | /** |
| 16 | * @param string $authInfo Serialized JSON blob obtained from |
| 17 | * WebAuthnAuthenticator::startAuthentication() |
| 18 | * @param bool $showPrompt Whether to display the prompt telling the user to use their security key. |
| 19 | */ |
| 20 | public function __construct( |
| 21 | public string $authInfo, |
| 22 | public bool $showPrompt = true |
| 23 | ) { |
| 24 | } |
| 25 | |
| 26 | /** @inheritDoc */ |
| 27 | public function describeCredentials() { |
| 28 | return [ |
| 29 | 'provider' => wfMessage( 'oathauth-describe-provider' ), |
| 30 | 'account' => new RawMessage( '$1', [ $this->username ] ), |
| 31 | ] + parent::describeCredentials(); |
| 32 | } |
| 33 | |
| 34 | /** @inheritDoc */ |
| 35 | public function getFieldInfo() { |
| 36 | return ( $this->showPrompt ? [ |
| 37 | 'label' => [ |
| 38 | 'type' => 'null', |
| 39 | 'value' => wfMessage( 'oathauth-webauthn-ui-login-prompt' ), |
| 40 | // TODO: Use a different message for help? |
| 41 | 'help' => wfMessage( 'oathauth-webauthn-ui-login-prompt' ), |
| 42 | ] |
| 43 | ] : [] ) + [ |
| 44 | // The hidden auth_info field only exists to send the authInfo JSON blob to the client. |
| 45 | // It's not used for authentication and ignored when submitted back to us, we get the |
| 46 | // authInfo blob from the session instead. |
| 47 | 'auth_info' => [ |
| 48 | 'type' => 'hidden', |
| 49 | 'value' => $this->authInfo, |
| 50 | 'label' => wfMessage( 'oathauth-webauthn-authentication-info-label' ), |
| 51 | 'help' => wfMessage( 'oathauth-webauthn-authentication-info-help' ), |
| 52 | ], |
| 53 | 'credential' => [ |
| 54 | 'type' => 'hidden', |
| 55 | 'value' => '', |
| 56 | 'label' => wfMessage( 'oathauth-webauthn-credential-label' ), |
| 57 | 'help' => wfMessage( 'oathauth-webauthn-credential-help' ), |
| 58 | ] |
| 59 | ]; |
| 60 | } |
| 61 | |
| 62 | /** @inheritDoc */ |
| 63 | public function loadFromSubmission( array $data ) { |
| 64 | if ( !isset( $data['credential'] ) ) { |
| 65 | return false; |
| 66 | } |
| 67 | $this->credential = $data['credential']; |
| 68 | |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | public function getSubmittedData(): array { |
| 73 | // Don't trust the submitted auth_info, otherwise the user could control which challenge |
| 74 | // we're validating against and do a replay attack. Instead, we use the authInfo blob |
| 75 | // in the session, which we stored there when we issued the challenge. |
| 76 | return [ |
| 77 | 'credential' => $this->credential |
| 78 | ]; |
| 79 | } |
| 80 | } |