28 $context[
'kex'][
'client'] = $kex;
30 if (!isset($context[
'rekeying'])) {
31 $context[
'rekeying'] =
'client';
35 $context[
'kexAlgo'] = null;
36 foreach ($kex->getKEXAlgos() as $algo) {
37 if ($algos->getClass(
'KEX', $algo) !== null) {
38 $kexCls = $context[
'kexAlgo'] = $algos->getClass(
'KEX', $algo);
43 if (!isset($context[
'kexAlgo'])) {
44 throw new \RuntimeException();
46 $kexCls::addHandlers($transport);
49 $context[
'C2S'][
'Encryption'] = null;
50 foreach ($kex->getC2SEncryptionAlgos() as $algo) {
51 if ($algos->getClass(
'Encryption', $algo) !== null) {
52 $context[
'C2S'][
'Encryption'] = $algos->getClass(
'Encryption', $algo);
57 if (!isset($context[
'C2S'][
'Encryption'])) {
58 throw new \RuntimeException();
62 $context[
'C2S'][
'Compression'] = null;
63 foreach ($kex->getC2SCompressionAlgos() as $algo) {
64 if ($algos->getClass(
'Compression', $algo) !== null) {
65 $context[
'C2S'][
'Compression'] = $algos->getClass(
'Compression', $algo);
70 if (!isset($context[
'C2S'][
'Compression'])) {
71 throw new \RuntimeException();
75 $context[
'C2S'][
'MAC'] = null;
76 $reflector = new \ReflectionClass($context[
'C2S'][
'Encryption']);
78 if ($reflector->implementsInterface(
'\\fpoirotte\\Pssht\\Algorithms\\AEAD\\AEADInterface')) {
79 $context[
'C2S'][
'MAC'] =
'\\fpoirotte\\Pssht\\MAC\\None';
81 foreach ($kex->getC2SMACAlgos() as $algo) {
82 if ($algos->getClass(
'MAC', $algo) !== null) {
83 $context[
'C2S'][
'MAC'] = $algos->getClass(
'MAC', $algo);
89 if (!isset($context[
'C2S'][
'MAC'])) {
90 throw new \RuntimeException();
94 $context[
'S2C'][
'Encryption'] = null;
95 foreach ($kex->getS2CEncryptionAlgos() as $algo) {
96 if ($algos->getClass(
'Encryption', $algo) !== null) {
97 $context[
'S2C'][
'Encryption'] = $algos->getClass(
'Encryption', $algo);
102 if (!isset($context[
'S2C'][
'Encryption'])) {
103 throw new \RuntimeException();
107 $context[
'S2C'][
'Compression'] = null;
108 foreach ($kex->getS2CCompressionAlgos() as $algo) {
109 if ($algos->getClass(
'Compression', $algo) !== null) {
110 $context[
'S2C'][
'Compression'] = $algos->getClass(
'Compression', $algo);
115 if (!isset($context[
'S2C'][
'Compression'])) {
116 throw new \RuntimeException();
120 $context[
'S2C'][
'MAC'] = null;
121 $reflector = new \ReflectionClass($context[
'S2C'][
'Encryption']);
123 if ($reflector->implementsInterface(
'\\fpoirotte\\Pssht\\Algorithms\\AEAD\\AEADInterface')) {
124 $context[
'S2C'][
'MAC'] =
'\\fpoirotte\\Pssht\\MAC\\None';
126 foreach ($kex->getS2CMACAlgos() as $algo) {
127 if ($algos->getClass(
'MAC', $algo) !== null) {
128 $context[
'S2C'][
'MAC'] = $algos->getClass(
'MAC', $algo);
134 if (!isset($context[
'S2C'][
'MAC'])) {
135 throw new \RuntimeException();
138 if ($context[
'rekeying'] ===
'client') {
139 $kexinit = new \fpoirotte\Pssht\Handlers\InitialState();
140 return $kexinit->handleKEXINIT($transport, $context);
static unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
handle($msgType,\fpoirotte\Pssht\Wire\Decoder $decoder,\fpoirotte\Pssht\Transport $transport, array &$context)