verify_file_signature( string $filename, string|array $signatures, string|false $filename_for_errors = false ): bool|WP_Error
- Since
- 5.2.0
- Source
wp-admin/includes/file.php:1387
Compatibility
- WordPress
- since 5.2.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$filenamestring- The file to validate.
$signaturesstring|array- A Signature provided for the file.
$filename_for_errorsstring|falseoptional- A friendly filename for errors.Default:
false
Return value
bool|WP_Error- True on success, false if verification not attempted, or WP_Error describing an error condition.
Performance profile
How much work a call to verify_file_signature() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 29–64
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 135.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below verify_file_signature()
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost verify_file_signature() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 29 | array_map(), __(), esc_html(), sprintf() |
| always | 31 | array_map(), __(), esc_html(), sprintf(), filename() |
| always | 33 | wp_basename(), array_map(), __(), esc_html(), sprintf() |
| always | 35 | wp_basename(), array_map(), __(), esc_html(), sprintf(), filename() |
!$signatures && !$trusted_keys && sodium_crypto_sign_verify_detached() | 56 | array_map(), wp_trusted_keys(), hash_file(), mbstring_binary_safe_encoding(), base64_decode(), base64_decode(), sodium_crypto_sign_verify_detached(), reset_mbstring_encoding() |
| always | 59–60 | array_map(), wp_trusted_keys(), hash_file(), mbstring_binary_safe_encoding(), reset_mbstring_encoding(), __(), esc_html(), sprintf(), bin2hex(), filename() |
!$signatures && !$trusted_keys && sodium_crypto_sign_verify_detached() | 60 | wp_basename(), array_map(), wp_trusted_keys(), hash_file(), mbstring_binary_safe_encoding(), base64_decode(), base64_decode(), sodium_crypto_sign_verify_detached(), reset_mbstring_encoding() |
| always | 63–64 | wp_basename(), array_map(), wp_trusted_keys(), hash_file(), mbstring_binary_safe_encoding(), reset_mbstring_encoding(), __(), esc_html(), sprintf(), bin2hex(), filename() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 135 | 29–64 | 10 | |
| 8.5 | 135 | 29–64 | 10 | |
| 8.4 | 135 | 29–64 | 10 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 138 | 32–67 | 10 | 2 fewer instructions than PHP 8.2 |
| 8.2 | 140 | 34–69 | 10 | |
| 8.1 | 140 | 34–69 | 10 | |
| 7.4 | 140 | 34–69 | 10 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 11
- wp_basename()i18n-friendly version of basename().
- __()Retrieves the translation of $text.
- esc_html()Escaping for HTML blocks.
- wp_trusted_keys()Retrieves the list of signing keys trusted by WordPress.
- mbstring_binary_safe_encoding()Sets the mbstring internal encoding to a binary safe encoding when func_overload is enabled.
- sodium_crypto_sign_verify_detached()
- reset_mbstring_encoding()Resets the mbstring internal encoding to a users previously set encoding.
- bin2hex()
- WP_Error::__construct()Initializes the error.
- ParagonIE_Sodium_Compat::polyfill_is_fast()Will sodium_compat run fast on the current hardware and PHP configuration?
- ParagonIE_Sodium_Compat::runtime_speed_test()Runtime testing method for 32-bit platforms.
Used by · 1
- download_url()Downloads a URL to a local temporary file using the WordPress HTTP API.
Source code
function verify_file_signature( $filename, $signatures, $filename_for_errors = false ) { if ( ! $filename_for_errors ) { $filename_for_errors = wp_basename( $filename ); } // Check we can process signatures. if ( ! function_exists( 'sodium_crypto_sign_verify_detached' ) || ! in_array( 'sha384', array_map( 'strtolower', hash_algos() ), true ) ) { return new WP_Error( 'signature_verification_unsupported', sprintf( /* translators: %s: The filename of the package. */ __( 'The authenticity of %s could not be verified as signature verification is unavailable on this system.' ), '<span class="code">' . esc_html( $filename_for_errors ) . '</span>' ), ( ! function_exists( 'sodium_crypto_sign_verify_detached' ) ? 'sodium_crypto_sign_verify_detached' : 'sha384' ) ); } // Verify runtime speed of Sodium_Compat is acceptable. if ( ! extension_loaded( 'sodium' ) && ! ParagonIE_Sodium_Compat::polyfill_is_fast() ) { $sodium_compat_is_fast = false; // Allow for an old version of Sodium_Compat being loaded before the bundled WordPress one. if ( method_exists( 'ParagonIE_Sodium_Compat', 'runtime_speed_test' ) ) { /* * Run `ParagonIE_Sodium_Compat::runtime_speed_test()` in optimized integer mode, * as that's what WordPress utilizes during signing verifications. */ // phpcs:disable WordPress.NamingConventions.ValidVariableName $old_fastMult = ParagonIE_Sodium_Compat::$fastMult; ParagonIE_Sodium_Compat::$fastMult = true; $sodium_compat_is_fast = ParagonIE_Sodium_Compat::runtime_speed_test( 100, 10 ); ParagonIE_Sodium_Compat::$fastMult = $old_fastMult; // phpcs:enable } /* * This cannot be performed in a reasonable amount of time. * https://github.com/paragonie/sodium_compat#help-sodium_compat-is-slow-how-can-i-make-it-fast */ if ( ! $sodium_compat_is_fast ) { return new WP_Error( 'signature_verification_unsupported', sprintf( /* translators: %s: The filename of the package. */ __( 'The authenticity of %s could not be verified as signature verification is unavailable on this system.' ), '<span class="code">' . esc_html( $filename_for_errors ) . '</span>' ), array( 'php' => PHP_VERSION, 'sodium' => defined( 'SODIUM_LIBRARY_VERSION' ) ? SODIUM_LIBRARY_VERSION : ( defined( 'ParagonIE_Sodium_Compat::VERSION_STRING' ) ? ParagonIE_Sodium_Compat::VERSION_STRING : false ), 'polyfill_is_fast' => false, 'max_execution_time' => ini_get( 'max_execution_time' ), ) ); } } if ( ! $signatures ) { return new WP_Error( 'signature_verification_no_signature', sprintf( /* translators: %s: The filename of the package. */ __( 'The authenticity of %s could not be verified as no signature was found.' ), '<span class="code">' . esc_html( $filename_for_errors ) . '</span>' ), array( 'filename' => $filename_for_errors, ) ); } $trusted_keys = wp_trusted_keys(); $file_hash = hash_file( 'sha384', $filename, true ); mbstring_binary_safe_encoding(); $skipped_key = 0; $skipped_signature = 0;Changelog
Introduced in 5.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-admin/includes/file.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.