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