php mongodb connect with x509 問題


  • 註冊用戶

    我在Debian8 的系統安裝了兩個mongodb的php driver,分別是1.6.10(legacy) and 1.2.5 (supported)

    採用php版本5.6.29

    兩個驅動都支持基本的credentials去連接

    但是只有舊的驅動可以連接時使用x509的證書

    1.2.5的版本則會導致下面的錯誤

    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 

    本帖下載内容已隐藏,请登入以查看隐藏内容!

    代碼如下

    <?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]]);

登录后回复
 

与 萌阔论坛 的连接断开,我们正在尝试重连,请耐心等待