diff options
Diffstat (limited to 'src/vmime/net')
-rw-r--r-- | src/vmime/net/imap/IMAPConnection.cpp | 21 | ||||
-rw-r--r-- | src/vmime/net/pop3/POP3Command.cpp | 11 | ||||
-rw-r--r-- | src/vmime/net/pop3/POP3Command.hpp | 1 | ||||
-rw-r--r-- | src/vmime/net/pop3/POP3Connection.cpp | 24 | ||||
-rw-r--r-- | src/vmime/net/smtp/SMTPCommand.cpp | 11 | ||||
-rw-r--r-- | src/vmime/net/smtp/SMTPCommand.hpp | 1 | ||||
-rw-r--r-- | src/vmime/net/smtp/SMTPConnection.cpp | 20 |
7 files changed, 86 insertions, 3 deletions
diff --git a/src/vmime/net/imap/IMAPConnection.cpp b/src/vmime/net/imap/IMAPConnection.cpp index 5e6f6f8f..04705f6c 100644 --- a/src/vmime/net/imap/IMAPConnection.cpp +++ b/src/vmime/net/imap/IMAPConnection.cpp @@ -355,7 +355,26 @@ void IMAPConnection::authenticateSASL() saslSession->init(); - send(true, "AUTHENTICATE " + mech->getName(), true); + std::ostringstream cmd; + cmd << "AUTHENTICATE " << mech->getName(); + + if (saslSession->getMechanism()->hasInitialResponse()) + { + byte_t* initialResp = 0; + size_t initialRespLen = 0; + + saslSession->evaluateChallenge(NULL, 0, &initialResp, &initialRespLen); + + string encodedInitialResp(saslContext->encodeB64(initialResp, initialRespLen)); + delete [] initialResp; + + if (encodedInitialResp.empty()) + cmd << " ="; + else + cmd << " " << encodedInitialResp; + } + + send(true, cmd.str(), true); for (bool cont = true ; cont ; ) { diff --git a/src/vmime/net/pop3/POP3Command.cpp b/src/vmime/net/pop3/POP3Command.cpp index 6fe301ce..3c544fc0 100644 --- a/src/vmime/net/pop3/POP3Command.cpp +++ b/src/vmime/net/pop3/POP3Command.cpp @@ -74,6 +74,17 @@ shared_ptr <POP3Command> POP3Command::AUTH(const string& mechName) // static +shared_ptr <POP3Command> POP3Command::AUTH(const string& mechName, const string& initialResponse) +{ + std::ostringstream cmd; + cmd.imbue(std::locale::classic()); + cmd << "AUTH " << mechName << " " << initialResponse; + + return createCommand(cmd.str()); +} + + +// static shared_ptr <POP3Command> POP3Command::STLS() { return createCommand("STLS"); diff --git a/src/vmime/net/pop3/POP3Command.hpp b/src/vmime/net/pop3/POP3Command.hpp index cc3c4fd5..e34e4e2b 100644 --- a/src/vmime/net/pop3/POP3Command.hpp +++ b/src/vmime/net/pop3/POP3Command.hpp @@ -57,6 +57,7 @@ public: static shared_ptr <POP3Command> CAPA(); static shared_ptr <POP3Command> NOOP(); static shared_ptr <POP3Command> AUTH(const string& mechName); + static shared_ptr <POP3Command> AUTH(const string& mechName, const string& initialResponse); static shared_ptr <POP3Command> STLS(); static shared_ptr <POP3Command> APOP(const string& username, const string& digest); static shared_ptr <POP3Command> USER(const string& username); diff --git a/src/vmime/net/pop3/POP3Connection.cpp b/src/vmime/net/pop3/POP3Connection.cpp index f5a1a448..45c668f5 100644 --- a/src/vmime/net/pop3/POP3Connection.cpp +++ b/src/vmime/net/pop3/POP3Connection.cpp @@ -446,7 +446,29 @@ void POP3Connection::authenticateSASL() saslSession->init(); - POP3Command::AUTH(mech->getName())->send(dynamicCast <POP3Connection>(shared_from_this())); + shared_ptr <POP3Command> authCmd; + + if (saslSession->getMechanism()->hasInitialResponse()) + { + byte_t* initialResp = 0; + size_t initialRespLen = 0; + + saslSession->evaluateChallenge(NULL, 0, &initialResp, &initialRespLen); + + string encodedInitialResp(saslContext->encodeB64(initialResp, initialRespLen)); + delete [] initialResp; + + if (encodedInitialResp.empty()) + authCmd = POP3Command::AUTH(mech->getName(), "="); + else + authCmd = POP3Command::AUTH(mech->getName(), encodedInitialResp); + } + else + { + authCmd = POP3Command::AUTH(mech->getName()); + } + + authCmd->send(dynamicCast <POP3Connection>(shared_from_this())); for (bool cont = true ; cont ; ) { diff --git a/src/vmime/net/smtp/SMTPCommand.cpp b/src/vmime/net/smtp/SMTPCommand.cpp index 949ab0c1..2120caf5 100644 --- a/src/vmime/net/smtp/SMTPCommand.cpp +++ b/src/vmime/net/smtp/SMTPCommand.cpp @@ -80,6 +80,17 @@ shared_ptr <SMTPCommand> SMTPCommand::AUTH(const string& mechName) // static +shared_ptr <SMTPCommand> SMTPCommand::AUTH(const string& mechName, const std::string& initialResponse) +{ + std::ostringstream cmd; + cmd.imbue(std::locale::classic()); + cmd << "AUTH " << mechName << " " << initialResponse; + + return createCommand(cmd.str()); +} + + +// static shared_ptr <SMTPCommand> SMTPCommand::STARTTLS() { return createCommand("STARTTLS"); diff --git a/src/vmime/net/smtp/SMTPCommand.hpp b/src/vmime/net/smtp/SMTPCommand.hpp index dbb0888b..a5b8cca5 100644 --- a/src/vmime/net/smtp/SMTPCommand.hpp +++ b/src/vmime/net/smtp/SMTPCommand.hpp @@ -60,6 +60,7 @@ public: static shared_ptr <SMTPCommand> HELO(const string& hostname); static shared_ptr <SMTPCommand> EHLO(const string& hostname); static shared_ptr <SMTPCommand> AUTH(const string& mechName); + static shared_ptr <SMTPCommand> AUTH(const string& mechName, const std::string& initialResponse); static shared_ptr <SMTPCommand> STARTTLS(); static shared_ptr <SMTPCommand> MAIL(const mailbox& mbox, const bool utf8); static shared_ptr <SMTPCommand> MAIL(const mailbox& mbox, const bool utf8, const size_t size); diff --git a/src/vmime/net/smtp/SMTPConnection.cpp b/src/vmime/net/smtp/SMTPConnection.cpp index a45f9149..4985b563 100644 --- a/src/vmime/net/smtp/SMTPConnection.cpp +++ b/src/vmime/net/smtp/SMTPConnection.cpp @@ -367,7 +367,25 @@ void SMTPConnection::authenticateSASL() saslSession->init(); - sendRequest(SMTPCommand::AUTH(mech->getName())); + if (saslSession->getMechanism()->hasInitialResponse()) + { + byte_t* initialResp = 0; + size_t initialRespLen = 0; + + saslSession->evaluateChallenge(NULL, 0, &initialResp, &initialRespLen); + + string encodedInitialResp(saslContext->encodeB64(initialResp, initialRespLen)); + delete [] initialResp; + + if (encodedInitialResp.empty()) + sendRequest(SMTPCommand::AUTH(mech->getName(), "=")); + else + sendRequest(SMTPCommand::AUTH(mech->getName(), encodedInitialResp)); + } + else + { + sendRequest(SMTPCommand::AUTH(mech->getName())); + } for (bool cont = true ; cont ; ) { |