Skip to content
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

Implementation of initial responses with GNU SASL (resolves #319) #320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/vmime/net/imap/IMAPConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,24 @@ void IMAPConnection::authenticateSASL() {

const std::vector <string> capa = getCapabilities();
std::vector <string> saslMechs;
bool saslIR = false;

for (unsigned int i = 0 ; i < capa.size() ; ++i) {

const string& x = capa[i];

if (x.length() > 5 &&
if (x.length() == 7 &&
(x[0] == 'S' || x[0] == 's') &&
(x[1] == 'A' || x[1] == 'a') &&
(x[2] == 'S' || x[2] == 's') &&
(x[3] == 'L' || x[3] == 'l') &&
x[4] == '-' &&
(x[5] == 'I' || x[5] == 'i') &&
(x[6] == 'R' || x[6] == 'r')) {

saslIR = true;
}
else if (x.length() > 5 &&
(x[0] == 'A' || x[0] == 'a') &&
(x[1] == 'U' || x[1] == 'u') &&
(x[2] == 'T' || x[2] == 't') &&
Expand Down Expand Up @@ -397,7 +409,7 @@ void IMAPConnection::authenticateSASL() {

shared_ptr <IMAPCommand> authCmd;

if (saslSession->getMechanism()->hasInitialResponse()) {
if (saslIR && saslSession->getMechanism()->hasInitialResponse()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could simply use hasCapability() here, maybe more concise?

if (hasCapability("SASL-IR") && saslSession->getMechanism()->hasInitialResponse()) {


byte_t* initialResp = 0;
size_t initialRespLen = 0;
Expand Down
25 changes: 22 additions & 3 deletions src/vmime/security/sasl/builtinSASLMechanism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@

#include <stdexcept>
#include <new>
#include <unordered_set>

namespace {
const std::unordered_set<std::string> CLIENT_FIRST_MECHANISMS{
"ANONYMOUS",
"EXTERNAL",
"GS2-KRB5",
"GSSAPI",
"LOGIN",
"NTLM",
"OPENID20",
"PLAIN",
"SAML20",
"SCRAM-SHA-1",
"SCRAM-SHA-256",
"SECURID"
};
const auto CLIENT_FIRST_MECHANISMS_END = CLIENT_FIRST_MECHANISMS.cend();
}


namespace vmime {
Expand All @@ -51,7 +70,8 @@ builtinSASLMechanism::builtinSASLMechanism(
)
: m_context(ctx),
m_name(name),
m_complete(false) {
m_complete(false),
m_initialResponse(CLIENT_FIRST_MECHANISMS.find(name) != CLIENT_FIRST_MECHANISMS_END) {

}

Expand Down Expand Up @@ -140,8 +160,7 @@ bool builtinSASLMechanism::isComplete() const {

bool builtinSASLMechanism::hasInitialResponse() const {

// It seems GNU SASL does not support initial response
return false;
return m_initialResponse;
}


Expand Down
3 changes: 3 additions & 0 deletions src/vmime/security/sasl/builtinSASLMechanism.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class VMIME_EXPORT builtinSASLMechanism : public SASLMechanism {

/** Authentication process status. */
bool m_complete;

/** Whether the mechanism is client-first, and thus supports an initial response. */
bool m_initialResponse;
};


Expand Down
Loading