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

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