36 $method = new \fpoirotte\Pssht\Authentication\None();
37 $realMethods = array($method->getName() => $method);
38 foreach ($methods as $method) {
40 throw new \InvalidArgumentException();
42 $realMethods[$method->getName()] = $method;
45 $this->methods = $realMethods;
46 $this->connection = null;
56 if ($this->connection !== null) {
62 $encoder = new \fpoirotte\Pssht\Wire\Encoder();
63 $user = $decoder->decodeString();
64 $service = $decoder->decodeString();
65 $method = $decoder->decodeString();
67 $encoder->encodeString($user);
68 $encoder->encodeString($service);
69 $encoder->encodeString($method);
70 $decoder->getBuffer()->unget($encoder->getBuffer()->get(0));
72 if (!isset($context[
'authMethods'])) {
76 if (!isset($context[
'banner'])) {
77 $context[
'banner'] = (string) $transport->getBanner();
78 if ($context[
'banner'] !==
'') {
79 $response = new \fpoirotte\Pssht\Messages\USERAUTH\BANNER($context[
'banner']);
80 $transport->writeMessage($response);
84 if (!isset($context[
'authMethods'][$method])) {
85 return $this->
failure($transport, $context);
90 '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\None',
92 '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\HostBased',
94 '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\Password',
96 '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\PublicKey',
98 $methodObj = $context[
'authMethods'][$method];
99 $message = $messagesCls[$method]::unserialize($decoder);
101 switch ($methodObj->check($message, $transport, $context)) {
106 return $this->
failure($transport, $context);
112 throw new \RuntimeException();
115 switch ($methodObj->authenticate($message, $transport, $context)) {
117 unset($context[
'authMethods'][$method]);
121 return $this->
failure($transport, $context);
127 throw new \RuntimeException();
130 unset($context[
'authMethods'][$method]);
131 $response = new \fpoirotte\Pssht\Messages\USERAUTH\SUCCESS();
132 $this->connection = new \fpoirotte\Pssht\Connection($transport);
133 $transport->writeMessage($response);
135 $compressor = $transport->getCompressor();
136 if ($compressor instanceof \
fpoirotte\Pssht\Compression\DelayedCompressionInterface) {
137 $compressor->setAuthenticated();
139 $uncompressor = $transport->getUncompressor();
140 if ($uncompressor instanceof \
fpoirotte\Pssht\Compression\DelayedCompressionInterface) {
141 $uncompressor->setAuthenticated();
170 if (!is_bool($partial)) {
171 throw new \InvalidArgumentException();
174 $remaining = $context[
'authMethods'];
175 unset($remaining[
'none']);
176 $remaining = array_keys($remaining);
177 $response = new \fpoirotte\Pssht\Messages\USERAUTH\FAILURE($remaining, $partial);
178 $transport->writeMessage($response);
$methods
Allowed authentication methods.
const AUTH_REMOVE
The authentication failed and the method should be removed.
const CHECK_REJECT
The message should be rejected.
const CHECK_IGNORE
The message should be ignored.
const CHECK_OK
The message passed the check.
handle($msgType,\fpoirotte\Pssht\Wire\Decoder $decoder,\fpoirotte\Pssht\Transport $transport, array &$context)
$connection
Connection layer.
const AUTH_ACCEPT
The authentication was successful.
failure(\fpoirotte\Pssht\Transport $transport, array &$context, $partial=false)
const AUTH_REJECT
The authentication failed.
__construct(array $methods)