rescuepayloadstorage
2 weeks ago
MfaBackupCodes.php
2 weeks ago
MfaBackupCodesInterface.php
2 weeks ago
MfaEndpoint.php
2 weeks ago
MfaEndpointInterface.php
2 weeks ago
MfaManager.php
2 weeks ago
MfaSettings.php
2 weeks ago
MfaSettingsInterface.php
2 weeks ago
MfaValidator.php
2 weeks ago
RescueCode.php
2 weeks ago
MfaBackupCodesInterface.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace LLAR\Core\Mfa; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; |
| 7 | } |
| 8 | |
| 9 | /** |
| 10 | * Interface for MFA backup/rescue codes service. |
| 11 | * Implementations: generation, encryption, rescue URLs, PDF HTML. |
| 12 | * |
| 13 | * Used for testability: MfaManager can depend on this interface. |
| 14 | */ |
| 15 | interface MfaBackupCodesInterface { |
| 16 | |
| 17 | /** |
| 18 | * Encrypt plain code for storage. OpenSSL only; returns false if unavailable. |
| 19 | * |
| 20 | * @param string $plain_code Plain rescue code. |
| 21 | * @param string $salt Salt (e.g. AUTH_SALT). |
| 22 | * @return string|false Base64-encoded ciphertext or false if OpenSSL unavailable/failure. |
| 23 | */ |
| 24 | public function encrypt_code( $plain_code, $salt = '' ); |
| 25 | |
| 26 | /** |
| 27 | * Decrypt stored blob. OpenSSL only; returns false if unavailable or invalid. |
| 28 | * |
| 29 | * @param string $encrypted_data Base64-encoded (iv + ciphertext). |
| 30 | * @return string|false Plain code or false. |
| 31 | */ |
| 32 | public function decrypt_code( $encrypted_data ); |
| 33 | |
| 34 | /** |
| 35 | * Generate rescue codes and return plain values. |
| 36 | * Persisting hashes is handled by MFA settings submit flow after confirmation. |
| 37 | * |
| 38 | * @return array Plain codes. |
| 39 | * @throws \Exception When hashing fails. |
| 40 | */ |
| 41 | public function generate(); |
| 42 | |
| 43 | /** |
| 44 | * Build rescue URL for a plain code and store encrypted payload. OpenSSL required. |
| 45 | * |
| 46 | * @param string $plain_code Plain rescue code. |
| 47 | * @return string Rescue URL. |
| 48 | * @throws \Exception When OpenSSL unavailable or encryption fails. |
| 49 | */ |
| 50 | public function get_rescue_url( $plain_code ); |
| 51 | |
| 52 | /** |
| 53 | * Generate HTML for rescue PDF. Caller must pass rescue_urls (from get_rescue_url for each code). |
| 54 | * |
| 55 | * @param array $rescue_urls List of rescue URLs. |
| 56 | * @return string HTML. |
| 57 | * @throws \Exception When template path invalid. |
| 58 | */ |
| 59 | public function generate_pdf_html( $rescue_urls ); |
| 60 | } |
| 61 |