Ejemplo n.º 1
0
 public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     $pubkey = $decoder->decodeString();
     if (strlen($pubkey) !== 32) {
         throw new \InvalidArgumentException();
     }
     return new static($pubkey);
 }
Ejemplo n.º 2
0
 protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     $passChange = $decoder->decodeBoolean();
     $res = array($decoder->decodeString());
     if ($passChange === true) {
         $res[] = $decoder->decodeString();
     }
     return $res;
 }
Ejemplo n.º 3
0
 public function handle($msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context)
 {
     $ident = $decoder->getBuffer()->get("\r\n");
     if ($ident === null) {
         throw new \RuntimeException();
     }
     $context['identity']['client'] = (string) substr($ident, 0, -2);
     if (strncmp($ident, 'SSH-2.0-', 8) !== 0) {
         throw new \fpoirotte\Pssht\Messages\DISCONNECT();
     }
     $context['rekeying'] = 'server';
     return $this->handleKEXINIT($transport, $context);
 }
Ejemplo n.º 4
0
 public function handle($msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context)
 {
     $localChannel = $decoder->decodeUint32();
     $encoder = new \fpoirotte\Pssht\Wire\Encoder();
     $encoder->encodeUint32($localChannel);
     $decoder->getBuffer()->unget($encoder->getBuffer()->get(0));
     if (isset($this->handlers[$localChannel][$msgType])) {
         $handler = $this->handlers[$localChannel][$msgType];
         $logging = \Plop\Plop::getInstance();
         $logging->debug('Calling %(handler)s for channel #%(channel)d ' . 'with message type #%(msgType)d', array('handler' => get_class($handler) . '::handle', 'channel' => $localChannel, 'msgType' => $msgType));
         return $handler->handle($msgType, $decoder, $transport, $context);
     }
     return true;
 }
Ejemplo n.º 5
0
 protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     $signature = $decoder->decodeBoolean();
     $algorithm = $decoder->decodeString();
     $res = array($algorithm, $decoder->decodeString());
     if ($signature === true) {
         $decoder2 = new \fpoirotte\Pssht\Wire\Decoder(new \fpoirotte\Pssht\Buffer($decoder->decodeString()));
         if ($decoder2->decodeString() !== $algorithm) {
             throw new \InvalidArgumentException();
         }
         $res[] = $decoder2->decodeString();
     }
     return $res;
 }
Ejemplo n.º 6
0
 protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     $algorithm = $decoder->decodeString();
     $res = array($algorithm, $decoder->decodeString(), $decoder->decodeString(), $decoder->decodeString());
     // Special handling for signature.
     $decoder2 = new \fpoirotte\Pssht\Wire\Decoder(new \fpoirotte\Pssht\Buffer($decoder->decodeString()));
     if ($decoder2->decodeString() !== $algorithm) {
         throw new \InvalidArgumentException();
     }
     $res[] = $decoder2->decodeString();
     return $res;
 }
Ejemplo n.º 7
0
 public function handle($msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context)
 {
     $encoder = new \fpoirotte\Pssht\Wire\Encoder();
     $channel = $decoder->decodeUint32();
     $type = $decoder->decodeString();
     $wantsReply = $decoder->decodeBoolean();
     $encoder->encodeUint32($channel);
     $encoder->encodeString($type);
     $encoder->encodeBoolean($wantsReply);
     $decoder->getBuffer()->unget($encoder->getBuffer()->get(0));
     $remoteChannel = $this->connection->getChannel($channel);
     switch ($type) {
         case 'exec':
         case 'shell':
         case 'pty-req':
             // Normalize the name.
             // Eg. "pty-req" becomes "PtyReq".
             $cls = str_replace(' ', '', ucwords(str_replace('-', ' ', $type)));
             $cls = '\\fpoirotte\\Pssht\\Messages\\CHANNEL\\REQUEST\\' . $cls;
             $message = $cls::unserialize($decoder);
             break;
         default:
             if ($wantsReply) {
                 $response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel);
                 $transport->writeMessage($response);
             }
             return true;
     }
     if (!$wantsReply) {
         return true;
     }
     if (in_array($type, array('shell', 'exec'), true)) {
         $response = new \fpoirotte\Pssht\Messages\CHANNEL\SUCCESS($remoteChannel);
     } else {
         $response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel);
     }
     $transport->writeMessage($response);
     if (in_array($type, array('shell', 'exec'), true)) {
         $callable = $transport->getApplicationFactory();
         if ($callable !== null) {
             call_user_func($callable, $transport, $this->connection, $message);
         }
     }
     return true;
 }
Ejemplo n.º 8
0
 protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     return array($decoder->decodeUint32());
 }
Ejemplo n.º 9
0
 public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     return new static($decoder->decodeUint32());
 }
Ejemplo n.º 10
0
 public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     $res = new static(new \fpoirotte\Pssht\Random\Fixed($decoder->decodeBytes(16)), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeBoolean());
     $decoder->decodeUint32();
     // Reserved
     return $res;
 }
Ejemplo n.º 11
0
 public static final function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     $reflector = new \ReflectionClass(get_called_class());
     $args = array_merge(array($decoder->decodeUint32(), $decoder->decodeString(), $decoder->decodeBoolean()), static::unserializeSub($decoder));
     return $reflector->newInstanceArgs($args);
 }
Ejemplo n.º 12
0
 public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     $point = \fpoirotte\Pssht\ECC\Point::unserialize(static::getCurve(), $decoder->decodeString());
     return new static($point);
 }
Ejemplo n.º 13
0
 public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     return new static($decoder->decodeBoolean(), $decoder->decodeString(), $decoder->decodeString());
 }
Ejemplo n.º 14
0
 public function handle($msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context)
 {
     if ($this->connection !== null) {
         // Silently ignore subsequent authentication requests
         // after a successful authentication took place.
         return true;
     }
     $encoder = new \fpoirotte\Pssht\Wire\Encoder();
     $user = $decoder->decodeString();
     $service = $decoder->decodeString();
     $method = $decoder->decodeString();
     $encoder->encodeString($user);
     $encoder->encodeString($service);
     $encoder->encodeString($method);
     $decoder->getBuffer()->unget($encoder->getBuffer()->get(0));
     if (!isset($context['authMethods'])) {
         $context['authMethods'] = $this->methods;
     }
     if (!isset($context['banner'])) {
         $context['banner'] = (string) $transport->getBanner();
         if ($context['banner'] !== '') {
             $response = new \fpoirotte\Pssht\Messages\USERAUTH\BANNER($context['banner']);
             $transport->writeMessage($response);
         }
     }
     if (!isset($context['authMethods'][$method])) {
         return $this->failure($transport, $context);
     }
     $messagesCls = array('none' => '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\None', 'hostbased' => '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\HostBased', 'password' => '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\Password', 'publickey' => '\\fpoirotte\\Pssht\\Messages\\USERAUTH\\REQUEST\\PublicKey');
     $methodObj = $context['authMethods'][$method];
     $message = $messagesCls[$method]::unserialize($decoder);
     switch ($methodObj->check($message, $transport, $context)) {
         case AuthenticationInterface::CHECK_IGNORE:
             return true;
         case AuthenticationInterface::CHECK_REJECT:
             return $this->failure($transport, $context);
         case AuthenticationInterface::CHECK_OK:
             break;
         default:
             throw new \RuntimeException();
     }
     switch ($methodObj->authenticate($message, $transport, $context)) {
         case AuthenticationInterface::AUTH_REMOVE:
             unset($context['authMethods'][$method]);
             // Do not break.
         // Do not break.
         case AuthenticationInterface::AUTH_REJECT:
             return $this->failure($transport, $context);
         case AuthenticationInterface::AUTH_ACCEPT:
             break;
         default:
             throw new \RuntimeException();
     }
     unset($context['authMethods'][$method]);
     $response = new \fpoirotte\Pssht\Messages\USERAUTH\SUCCESS();
     $this->connection = new \fpoirotte\Pssht\Connection($transport);
     $transport->writeMessage($response);
     $compressor = $transport->getCompressor();
     if ($compressor instanceof \fpoirotte\Pssht\DelayedCompressionInterface) {
         $compressor->setAuthenticated();
     }
     $uncompressor = $transport->getUncompressor();
     if ($uncompressor instanceof \fpoirotte\Pssht\DelayedCompressionInterface) {
         $uncompressor->setAuthenticated();
     }
     return true;
 }
Ejemplo n.º 15
0
 protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
 {
     return array($decoder->decodeString(), $decoder->decodeBoolean(), $decoder->decodeString(), $decoder->decodeString());
 }