Exemple #1
0
 public function handle($msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context)
 {
     $message = \fpoirotte\Pssht\Messages\DEBUG::unserialize($decoder);
     if ($message->mustAlwaysDisplay()) {
         echo escape($message->getMessage()) . PHP_EOL;
     }
     return true;
 }
Exemple #2
0
 /**
  * Construct a new SSH transport layer.
  *
  *  \param array $serverKeys
  *      Keys presented by the server as an associated array where:
  *      -   keys indicate the key's algorithm (eg. "ssh-dss")
  *      -   values are an associative array with the following keys:
  *          -   "file": a PEM-encoded private key or path to a PEM-encoded
  *                      private key, in "file:///path/to/key.pem" format
  *          -   "passphrase": (optional) passphrase for the key
  *
  *  \param fpoirotte::Pssht::Handlers::SERVICE::REQUEST $authMethods
  *      Allowed authentication methods.
  *
  *  \param fpoirotte::Pssht::Wire::Encoder $encoder
  *      (optional) Encoder to use when sending SSH messages.
  *      If omitted, a new encoder is automatically created.
  *
  *  \param fpoirotte::Pssht::Wire::Decoder $decoder
  *      (optional) Decoder to use when sending SSH messages.
  *      If omitted, a new decoder is automatically created.
  *
  *  \note
  *      Once this class' constructor has been called,
  *      you are advised to call the setAddress() method
  *      to register the client's IP address.
  *      This is required for some authentication methods
  *      to work properly.
  */
 public function __construct(array $serverKeys, \fpoirotte\Pssht\Handlers\SERVICE\REQUEST $authMethods, \fpoirotte\Pssht\Wire\Encoder $encoder = null, \fpoirotte\Pssht\Wire\Decoder $decoder = null, $rekeyingBytes = 1073741824, $rekeyingTime = 3600)
 {
     if ($encoder === null) {
         $encoder = new \fpoirotte\Pssht\Wire\Encoder();
     }
     if ($decoder === null) {
         $decoder = new \fpoirotte\Pssht\Wire\Decoder();
     }
     if (!is_int($rekeyingBytes) || $rekeyingBytes <= 1024) {
         throw new \InvalidArgumentException();
     }
     if (!is_int($rekeyingTime) || $rekeyingTime <= 60) {
         throw new \InvalidArgumentException();
     }
     $algos = \fpoirotte\Pssht\Algorithms::factory();
     $keys = array();
     foreach ($serverKeys as $keyType => $params) {
         $cls = $algos->getClass('PublicKey', $keyType);
         if ($cls === null) {
             throw new \InvalidArgumentException();
         }
         $passphrase = '';
         if (isset($params['passphrase'])) {
             $passphrase = $params['passphrase'];
         }
         $keys[$keyType] = $cls::loadPrivate($params['file'], $passphrase);
     }
     $this->address = null;
     $this->appFactory = null;
     $this->banner = null;
     $this->context = array('rekeyingBytes' => 0, 'rekeyingTime' => time() + $rekeyingTime);
     $this->rekeyingBytes = $rekeyingBytes;
     $this->rekeyingTime = $rekeyingTime;
     $this->inSeqNo = 0;
     $this->outSeqNo = 0;
     $this->encoder = $encoder;
     $this->decoder = $decoder;
     $this->compressor = new \fpoirotte\Pssht\Compression\None(\fpoirotte\Pssht\CompressionInterface::MODE_COMPRESS);
     $this->uncompressor = new \fpoirotte\Pssht\Compression\None(\fpoirotte\Pssht\CompressionInterface::MODE_UNCOMPRESS);
     $this->encryptor = new \fpoirotte\Pssht\Encryption\None(null, null);
     $this->decryptor = new \fpoirotte\Pssht\Encryption\None(null, null);
     $this->inMAC = new \fpoirotte\Pssht\MAC\None(null);
     $this->outMAC = new \fpoirotte\Pssht\MAC\None(null);
     $this->handlers = array(\fpoirotte\Pssht\Messages\DISCONNECT::getMessageId() => new \fpoirotte\Pssht\Handlers\DISCONNECT(), \fpoirotte\Pssht\Messages\IGNORE::getMessageId() => new \fpoirotte\Pssht\Handlers\IGNORE(), \fpoirotte\Pssht\Messages\DEBUG::getMessageId() => new \fpoirotte\Pssht\Handlers\DEBUG(), \fpoirotte\Pssht\Messages\SERVICE\REQUEST::getMessageId() => $authMethods, \fpoirotte\Pssht\Messages\KEXINIT::getMessageId() => new \fpoirotte\Pssht\Handlers\KEXINIT(), \fpoirotte\Pssht\Messages\NEWKEYS::getMessageId() => new \fpoirotte\Pssht\Handlers\NEWKEYS(), 256 => new \fpoirotte\Pssht\Handlers\InitialState());
     $ident = "SSH-2.0-pssht_1.0.x_dev";
     $this->context['identity']['server'] = $ident;
     $this->context['serverKeys'] = $keys;
     $this->encoder->encodeBytes($ident . "\r\n");
 }