mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 00:29:54 +00:00
EncryptionContext: Allow passing encryption algo as a constructor parameter
This commit is contained in:
parent
cc00b3e19b
commit
0df2677464
@ -670,7 +670,7 @@ class NetworkSession{
|
|||||||
}
|
}
|
||||||
$this->sendDataPacket(ServerToClientHandshakePacket::create($handshakeJwt), true); //make sure this gets sent before encryption is enabled
|
$this->sendDataPacket(ServerToClientHandshakePacket::create($handshakeJwt), true); //make sure this gets sent before encryption is enabled
|
||||||
|
|
||||||
$this->cipher = new EncryptionContext($encryptionKey);
|
$this->cipher = new EncryptionContext($encryptionKey, EncryptionContext::ENCRYPTION_SCHEME);
|
||||||
|
|
||||||
$this->setHandler(new HandshakePacketHandler(function() : void{
|
$this->setHandler(new HandshakePacketHandler(function() : void{
|
||||||
$this->onServerLoginSuccess();
|
$this->onServerLoginSuccess();
|
||||||
|
@ -32,7 +32,7 @@ use function strlen;
|
|||||||
use function substr;
|
use function substr;
|
||||||
|
|
||||||
class EncryptionContext{
|
class EncryptionContext{
|
||||||
private const ENCRYPTION_SCHEME = "AES-256-GCM";
|
public const ENCRYPTION_SCHEME = "AES-256-GCM";
|
||||||
private const CHECKSUM_ALGO = "sha256";
|
private const CHECKSUM_ALGO = "sha256";
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
@ -43,22 +43,22 @@ class EncryptionContext{
|
|||||||
|
|
||||||
/** @var Cipher */
|
/** @var Cipher */
|
||||||
private $decryptCipher;
|
private $decryptCipher;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $decryptCounter = 0;
|
private $decryptCounter = 0;
|
||||||
|
|
||||||
/** @var Cipher */
|
/** @var Cipher */
|
||||||
private $encryptCipher;
|
private $encryptCipher;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $encryptCounter = 0;
|
private $encryptCounter = 0;
|
||||||
|
|
||||||
public function __construct(string $encryptionKey){
|
public function __construct(string $encryptionKey, string $algorithm){
|
||||||
$this->key = $encryptionKey;
|
$this->key = $encryptionKey;
|
||||||
|
|
||||||
$this->decryptCipher = new Cipher(self::ENCRYPTION_SCHEME);
|
$this->decryptCipher = new Cipher($algorithm);
|
||||||
$ivLength = $this->decryptCipher->getIVLength();
|
$ivLength = $this->decryptCipher->getIVLength();
|
||||||
$this->decryptCipher->decryptInit($this->key, substr($this->key, 0, $ivLength));
|
$this->decryptCipher->decryptInit($this->key, substr($this->key, 0, $ivLength));
|
||||||
|
|
||||||
$this->encryptCipher = new Cipher(self::ENCRYPTION_SCHEME);
|
$this->encryptCipher = new Cipher($algorithm);
|
||||||
$ivLength = $this->encryptCipher->getIVLength();
|
$ivLength = $this->encryptCipher->getIVLength();
|
||||||
$this->encryptCipher->encryptInit($this->key, substr($this->key, 0, $ivLength));
|
$this->encryptCipher->encryptInit($this->key, substr($this->key, 0, $ivLength));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user