aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Osusky <[email protected]>2017-10-20 12:05:01 +0000
committerJan Osusky <[email protected]>2017-10-20 14:06:14 +0000
commit6cfe2c5f6cf1fa5c07c361bc6a5ec5b9690b68c7 (patch)
tree62bf84260f460c922ec83dd0407d45f729eb14b1
parentFix of compilation warning reported by GCC 4.9.3 (diff)
downloadvmime-6cfe2c5f6cf1fa5c07c361bc6a5ec5b9690b68c7.tar.gz
vmime-6cfe2c5f6cf1fa5c07c361bc6a5ec5b9690b68c7.zip
Add SMTPS with AUTH PLAIN without SASL
GNU SASL is a nice library but comes with its own prerequisites and dependencies. As IMAP and POP3 are able to work without SASL it seems to me logical to add some authentication support to SMTP too. As these days most of the communication is encrypted it is common to use simple mechanism like AUTH PLAIN, so I have added it.
-rw-r--r--src/vmime/net/smtp/SMTPConnection.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/vmime/net/smtp/SMTPConnection.cpp b/src/vmime/net/smtp/SMTPConnection.cpp
index 3785126a..8709efe4 100644
--- a/src/vmime/net/smtp/SMTPConnection.cpp
+++ b/src/vmime/net/smtp/SMTPConnection.cpp
@@ -40,6 +40,10 @@
#if VMIME_HAVE_SASL_SUPPORT
#include "vmime/security/sasl/SASLContext.hpp"
+#else
+ #include "vmime/utility/encoder/b64Encoder.hpp"
+ #include "vmime/utility/inputStreamStringAdapter.hpp"
+ #include "vmime/utility/outputStreamStringAdapter.hpp"
#endif // VMIME_HAVE_SASL_SUPPORT
#if VMIME_HAVE_TLS_SUPPORT
@@ -48,7 +52,6 @@
#endif // VMIME_HAVE_TLS_SUPPORT
-
// Helpers for service properties
#define GET_PROPERTY(type, prop) \
(m_transport.lock()->getInfos().getPropertyValue <type>(getSession(), \
@@ -307,6 +310,39 @@ void SMTPConnection::authenticate()
throw;
}
}
+#else // no SASL
+
+ // allow AUTH PLAIN over TLS - it is a popular and simple mechanism
+ if (m_secured)
+ {
+ std::vector <string> authMechs;
+ hasExtension("AUTH", &authMechs);
+
+ if (authMechs.empty())
+ throw exceptions::authentication_error("No AUTH mechanism available.");
+
+ const string plain("PLAIN");
+ if (std::find(authMechs.begin(), authMechs.end(), plain) != authMechs.end())
+ {
+ const string username = getAuthenticator()->getUsername();
+ const string password = getAuthenticator()->getPassword();
+ const string authToken = username + '\0' + username + '\0' + password;
+ auto encoder = new vmime::utility::encoder::b64Encoder();
+ utility::inputStreamStringAdapter in(authToken);
+ string authTokenBase64;
+ utility::outputStreamStringAdapter out(authTokenBase64);
+ encoder->encode(in, out);
+ sendRequest(SMTPCommand::AUTH(plain, authTokenBase64));
+ shared_ptr <SMTPResponse> response = readResponse();
+ const int code = response ? response->getCode() : -1;
+ if (code == 235)
+ {
+ m_authenticated = true;
+ return;
+ }
+ }
+ }
+
#endif // VMIME_HAVE_SASL_SUPPORT
// No other authentication method is possible