mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +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->cipher = new EncryptionContext($encryptionKey);
|
||||
$this->cipher = new EncryptionContext($encryptionKey, EncryptionContext::ENCRYPTION_SCHEME);
|
||||
|
||||
$this->setHandler(new HandshakePacketHandler(function() : void{
|
||||
$this->onServerLoginSuccess();
|
||||
|
@ -32,7 +32,7 @@ use function strlen;
|
||||
use function substr;
|
||||
|
||||
class EncryptionContext{
|
||||
private const ENCRYPTION_SCHEME = "AES-256-GCM";
|
||||
public const ENCRYPTION_SCHEME = "AES-256-GCM";
|
||||
private const CHECKSUM_ALGO = "sha256";
|
||||
|
||||
/** @var bool */
|
||||
@ -43,22 +43,22 @@ class EncryptionContext{
|
||||
|
||||
/** @var Cipher */
|
||||
private $decryptCipher;
|
||||
|
||||
/** @var int */
|
||||
private $decryptCounter = 0;
|
||||
|
||||
/** @var Cipher */
|
||||
private $encryptCipher;
|
||||
/** @var int */
|
||||
private $encryptCounter = 0;
|
||||
|
||||
public function __construct(string $encryptionKey){
|
||||
public function __construct(string $encryptionKey, string $algorithm){
|
||||
$this->key = $encryptionKey;
|
||||
|
||||
$this->decryptCipher = new Cipher(self::ENCRYPTION_SCHEME);
|
||||
$this->decryptCipher = new Cipher($algorithm);
|
||||
$ivLength = $this->decryptCipher->getIVLength();
|
||||
$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();
|
||||
$this->encryptCipher->encryptInit($this->key, substr($this->key, 0, $ivLength));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user