mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-15 19:46:20 +00:00
Move PHP minimum to 8.0
This commit is contained in:
@@ -97,12 +97,9 @@ final class JwtUtils{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \OpenSSLAsymmetricKey|resource $signingKey
|
||||
* @phpstan-param PhpOpenSSLAsymmetricKey $signingKey
|
||||
*
|
||||
* @throws JwtException
|
||||
*/
|
||||
public static function verify(string $jwt, $signingKey) : bool{
|
||||
public static function verify(string $jwt, \OpenSSLAsymmetricKey $signingKey) : bool{
|
||||
[$header, $body, $signature] = self::split($jwt);
|
||||
|
||||
$plainSignature = self::b64UrlDecode($signature);
|
||||
@@ -133,13 +130,10 @@ final class JwtUtils{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \OpenSSLAsymmetricKey|resource $signingKey
|
||||
* @phpstan-param PhpOpenSSLAsymmetricKey $signingKey
|
||||
*
|
||||
* @phpstan-param array<string, mixed> $header
|
||||
* @phpstan-param array<string, mixed> $claims
|
||||
*/
|
||||
public static function create(array $header, array $claims, $signingKey) : string{
|
||||
public static function create(array $header, array $claims, \OpenSSLAsymmetricKey $signingKey) : string{
|
||||
$jwtBody = JwtUtils::b64UrlEncode(json_encode($header, JSON_THROW_ON_ERROR)) . "." . JwtUtils::b64UrlEncode(json_encode($claims, JSON_THROW_ON_ERROR));
|
||||
|
||||
openssl_sign(
|
||||
@@ -190,11 +184,7 @@ final class JwtUtils{
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \OpenSSLAsymmetricKey|resource $opensslKey
|
||||
* @phpstan-param PhpOpenSSLAsymmetricKey $opensslKey
|
||||
*/
|
||||
public static function emitDerPublicKey($opensslKey) : string{
|
||||
public static function emitDerPublicKey(\OpenSSLAsymmetricKey $opensslKey) : string{
|
||||
$details = openssl_pkey_get_details($opensslKey);
|
||||
if($details === false){
|
||||
throw new AssumptionFailedError("Failed to get details from OpenSSL key resource");
|
||||
@@ -211,11 +201,7 @@ final class JwtUtils{
|
||||
throw new AssumptionFailedError("OpenSSL resource contains invalid public key");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \OpenSSLAsymmetricKey|resource
|
||||
* @phpstan-return PhpOpenSSLAsymmetricKey
|
||||
*/
|
||||
public static function parseDerPublicKey(string $derKey){
|
||||
public static function parseDerPublicKey(string $derKey) : \OpenSSLAsymmetricKey{
|
||||
$signingKeyOpenSSL = openssl_pkey_get_public(sprintf("-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n", base64_encode($derKey)));
|
||||
if($signingKeyOpenSSL === false){
|
||||
throw new JwtException("OpenSSL failed to parse key: " . openssl_error_string());
|
||||
|
@@ -40,13 +40,7 @@ final class EncryptionUtils{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \OpenSSLAsymmetricKey|resource $localPriv
|
||||
* @param \OpenSSLAsymmetricKey|resource $remotePub
|
||||
* @phpstan-param PhpOpenSSLAsymmetricKey $localPriv
|
||||
* @phpstan-param PhpOpenSSLAsymmetricKey $remotePub
|
||||
*/
|
||||
public static function generateSharedSecret($localPriv, $remotePub) : \GMP{
|
||||
public static function generateSharedSecret(\OpenSSLAsymmetricKey $localPriv, \OpenSSLAsymmetricKey $remotePub) : \GMP{
|
||||
$hexSecret = openssl_pkey_derive($remotePub, $localPriv, 48);
|
||||
if($hexSecret === false){
|
||||
throw new \InvalidArgumentException("Failed to derive shared secret: " . openssl_error_string());
|
||||
@@ -58,11 +52,7 @@ final class EncryptionUtils{
|
||||
return openssl_digest($salt . hex2bin(str_pad(gmp_strval($secret, 16), 96, "0", STR_PAD_LEFT)), 'sha256', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \OpenSSLAsymmetricKey|resource $serverPriv
|
||||
* @phpstan-param PhpOpenSSLAsymmetricKey $serverPriv
|
||||
*/
|
||||
public static function generateServerHandshakeJwt($serverPriv, string $salt) : string{
|
||||
public static function generateServerHandshakeJwt(\OpenSSLAsymmetricKey $serverPriv, string $salt) : string{
|
||||
$derPublicKey = JwtUtils::emitDerPublicKey($serverPriv);
|
||||
return JwtUtils::create(
|
||||
[
|
||||
|
@@ -38,11 +38,7 @@ class PrepareEncryptionTask extends AsyncTask{
|
||||
|
||||
private const TLS_KEY_ON_COMPLETION = "completion";
|
||||
|
||||
/**
|
||||
* @var \OpenSSLAsymmetricKey|resource|null
|
||||
* @phpstan-var PhpOpenSSLAsymmetricKey|null
|
||||
*/
|
||||
private static $SERVER_PRIVATE_KEY = null;
|
||||
private static ?\OpenSSLAsymmetricKey $SERVER_PRIVATE_KEY = null;
|
||||
|
||||
/** @var string */
|
||||
private $serverPrivateKey;
|
||||
|
@@ -63,11 +63,7 @@ final class DedicatedQueryNetworkInterface implements AdvancedNetworkInterface{
|
||||
private $port;
|
||||
/** @var \Logger */
|
||||
private $logger;
|
||||
/**
|
||||
* @var \Socket|resource
|
||||
* @phpstan-var PhpSocket
|
||||
*/
|
||||
private $socket;
|
||||
private \Socket $socket;
|
||||
/** @var Network */
|
||||
private $network;
|
||||
/**
|
||||
|
Reference in New Issue
Block a user