Discussion:
Connecting to MongoDB through SSL
Fabian Bernhard
2014-01-14 07:24:32 UTC
Permalink
Dear list,

I try to connect to the MongoDB Server through SSL, using the following
code:

var config = {
mongo: {
host: "example.com",
port: 27017,
db: "my-db",
username: "webuser",
password: "secret"
}
}

var dbstring = "mongodb://" + config.mongo.host + ":" + config.mongo.port +
"/"
+ config.mongo.db;

var dboptions = {
username: config.mongo.username,
password: config.mongo.password
};

mongoose.connect(dbstring, dboptions);

The connection fails, the MongoDB server log says:

Tue Jan 14 10:12:03.081 [initandlisten] connection accepted from
XXX.XXX.XXX.XXX:49967 #15 (3 connections now open)
Tue Jan 14 10:12:03.105 [conn15] ERROR: no SSL certificate provided by
peer; connection rejected
Tue Jan 14 10:12:03.105 [conn15] SocketException handling request, closing
client connection: 9001 socket exception [CONNECT_ERROR]


How can I provide an SSL certificate to the MongoDB connection through
Mongoose Node.JS?

Thank you!
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Fabian Bernhard
2014-01-14 12:10:53 UTC
Permalink
Reading through the code I have found the answer myself. The correct
configuration is this:

var dboptions = {
username: config.mongo.username,
password: config.mongo.password,
server: {
ssl: true,
sslCert: fs.readFileSync('./ssl/mongodb.crt'),
sslKey: fs.readFileSync('./ssl/mongodb.key')
}
};

With this the encrypted communication with the MongoDB works.
Post by Fabian Bernhard
Dear list,
I try to connect to the MongoDB Server through SSL, using the following
var config = {
mongo: {
host: "example.com",
port: 27017,
db: "my-db",
username: "webuser",
password: "secret"
}
}
var dbstring = "mongodb://" + config.mongo.host + ":" + config.mongo.port
+ "/"
+ config.mongo.db;
var dboptions = {
username: config.mongo.username,
password: config.mongo.password
};
mongoose.connect(dbstring, dboptions);
Tue Jan 14 10:12:03.081 [initandlisten] connection accepted from
XXX.XXX.XXX.XXX:49967 #15 (3 connections now open)
Tue Jan 14 10:12:03.105 [conn15] ERROR: no SSL certificate provided by
peer; connection rejected
Tue Jan 14 10:12:03.105 [conn15] SocketException handling request, closing
client connection: 9001 socket exception [CONNECT_ERROR]
How can I provide an SSL certificate to the MongoDB connection through
Mongoose Node.JS?
Thank you!
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Fabian Bernhard
2014-01-15 08:27:37 UTC
Permalink
Correction: It should be user/pass and not username/password.

var dboptions = {
*user*: config.mongo.username,
*pass*: config.mongo.password,
server: {
ssl: true,
sslCert: fs.readFileSync('./ssl/mongodb.crt'),
sslKey: fs.readFileSync('./ssl/mongodb.key')
}
};
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...