Skip to content

Commit 7239779

Browse files
committed
Add option to enforce usage of SCRAM-*-PLUS variants
Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent 4ccd7e5 commit 7239779

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

src/auth.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,9 @@ static void _auth(xmpp_conn_t *conn)
765765
conn->ctx, "auth",
766766
"Password hasn't been set, and SASL ANONYMOUS unsupported.");
767767
xmpp_disconnect(conn);
768-
} else if (conn->sasl_support & SASL_MASK_SCRAM) {
768+
} else if ((conn->sasl_support & SASL_MASK_SCRAM_PLUS) ||
769+
((conn->sasl_support & SASL_MASK_SCRAM_WEAK) &&
770+
!conn->only_strong_auth)) {
769771
scram_ctx = strophe_alloc(conn->ctx, sizeof(*scram_ctx));
770772
memset(scram_ctx, 0, sizeof(*scram_ctx));
771773
if (conn->sasl_support & SASL_MASK_SCRAMSHA256_PLUS) {

src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ struct _xmpp_conn_t {
233233
mechanisms */
234234
int auth_legacy_enabled;
235235
int weak_auth_enabled;
236+
int only_strong_auth;
236237
int secured; /* set when stream is secured with TLS */
237238
xmpp_certfail_handler certfail_handler;
238239
xmpp_password_callback password_callback;

src/conn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,8 @@ long xmpp_conn_get_flags(const xmpp_conn_t *conn)
11131113
XMPP_CONN_FLAG_TRUST_TLS * conn->tls_trust |
11141114
XMPP_CONN_FLAG_DISABLE_SM * conn->sm_disable |
11151115
XMPP_CONN_FLAG_LEGACY_AUTH * conn->auth_legacy_enabled |
1116-
XMPP_CONN_FLAG_WEAK_AUTH * conn->weak_auth_enabled;
1116+
XMPP_CONN_FLAG_WEAK_AUTH * conn->weak_auth_enabled |
1117+
XMPP_CONN_FLAG_STRONG_AUTH * conn->only_strong_auth;
11171118

11181119
return flags;
11191120
}
@@ -1163,6 +1164,7 @@ int xmpp_conn_set_flags(xmpp_conn_t *conn, long flags)
11631164
conn->auth_legacy_enabled = (flags & XMPP_CONN_FLAG_LEGACY_AUTH) ? 1 : 0;
11641165
conn->sm_disable = (flags & XMPP_CONN_FLAG_DISABLE_SM) ? 1 : 0;
11651166
conn->weak_auth_enabled = (flags & XMPP_CONN_FLAG_WEAK_AUTH) ? 1 : 0;
1167+
conn->only_strong_auth = (flags & XMPP_CONN_FLAG_STRONG_AUTH) ? 1 : 0;
11661168

11671169
return 0;
11681170
}

strophe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ typedef struct _xmpp_sm_t xmpp_sm_state_t;
195195
* Allow weak authentication methods (DIGEST-MD5 and PLAIN).
196196
*/
197197
#define XMPP_CONN_FLAG_WEAK_AUTH (1UL << 6)
198+
/** @def XMPP_CONN_FLAG_STRONG_AUTH
199+
* Only allow strong authentication methods (Only the SCRAM-*-PLUS variants).
200+
*/
201+
#define XMPP_CONN_FLAG_STRONG_AUTH (1UL << 7)
198202

199203
/* connect callback */
200204
typedef enum {

0 commit comments

Comments
 (0)