mbin
mbin copied to clipboard
Check if the openssl_sign went OK
In case openssl_sign fails the $signature will be null. Resulting into errors like this:
{"message":"Warning: openssl_sign(): Supplied key param cannot be coerced into a private key","context":{"exception":{"class":"ErrorException","message":"Warning: openssl_sign(): Supplied key param cannot be coerced into a private key","code":0,"file":"/var/www/kbin.melroy.org/html/src/Service/ActivityPub/ApHttpClient.php:504"}},"level":400,"level_name":"ERROR","channel":"php","datetime":"2024-09-09T21:33:35.100575+02:00","extra":{}}
{"message":"Error thrown while handling message App\\Message\\ActivityPub\\Outbox\\DeliverMessage. Sending for retry #2 using 3600000 ms delay. Error: \"Handling \"App\\Message\\ActivityPub\\Outbox\\DeliverMessage\" failed: base64_encode(): Argument #1 ($string) must be of type string, null given\"","context":{"class":"App\\Message\\ActivityPub\\Outbox\\DeliverMessage","message_id":3420233,"retryCount":2,"delay":3600000,"error":"Handling \"App\\Message\\ActivityPub\\Outbox\\DeliverMessage\" failed: base64_encode(): Argument #1 ($string) must be of type string, null given","exception":{"class":"Symfony\\Component\\Messenger\\Exception\\HandlerFailedException","message":"Handling \"App\\Message\\ActivityPub\\Outbox\\DeliverMessage\" failed: base64_encode(): Argument #1 ($string) must be of type string, null given","code":0,"file":"/var/www/kbin.melroy.org/html/vendor/symfony/messenger/Middleware/HandleMessageMiddleware.php:124","previous":{"class":"TypeError","message":"base64_encode(): Argument #1 ($string) must be of type string, null given","code":0,"file":"/var/www/kbin.melroy.org/html/src/Service/ActivityPub/ApHttpClient.php:505"}}},"level":300,"level_name":"WARNING","channel":"messenger","datetime":"2024-09-09T21:33:35.100878+02:00","extra":{}}
We can better check on the return value of openssl_sign to validate if the signature actually succeeded or not.
If not, we now log a better error message. And we leave out the Signature header for now. We could also throw an error and abort. Ideas are welcome here.
Also we now free the memory of the $key using the appropriate openssl_free_key method.