官术网_书友最值得收藏!

How it works...

In step 1, we created a self-signed certificate to get us started with SSL enabled connections. One could very well use a certificate signed by a valid Certificate Authority (CA), but for test purposes we are good with a self-signed certificate. In all honesty, if connection security is all you need, a self-signed certificate can also be used in a production environment as long as you keep the keys secure. You might as well take it a step forward by creating your own CA certificate and use it to sign your certificates.

In step 2, we concatenate the key and the certificate file. Next, in step 3, we start the mongod daemon with --sslMode requireSSL followed by providing the path to the concatenated .pem file. At this point, we have a standalone MongoDB server listening to the default port 27017, ready to accept only SSL based clients.

Next, we attempt to connect to the mongod server using the default non-SSL mode, which is immediately rejected by the sever. Finally, in step 5 we explicitly make an SSL connection by providing the --ssl parameter followed by --sslAllowInvalidCertificates. The latter parameter is used because we are using a self-signed certificate on the server. If we were using an certificate signed by a authorized CA or even a self-signed CA, we could very well use the --sslCAFile to provide the CA certificate.

主站蜘蛛池模板: 巧家县| 富民县| 泗洪县| 美姑县| 扶风县| 湖北省| 大连市| 东丽区| 桑植县| 鄂托克前旗| 化德县| 水城县| 西青区| 临城县| 巴南区| 离岛区| 正定县| 南昌县| 德保县| 西宁市| 武宁县| 湖州市| 雷州市| 宁晋县| 静安区| 嫩江县| 泰兴市| 禹城市| 马龙县| 定安县| 修文县| 霍城县| 区。| 通渭县| 阜新| 故城县| 温宿县| 泸定县| 南江县| 海宁市| 哈巴河县|