Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-914

php mongodb connect 'SCRAM Failure: invalid salt length of 0 in sasl step2' exception

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.3.0-beta1, 1.3.0
    • Affects Version/s: 1.2.5
    • Component/s: None
    • None
    • Environment:
      5.6.29 on Debian 8

      I have both legacy mongo php 1.6.10 driver and supported 1.2.5 mongodb php driver installed. php version is 5.6.29 on Debian 8.

      both legacy driver and supported driver can connect using basic credentials.

      Only the legacy driver can connect using the x509 certificate.

      The supported driver causes the below exception when trying to do a simple findOne on a collection.

      PHP Fatal error:  Uncaught exception 'MongoDB\Driver\Exception\RuntimeException' with message 'SCRAM Failure: invalid salt length of 0 in sasl step2' in /var/www/html/mongo/vendor/mongodb/mongodb/src/Operation/Find.php:219
      Stack trace:
      #0 /var/www/html/mongo/vendor/mongodb/mongodb/src/Operation/Find.php(219): MongoDB\Driver\Server->executeQuery('uatdata...', Object(MongoDB\Driver\Query), Object(MongoDB\Driver\ReadPreference))
      #1 /var/www/html/mongo/vendor/mongodb/mongodb/src/Operation/FindOne.php(105): MongoDB\Operation\Find->execute(Object(MongoDB\Driver\Server))
      #2 /var/www/html/mongo/vendor/mongodb/mongodb/src/Collection.php(559): MongoDB\Operation\FindOne->execute(Object(MongoDB\Driver\Server))
      #3 /var/www/html/mongo/index.php(50): MongoDB\Collection->findOne(Array, Array)
      #4 {main}
        thrown in /var/www/html/mongo/vendor/mongodb/mongodb/src/Operation/Find.php on line 219
      

      I am using the Mongodb Client library for the mongodb driver http://php.net/manual/en/set.mongodb.php[1]

      Here is paraphrased code I am using

          <?php
          $server = 'mongodb://uat-a:27017,uat-b:27017,uat-c:27017';
          $options = [
              'replicaSet' => 'rs-uat',
              'username' => 'CN=my-user,OU=user,O=NA,L=Place,ST=State,C=GB',
              'authMechanism' => 'MONGODB-X509',
              'authSource' => '$external',
              'ssl' => true,
              'connect' => true,
          ];
          $driverOptions = [
              'context' => stream_context_create(
                  [
                      'ssl' => [
                          'local_cert' => '/etc/local-cert.pem',
                          'cafile' => '/etc/cafile.pem',
                      ],
                  ]
              ),
          ];
          $database = 'uatdata';
      
          $client = new MongoDB\Client($server, $options, $driverOptions);
          $db = $client->selectDatabase($database);
      
          $doc = $db->selectCollection('errors')->findOne([], ['projection' => ['timestamp' => 1, 'uri' => 1]]);
      

      [1]: http://php.net/manual/en/set.mongodb.php

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            gawpertron Adam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: