-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSL errors #173
Comments
Did you take a look of |
ssl_options() does not solve the security issue and is also not flexible. By disabling peer verification, it means that a hacker can make the Mailio client connect to a different server than intended and you won't know about it. The error you are seeing is not from the email servers, it is your client saying it cannot verify that the server is who it says it is. For SSL/TLS to work correctly you need to give the ssl context the certificate chain to use so it can verify the server it is connecting to. You are receiving this error because you didn't setup certificates. Here are some ways to correctly do this:
The Stack Overflow example shows using 1 and 2 together. This would be similar to how browsers can know if a website's server is safe. Since this in a library you would also want to support option one since someone may use it to make a tool for sending mail just through their own server, such as for notifications from their app. An example of context setup may look like this:
Like the example I also set extra options with set_options(). I don't remember why but I think it didn't work properly in the constructor. Disabling peer verification is very bad, instead using those options should solve the error. If the user has a way to work with the ssl context before the socket creation then you won't need to write much support for all these things since the library user can then choose what method they need for themselves. More advanced use also allows servers to require the client to verify itself with a certificate and key, then the client would need to register a certificate and private key or even a password callback to be able to use that key. This may look like this:
Or limiting the ciphers to only allow the most secure ones:
I hope this helps, I didn't explain deeply how certificates work, read about SSL/TLS and x509 certificates if you didn't already understand it well. |
mailio.zip My usage looks something like this:
|
Hey, I agree with your remarks,. This is a debt from my side. Please make a PR with your changes, so I could take a look. Since I am doing refactoring regarding the line policy and folding, I cannot immediately test your changes, but I will do it for sure and get back to you. |
I had to manually copy my changes, I don't think I missed anything. I had tested it but only made the changes for smtps. Hope that helps |
Regarding the SSL issues as mentioned:
#163
#148 (comment)
The suggested solution of disabling peer verification is unsafe.
Would it be possible to add an overload to the smtp::authenticate() method and for other classes that takes an externally created ssl::context?
std::string authenticate(const std::string& username, const std::string& password, auth_method_t method, std::shared_ptr<ssl::context> ctx);
This would allow users to setup certificate stores etc. before the connection is made.
Another option could be a callback after the ssl context is initialised that allows the user to modify the context before the socket gets initialised.
The text was updated successfully, but these errors were encountered: