Added KnownTranslationKeys (generated) and start using it

This commit is contained in:
Dylan K. Taylor
2021-06-29 22:46:04 +01:00
parent f02817bcd3
commit 94e16f416d
57 changed files with 802 additions and 286 deletions

View File

@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\auth;
use FG\ASN1\Exception\ParserException;
use Mdanter\Ecc\Crypto\Key\PublicKeyInterface;
use Mdanter\Ecc\Serializer\PublicKey\DerPublicKeySerializer;
use pocketmine\lang\KnownTranslationKeys;
use pocketmine\network\mcpe\JwtException;
use pocketmine\network\mcpe\JwtUtils;
use pocketmine\network\mcpe\protocol\types\login\JwtChainLinkBody;
@ -133,14 +134,14 @@ class ProcessLoginTask extends AsyncTask{
if($currentPublicKey === null){
if(!$first){
throw new VerifyLoginException("%pocketmine.disconnect.invalidSession.missingKey");
throw new VerifyLoginException("%" . KnownTranslationKeys::POCKETMINE_DISCONNECT_INVALIDSESSION_MISSINGKEY);
}
//First link, check that it is self-signed
$currentPublicKey = $headers->x5u;
}elseif($headers->x5u !== $currentPublicKey){
//Fast path: if the header key doesn't match what we expected, the signature isn't going to validate anyway
throw new VerifyLoginException("%pocketmine.disconnect.invalidSession.badSignature");
throw new VerifyLoginException("%" . KnownTranslationKeys::POCKETMINE_DISCONNECT_INVALIDSESSION_BADSIGNATURE);
}
$derPublicKeySerializer = new DerPublicKeySerializer();
@ -156,7 +157,7 @@ class ProcessLoginTask extends AsyncTask{
try{
if(!JwtUtils::verify($jwt, $signingKey)){
throw new VerifyLoginException("%pocketmine.disconnect.invalidSession.badSignature");
throw new VerifyLoginException("%" . KnownTranslationKeys::POCKETMINE_DISCONNECT_INVALIDSESSION_BADSIGNATURE);
}
}catch(JwtException $e){
throw new VerifyLoginException($e->getMessage(), 0, $e);
@ -180,11 +181,11 @@ class ProcessLoginTask extends AsyncTask{
$time = time();
if(isset($claims->nbf) and $claims->nbf > $time + self::CLOCK_DRIFT_MAX){
throw new VerifyLoginException("%pocketmine.disconnect.invalidSession.tooEarly");
throw new VerifyLoginException("%" . KnownTranslationKeys::POCKETMINE_DISCONNECT_INVALIDSESSION_TOOEARLY);
}
if(isset($claims->exp) and $claims->exp < $time - self::CLOCK_DRIFT_MAX){
throw new VerifyLoginException("%pocketmine.disconnect.invalidSession.tooLate");
throw new VerifyLoginException("%" . KnownTranslationKeys::POCKETMINE_DISCONNECT_INVALIDSESSION_TOOLATE);
}
$currentPublicKey = $claims->identityPublicKey ?? null; //if there are further links, the next link should be signed with this