Skip to content

Commit c65dfe0

Browse files
author
Giorgio Franceschetti
committed
0.10.1
1 parent 573da75 commit c65dfe0

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ When you use the `mongodb+srv` url schema, the "tls" (or "ssl") parameter is imp
272272

273273
You can also use certificates for tls handshake [see this tutorial][19] for more info.
274274

275+
### Authentication
276+
277+
The driver supports three authentication methods:
278+
279+
- SCRAM_SHA_1
280+
- SCRAM_SHA_256
281+
- X509. See [here][20] for more details.
282+
275283
### Atlas (MongoDb cloud service) connection
276284

277285
Atlas requires a tls connection, so now it is possible to connect to this cloud service.
@@ -373,3 +381,4 @@ Last but not least, some commands:
373381
[17]: https://github.com/mongo-dart/mongo_dart/blob/main/example/manual/watch/watch_on_collection.dart
374382
[18]: https://github.com/mongo-dart/mongo_dart/blob/main/example/manual/watch/watch_on_collection_insert.dart
375383
[19]: https://github.com/mongo-dart/mongo_dart/blob/main/doc/manual/connection/simple_connection_no_auth.md
384+
[20]: https://github.com/mongo-dart/mongo_dart/blob/main/doc/manual/connection/x509_authentication.md

doc/manual/connection/tls_connection_no_auth_client_certificate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ or
112112

113113
If the key was password protected you must add also the `tlsCertificateKeyFilePassword` parameter, either in the connection string or as a `db.open()` parameter.
114114

115-
[Prev doc.](tls_connection_no_auth_self_signed_certificate.md)
115+
[Prev doc.](tls_connection_no_auth_self_signed_certificate.md) - [Next doc.](x509_authentication.md)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
# X509 Authentication
3+
4+
## Prerequisites
5+
6+
For X509 authentication, we have to pass the same parameters like fordar the connection with the client certificate.
7+
Be careful that at leat one in:
8+
9+
- Organization (O)
10+
- Organizational Unit (OU)
11+
- Domain Component (DC)
12+
13+
must be different between the client and the server certificates.
14+
15+
When you insert the user in the db, you have to store in the "$external" database the credentials. The user must be the subject of the certificate, for example "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry".
16+
17+
```javaScript
18+
db.getSiblingDB("$external").runCommand(
19+
{
20+
createUser: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
21+
roles: [
22+
{ role: "readWrite", db: "test" },
23+
{ role: "userAdminAnyDatabase", db: "admin" }
24+
],
25+
writeConcern: { w: "majority" , wtimeout: 5000 }
26+
}
27+
)
28+
```
29+
30+
31+
You can extract this from the certificate with the command:
32+
33+
```bash
34+
openssl x509 -in <pathToClientPEM> -inform PEM -subject -nameopt RFC2253
35+
```
36+
37+
for more detail give a look to this two pages:
38+
39+
- [Use certificates](https://www.mongodb.com/docs/manual/tutorial/configure-x509-client-authentication/).
40+
- [X509](https://www.mongodb.com/docs/manual/core/security-x.509/).
41+
42+
## How to Authenticate
43+
44+
Then we have to options:
45+
46+
- Authenticate immediately: for this you have to pass also the parameter `authMechanism=MONGODB-X509` in the connection string. You don't need to pass also the "$external" datbase as authsource because the driver authomatically will set it in case of X509 authentication.
47+
- Authenticate after connecting: you have to use the `db.authenticateX509()` method after that the connection is in place.
48+
49+
[Prev doc.](tls_connection_no_auth_client_certificate.md)

test/op_msg_read_operation_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,7 @@ db.runCommand(
20162016
countOptions: CountOptions(
20172017
readConcern: ReadConcern(ReadConcernLevel.majority)));
20182018

2019+
await Future.delayed(Duration(seconds: 3));
20192020
var result = await operation.executeDocument();
20202021

20212022
expect(result.ok, 1.0);

0 commit comments

Comments
 (0)