-
Notifications
You must be signed in to change notification settings - Fork 81
Signature: Avoid PHP warning when algorithm
is not set
#1803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
429fd32
0559052
68fd2d7
df002b4
1f45bb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -297,7 +297,7 @@ public static function verify_http_signature( $request ) { | |||||||||||||||||
$algorithm = 'sha512'; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
if ( \base64_encode( \hash( $algorithm, $body, true ) ) !== $digest[1] ) { // phpcs:ignore | ||||||||||||||||||
if ( \base64_encode( \hash( $algorithm, $body, true ) ) !== $digest[1] ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable, WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode | ||||||||||||||||||
return new WP_Error( 'activitypub_signature', __( 'Invalid Digest header', 'activitypub' ), array( 'status' => 401 ) ); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
@@ -354,7 +354,7 @@ public static function get_remote_key( $key_id ) { | |||||||||||||||||
* @return string The signature algorithm. | ||||||||||||||||||
*/ | ||||||||||||||||||
public static function get_signature_algorithm( $signature_block ) { | ||||||||||||||||||
if ( $signature_block['algorithm'] ) { | ||||||||||||||||||
if ( isset( $signature_block['algorithm'] ) ) { | ||||||||||||||||||
obenland marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
switch ( $signature_block['algorithm'] ) { | ||||||||||||||||||
case 'rsa-sha-512': | ||||||||||||||||||
return 'sha512'; // hs2019 https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mediaformat While looking at this function I opened the spec that's linked to in the
The error that gets returned when there is no algorithm says "only rsa-sha256 and hs2019 are supported": wordpress-activitypub/includes/class-signature.php Lines 286 to 288 in 499bcad
Should the case statement test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @obenland I think the error message is correct, in that the declared algorithm should be either
The implementation actually derives the key from the digest header rather than the wordpress-activitypub/includes/class-signature.php Lines 294 to 298 in 499bcad
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@mediaformat Based on the doc you shared, I guess we shouldn't return an error if algorithm is not set? |
||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.