28 unset($context[
'rekeying']);
29 $response = new \fpoirotte\Pssht\Messages\NEWKEYS();
30 $transport->writeMessage($response);
31 $logging = \Plop\Plop::getInstance();
34 $kexAlgo = $context[
'kexAlgo'];
35 $kexAlgo =
new $kexAlgo();
36 $encoder = new \fpoirotte\Pssht\Wire\Encoder();
37 $encoder->encodeMpint($context[
'DH']->getSharedSecret());
38 $sharedSecret = $encoder->getBuffer()->get(0);
39 $exchangeHash = $context[
'DH']->getExchangeHash();
40 $sessionId = $context[
'sessionIdentifier'];
42 'A' => array($context[
'C2S'][
'Encryption'],
'getIVSize'),
43 'B' => array($context[
'S2C'][
'Encryption'],
'getIVSize'),
44 'C' => array($context[
'C2S'][
'Encryption'],
'getKeySize'),
45 'D' => array($context[
'S2C'][
'Encryption'],
'getKeySize'),
46 'E' => array($context[
'C2S'][
'MAC'],
'getKeySize'),
47 'F' => array($context[
'C2S'][
'MAC'],
'getKeySize'),
50 $shared = gmp_strval($context[
'DH']->getSharedSecret(), 16);
51 $shared = str_pad($shared, ((strlen($shared) + 1) >> 1) << 1,
'0', STR_PAD_LEFT);
52 $logging->debug(
'Key exchange: %s', array($context[
'kexAlgo']));
55 array(wordwrap($shared, 16,
' ',
true))
59 array(wordwrap(bin2hex($exchangeHash), 16,
' ',
true))
62 foreach (array(
'A',
'B',
'C',
'D',
'E',
'F') as $keyIndex) {
63 $key = $kexAlgo->hash($sharedSecret . $exchangeHash . $keyIndex . $sessionId);
64 $limit = call_user_func($limiters[$keyIndex]);
65 while (strlen($key) < $limit) {
66 $key .= $kexAlgo->hash($sharedSecret . $exchangeHash . $key);
68 $key = (string) substr($key, 0, $limit);
69 $context[
'keys'][$keyIndex] = $key;
71 'Key %(keyName)s: %(keyValue)s',
73 'keyName' => $keyIndex,
74 'keyValue' => wordwrap(bin2hex($key), 16,
' ',
true),
80 $cls = $context[
'C2S'][
'Encryption'];
81 $transport->setDecryptor(
82 new $cls($context[
'keys'][
'A'], $context[
'keys'][
'C'])
84 $logging->debug(
'C2S Encryption: %s', array($cls));
86 $cls = $context[
'S2C'][
'Encryption'];
87 $transport->setEncryptor(
88 new $cls($context[
'keys'][
'B'], $context[
'keys'][
'D'])
90 $logging->debug(
'S2C Encryption: %s', array($cls));
93 $cls = $context[
'C2S'][
'MAC'];
94 $transport->setInputMAC(
new $cls($context[
'keys'][
'E']));
95 $logging->debug(
'C2S MAC: %s', array($cls));
97 $cls = $context[
'S2C'][
'MAC'];
98 $transport->setOutputMAC(
new $cls($context[
'keys'][
'F']));
99 $logging->debug(
'S2C MAC: %s', array($cls));
102 $cls = $context[
'C2S'][
'Compression'];
103 $transport->setUncompressor(
106 $logging->debug(
'C2S Compression: %s', array($cls));
108 $cls = $context[
'S2C'][
'Compression'];
109 $transport->setCompressor(
112 $logging->debug(
'S2C Compression: %s', array($cls));
const MODE_COMPRESS
Use the algorithm for compression.
handle($msgType,\fpoirotte\Pssht\Wire\Decoder $decoder,\fpoirotte\Pssht\Transport $transport, array &$context)
const MODE_UNCOMPRESS
Use the algorithm for decompression.