Support the no-MDC (resync) case
This commit is contained in:
parent
47a7f6e25c
commit
8c60f4e37b
@ -37,10 +37,10 @@ class OpenPGP_Crypt_AES_TripleDES {
|
|||||||
|
|
||||||
if(strlen($p->encrypted_data) < 1) {
|
if(strlen($p->encrypted_data) < 1) {
|
||||||
if($epacket instanceof OpenPGP_IntegrityProtectedDataPacket) {
|
if($epacket instanceof OpenPGP_IntegrityProtectedDataPacket) {
|
||||||
$data = substr($cipher->decrypt($epacket->data . str_repeat("\0", $padAmount)), 0, strlen($epacket->data));
|
$data = substr($cipher->decrypt($epacket->data . str_repeat("\0", $padAmount)), 0, strlen($epacket->data));
|
||||||
$prefix = substr($data, 0, $key_block_bytes + 2);
|
$prefix = substr($data, 0, $key_block_bytes + 2);
|
||||||
$mdc = substr(substr($data, -22, 22), 2);
|
$mdc = substr(substr($data, -22, 22), 2);
|
||||||
$data = substr($data, $key_block_bytes + 2, -22);
|
$data = substr($data, $key_block_bytes + 2, -22);
|
||||||
|
|
||||||
$mkMDC = hash("sha1", $prefix . $data . "\xD3\x14", true);
|
$mkMDC = hash("sha1", $prefix . $data . "\xD3\x14", true);
|
||||||
if($mkMDC !== $mdc) return false;
|
if($mkMDC !== $mdc) return false;
|
||||||
@ -50,7 +50,17 @@ class OpenPGP_Crypt_AES_TripleDES {
|
|||||||
} catch (Exception $ex) { $msg = NULL; }
|
} catch (Exception $ex) { $msg = NULL; }
|
||||||
if($msg) return $msg; /* Otherwise keep trying */
|
if($msg) return $msg; /* Otherwise keep trying */
|
||||||
} else {
|
} else {
|
||||||
// TODO (resync)
|
// No MDC mean decrypt with resync
|
||||||
|
$iv = substr($epacket->data, 2, $key_block_bytes);
|
||||||
|
$edata = substr($epacket->data, $key_block_bytes + 2);
|
||||||
|
|
||||||
|
$cipher->setIV($iv);
|
||||||
|
$data = substr($cipher->decrypt($edata . str_repeat("\0", $padAmount)), 0, strlen($edata));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$msg = OpenPGP_Message::parse($data);
|
||||||
|
} catch (Exception $ex) { $msg = NULL; }
|
||||||
|
if($msg) return $msg; /* Otherwise keep trying */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -88,9 +88,9 @@ class Decryption extends PHPUnit_Framework_TestCase {
|
|||||||
public function testDecryptSessionKey() {
|
public function testDecryptSessionKey() {
|
||||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-with-session-key.gpg");
|
$this->oneSymmetric("hello", "PGP\n", "symmetric-with-session-key.gpg");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public function testDecryptNoMDC() {
|
public function testDecryptNoMDC() {
|
||||||
$this->oneSymmetric("hello", "PGP\n", "symmetric-no-mdc.gpg");
|
$this->oneSymmetric("hello", "PGP\n", "symmetric-no-mdc.gpg");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user