Skip to content

Commit fac1900

Browse files
committed
Disable weak authentication methods per default
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
1 parent 3f03de0 commit fac1900

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/auth.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@ static void _auth(xmpp_conn_t *conn)
857857

858858
/* SASL algorithm was tried, unset flag */
859859
conn->sasl_support &= ~scram_ctx->alg->mask;
860-
} else if (conn->sasl_support & SASL_MASK_DIGESTMD5) {
860+
} else if ((conn->sasl_support & SASL_MASK_DIGESTMD5) &&
861+
conn->weak_auth_enabled) {
861862
auth = _make_sasl_auth(conn, "DIGEST-MD5");
862863
if (!auth) {
863864
disconnect_mem_error(conn);
@@ -871,7 +872,8 @@ static void _auth(xmpp_conn_t *conn)
871872

872873
/* SASL DIGEST-MD5 was tried, unset flag */
873874
conn->sasl_support &= ~SASL_MASK_DIGESTMD5;
874-
} else if (conn->sasl_support & SASL_MASK_PLAIN) {
875+
} else if ((conn->sasl_support & SASL_MASK_PLAIN) &&
876+
conn->weak_auth_enabled) {
875877
auth = _make_sasl_auth(conn, "PLAIN");
876878
if (!auth) {
877879
disconnect_mem_error(conn);

src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ struct _xmpp_conn_t {
259259
int sasl_support; /* if true, field is a bitfield of supported
260260
mechanisms */
261261
int auth_legacy_enabled;
262+
int weak_auth_enabled;
262263
int secured; /* set when stream is secured with TLS */
263264
xmpp_certfail_handler certfail_handler;
264265
xmpp_password_callback password_callback;

src/conn.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ long xmpp_conn_get_flags(const xmpp_conn_t *conn)
11331133
XMPP_CONN_FLAG_DISABLE_SM * conn->sm_disable |
11341134
XMPP_CONN_FLAG_ENABLE_COMPRESSION * conn->compression.allowed |
11351135
XMPP_CONN_FLAG_COMPRESSION_DONT_RESET * conn->compression.dont_reset |
1136+
XMPP_CONN_FLAG_WEAK_AUTH * conn->weak_auth_enabled |
11361137
XMPP_CONN_FLAG_LEGACY_AUTH * conn->auth_legacy_enabled;
11371138

11381139
return flags;
@@ -1188,11 +1189,13 @@ int xmpp_conn_set_flags(xmpp_conn_t *conn, long flags)
11881189
(flags & XMPP_CONN_FLAG_ENABLE_COMPRESSION) ? 1 : 0;
11891190
conn->compression.dont_reset =
11901191
(flags & XMPP_CONN_FLAG_COMPRESSION_DONT_RESET) ? 1 : 0;
1191-
flags &= ~(XMPP_CONN_FLAG_DISABLE_TLS | XMPP_CONN_FLAG_MANDATORY_TLS |
1192-
XMPP_CONN_FLAG_LEGACY_SSL | XMPP_CONN_FLAG_TRUST_TLS |
1193-
XMPP_CONN_FLAG_LEGACY_AUTH | XMPP_CONN_FLAG_DISABLE_SM |
1194-
XMPP_CONN_FLAG_ENABLE_COMPRESSION |
1195-
XMPP_CONN_FLAG_COMPRESSION_DONT_RESET);
1192+
conn->weak_auth_enabled = (flags & XMPP_CONN_FLAG_WEAK_AUTH) ? 1 : 0;
1193+
flags &=
1194+
~(XMPP_CONN_FLAG_DISABLE_TLS | XMPP_CONN_FLAG_MANDATORY_TLS |
1195+
XMPP_CONN_FLAG_LEGACY_SSL | XMPP_CONN_FLAG_TRUST_TLS |
1196+
XMPP_CONN_FLAG_LEGACY_AUTH | XMPP_CONN_FLAG_DISABLE_SM |
1197+
XMPP_CONN_FLAG_ENABLE_COMPRESSION |
1198+
XMPP_CONN_FLAG_COMPRESSION_DONT_RESET | XMPP_CONN_FLAG_WEAK_AUTH);
11961199
if (flags) {
11971200
strophe_error(conn->ctx, "conn", "Flags 0x%04lx unknown", flags);
11981201
return XMPP_EINVOP;

strophe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ typedef struct _xmpp_sm_t xmpp_sm_state_t;
208208
* Only enable this flag if you know what you're doing.
209209
*/
210210
#define XMPP_CONN_FLAG_COMPRESSION_DONT_RESET (1UL << 7)
211+
/** @def XMPP_CONN_FLAG_WEAK_AUTH
212+
* Allow weak authentication methods (DIGEST-MD5 and PLAIN).
213+
*/
214+
#define XMPP_CONN_FLAG_WEAK_AUTH (1UL << 8)
211215

212216
/* connect callback */
213217
typedef enum {

0 commit comments

Comments
 (0)