/** * @Override */ public function get($property, $default = null) { if ($property == 'length') { return 5 + $this->encLength; } return parent::get($property); }
/** * @Override */ public function decode() { $conn = $this->conn; $core = $conn->getCore(); $cipherSuite = $core->cipherSuite; $sharedKey = $conn->Key; $ivLen = $cipherSuite->getIVLen(); $macLen = $cipherSuite->getMACLen(); $MAC = $this->calculateMAC(); $IV = Core::getRandom($ivLen); $data = $this->payload . $MAC; // Calculate and append padding $fpd = function ($l, $bz) { return $l + $bz - $l % $bz - $l; }; $paddingLength = $fpd(strlen($this->payload . $MAC) + 1, $ivLen); $data .= Core::_pack('C', $paddingLength); $encData = $cipherSuite->blockEncrypt($data, $sharedKey, $IV); if (false === $encData) { throw new TLSAlertException(Alert::create(Alert::BAD_RECORD_MAC), "Cipher block encryption failed"); } $encData = $IV . $encData; $this->incrementSeq(); if ($this->contentType == ContentType::HANDSHAKE) { $core->countHandshakeMessages($this->payload); } $this->set('payload', $encData); return parent::decode(); }