2017-02-15 64 views
0

我有兩個傳統的mongo php 1.6.10驅動程序和支持1.2.5 mongodb的PHP驅動程序安裝。在Debian 8上php的版本是5.6.29。php mongodb連接x509

舊版驅動程序和受支持的驅動程序都可以使用基本憑證進行連接。

只有傳統驅動程序可以使用x509證書進行連接。

當試圖對集合執行簡單的findOne時,支持的驅動程序會導致下面的異常。

PHP Fatal error: Uncaught exception 'MongoDB\Driver\Exception\RuntimeException' with message 'SCRAM Failure: invalid salt length of 0 in sasl step2' 
我使用MongoDB的客戶端庫MongoDB的驅動 http://php.net/manual/en/set.mongodb.php

這裏

被意譯代碼我使用

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

回答