Skip to content

Commit 460e345

Browse files
committed
Add option to enforce usage of SCRAM-*-PLUS variants
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
1 parent fac1900 commit 460e345

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/auth.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,9 @@ static void _auth(xmpp_conn_t *conn)
799799
conn->ctx, "auth",
800800
"Password hasn't been set, and SASL ANONYMOUS unsupported.");
801801
xmpp_disconnect(conn);
802-
} else if (conn->sasl_support & SASL_MASK_SCRAM) {
802+
} else if ((conn->sasl_support & SASL_MASK_SCRAM_PLUS) ||
803+
((conn->sasl_support & SASL_MASK_SCRAM_WEAK) &&
804+
!conn->only_strong_auth)) {
803805
size_t n;
804806
scram_ctx = strophe_alloc(conn->ctx, sizeof(*scram_ctx));
805807
memset(scram_ctx, 0, sizeof(*scram_ctx));

src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ struct _xmpp_conn_t {
260260
mechanisms */
261261
int auth_legacy_enabled;
262262
int weak_auth_enabled;
263+
int only_strong_auth;
263264
int secured; /* set when stream is secured with TLS */
264265
xmpp_certfail_handler certfail_handler;
265266
xmpp_password_callback password_callback;

src/conn.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ long xmpp_conn_get_flags(const xmpp_conn_t *conn)
11341134
XMPP_CONN_FLAG_ENABLE_COMPRESSION * conn->compression.allowed |
11351135
XMPP_CONN_FLAG_COMPRESSION_DONT_RESET * conn->compression.dont_reset |
11361136
XMPP_CONN_FLAG_WEAK_AUTH * conn->weak_auth_enabled |
1137+
XMPP_CONN_FLAG_STRONG_AUTH * conn->only_strong_auth |
11371138
XMPP_CONN_FLAG_LEGACY_AUTH * conn->auth_legacy_enabled;
11381139

11391140
return flags;
@@ -1190,12 +1191,13 @@ int xmpp_conn_set_flags(xmpp_conn_t *conn, long flags)
11901191
conn->compression.dont_reset =
11911192
(flags & XMPP_CONN_FLAG_COMPRESSION_DONT_RESET) ? 1 : 0;
11921193
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);
1194+
conn->only_strong_auth = (flags & XMPP_CONN_FLAG_STRONG_AUTH) ? 1 : 0;
1195+
flags &= ~(XMPP_CONN_FLAG_DISABLE_TLS | XMPP_CONN_FLAG_MANDATORY_TLS |
1196+
XMPP_CONN_FLAG_LEGACY_SSL | XMPP_CONN_FLAG_TRUST_TLS |
1197+
XMPP_CONN_FLAG_LEGACY_AUTH | XMPP_CONN_FLAG_DISABLE_SM |
1198+
XMPP_CONN_FLAG_ENABLE_COMPRESSION |
1199+
XMPP_CONN_FLAG_COMPRESSION_DONT_RESET |
1200+
XMPP_CONN_FLAG_WEAK_AUTH | XMPP_CONN_FLAG_STRONG_AUTH);
11991201
if (flags) {
12001202
strophe_error(conn->ctx, "conn", "Flags 0x%04lx unknown", flags);
12011203
return XMPP_EINVOP;

strophe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ typedef struct _xmpp_sm_t xmpp_sm_state_t;
212212
* Allow weak authentication methods (DIGEST-MD5 and PLAIN).
213213
*/
214214
#define XMPP_CONN_FLAG_WEAK_AUTH (1UL << 8)
215+
/** @def XMPP_CONN_FLAG_STRONG_AUTH
216+
* Only allow strong authentication methods (Only the SCRAM-*-PLUS variants).
217+
*/
218+
#define XMPP_CONN_FLAG_STRONG_AUTH (1UL << 9)
215219

216220
/* connect callback */
217221
typedef enum {

0 commit comments

Comments
 (0)