0

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'

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

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 Answer 1

0

The answer is to pass the authMechanism option within the URI string. e.g.

mongodb://uat-a:27017,uat-b:27017,uat-c:27017/?authMechanism=MONGODB-X509

A more detailed explanation can be found here https://jira.mongodb.org/browse/PHPC-914

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.