diff --git a/resources/lib/utils.php b/resources/lib/utils.php index 9c281145..1d06c737 100644 --- a/resources/lib/utils.php +++ b/resources/lib/utils.php @@ -5,6 +5,7 @@ use UnityWebPortal\lib\exceptions\EncodingUnknownException; use UnityWebPortal\lib\exceptions\EncodingConversionException; use phpseclib3\Crypt\PublicKeyLoader; +use phpseclib3\Exception\NoKeyLoadedException; // like assert() but not subject to zend.assertions config function ensure(bool $condition, ?string $message = null): void @@ -16,24 +17,10 @@ function ensure(bool $condition, ?string $message = null): void function testValidSSHKey(string $key_str): bool { - // key loader still throws, these just mute warnings for phpunit - // https://github.com/phpseclib/phpseclib/issues/2079 - if ($key_str == "") { - return false; - } - // https://github.com/phpseclib/phpseclib/issues/2076 - // https://github.com/phpseclib/phpseclib/issues/2077 - // there are actually valid JSON keys (JWK), but I don't think anybody uses it - if (!is_null(@json_decode($key_str))) { - return false; - } try { PublicKeyLoader::load($key_str); return true; - // phpseclib should throw only NoKeyLoadedException but that is not the case - // https://github.com/phpseclib/phpseclib/pull/2078 - // } catch (\phpseclib3\Exception\NoKeyLoadedException $e) { - } catch (\Throwable $e) { + } catch (NoKeyLoadedException $e) { return false; } }