kay / rpms / cyrus-sasl

Forked from rpms/cyrus-sasl 5 years ago
Clone

Blame cyrus-sasl-2.1.26-prefer-SCRAM-SHA-1-over-PLAIN.patch

58097f5
commit 26dcfb2d7176b78e70757aa5d01951a28ca217c7
58097f5
Author: Alexey Melnikov <alexey.melnikov@isode.com>
58097f5
Date:   Fri Jul 5 16:37:59 2013 +0100
58097f5
58097f5
    Treat SCRAM-SHA-1/DIGEST-MD5 as more secure than PLAIN when selecting the best client side SASL mechanism
58097f5
    
58097f5
    Both SCRAM-SHA-1 & DIGEST-MD5 are lacking SASL_SEC_PASS_CREDENTIALS security
58097f5
    flag, which prevented them from being chosen over PLAIN when PLAIN is selected
58097f5
    as the best mechanism first. For example the problem can be observed when
58097f5
    the server advertises "PLAIN DIGEST-MD5 SCRAM-SHA-1" (PLAIN just has to be
58097f5
    returned before SCRAM/DIGEST.)
58097f5
    
58097f5
    Cyrus SASL bug # 3793
58097f5
58097f5
diff --git a/lib/client.c b/lib/client.c
58097f5
index 62dfb0b..31fe346 100644
58097f5
--- a/lib/client.c
58097f5
+++ b/lib/client.c
58097f5
@@ -658,6 +658,20 @@ _sasl_cbinding_disp(sasl_client_params_t *cparams,
58097f5
     return SASL_OK;
58097f5
 }
58097f5
 
58097f5
+static int
58097f5
+_sasl_are_current_security_flags_worse_then_best(unsigned best_security_flags,
58097f5
+						 unsigned current_security_flags)
58097f5
+{
58097f5
+    /* We don't qualify SASL_SEC_PASS_CREDENTIALS as "secure" flag */
58097f5
+    best_security_flags &= ~SASL_SEC_PASS_CREDENTIALS;
58097f5
+
58097f5
+    if ((current_security_flags ^ best_security_flags) & best_security_flags) {
58097f5
+	return 1;
58097f5
+    } else {
58097f5
+	return 0;
58097f5
+    }
58097f5
+}
58097f5
+
58097f5
 /* select a mechanism for a connection
58097f5
  *  mechlist      -- mechanisms server has available (punctuation ignored)
58097f5
  *  secret        -- optional secret from previous session
58097f5
@@ -823,8 +837,9 @@ int sasl_client_start(sasl_conn_t *conn,
58097f5
 	     */
58097f5
 
58097f5
 	    if (bestm &&
58097f5
-		((m->m.plug->security_flags ^ bestm->m.plug->security_flags) &
58097f5
-		 bestm->m.plug->security_flags)) {
58097f5
+		_sasl_are_current_security_flags_worse_then_best(
58097f5
+		    bestm->m.plug->security_flags,
58097f5
+		    m->m.plug->security_flags)) {
58097f5
 		break;
58097f5
 	    }
58097f5