Skip to content

Commit a62fa95

Browse files
Roytakmichalvasko
authored andcommitted
session server ssh BUGFIX ncclient auth style
Handle the case where the ssh client doesnt probe for auth methods using the 'none' method first, but instead just directly tries to auth using e.g. pubkey auth, which lead to internal errors.
1 parent 0a3f1af commit a62fa95

1 file changed

Lines changed: 55 additions & 27 deletions

File tree

src/session_server_ssh.c

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,9 @@ nc_server_ssh_auth_password(struct nc_session *session, int local_users_supporte
12481248
/* obtain pw from config */
12491249
password = auth_client->password;
12501250
if (!password) {
1251-
VRB(session, "User \"%s\" does not have password method configured, but a request was received.", session->username);
1251+
/* client requested password auth, but it is not configured for this user, so just deny */
1252+
DBG(session,
1253+
"User \"%s\" does not have password method configured, but a request was received.", session->username);
12521254
return 1;
12531255
}
12541256
} else {
@@ -1294,23 +1296,40 @@ nc_server_ssh_auth_pubkey(struct nc_session *session, int local_users_supported,
12941296
assert(!local_users_supported || auth_client);
12951297

12961298
/* get the public keys */
1297-
if (!local_users_supported || (auth_client->pubkey_store == NC_STORE_SYSTEM)) {
1298-
/* system user or the user has 'use system keys' configured, these need to be free'd */
1299+
if (!local_users_supported) {
1300+
/* system user, get the keys from the system (these need to be free'd as they're not in the config) */
12991301
ret = nc_server_ssh_get_system_keys(session->username, &pubkeys, &pubkey_count);
13001302
if (ret) {
13011303
goto cleanup;
13021304
}
1303-
} else if (auth_client->pubkey_store == NC_STORE_LOCAL) {
1304-
pubkeys = auth_client->pubkeys;
1305-
pubkey_count = LY_ARRAY_COUNT(auth_client->pubkeys);
1306-
} else if (auth_client->pubkey_store == NC_STORE_TRUSTSTORE) {
1307-
ret = nc_server_ssh_ts_ref_get_keys(auth_client->ts_ref, &pubkeys, &pubkey_count);
1308-
if (ret) {
1309-
goto cleanup;
1310-
}
13111305
} else {
1312-
ERRINT;
1313-
return 1;
1306+
if (auth_client->pubkey_store == NC_STORE_UNKNOWN) {
1307+
/* client requested pubkey auth, but it is not configured for this user, so just deny */
1308+
DBG(session,
1309+
"User \"%s\" does not have public key method configured, but a request was received.", session->username);
1310+
return 1;
1311+
}
1312+
1313+
if (auth_client->pubkey_store == NC_STORE_SYSTEM) {
1314+
/* get the keys from the system (these need to be free'd as they're not in the config) */
1315+
ret = nc_server_ssh_get_system_keys(session->username, &pubkeys, &pubkey_count);
1316+
if (ret) {
1317+
goto cleanup;
1318+
}
1319+
} else if (auth_client->pubkey_store == NC_STORE_LOCAL) {
1320+
/* saved directly in the user's config */
1321+
pubkeys = auth_client->pubkeys;
1322+
pubkey_count = LY_ARRAY_COUNT(auth_client->pubkeys);
1323+
} else if (auth_client->pubkey_store == NC_STORE_TRUSTSTORE) {
1324+
/* need to fetch from the truststore */
1325+
ret = nc_server_ssh_ts_ref_get_keys(auth_client->ts_ref, &pubkeys, &pubkey_count);
1326+
if (ret) {
1327+
goto cleanup;
1328+
}
1329+
} else {
1330+
ERRINT;
1331+
return 1;
1332+
}
13141333
}
13151334

13161335
/* compare the received pubkey with the authorized ones */
@@ -1351,29 +1370,38 @@ nc_server_ssh_auth_pubkey(struct nc_session *session, int local_users_supported,
13511370
static int
13521371
nc_server_ssh_auth_kbdint(struct nc_session *session, int local_users_supported, struct nc_auth_client *auth_client, ssh_message msg)
13531372
{
1354-
int rc = 0;
1373+
int r = 0;
13551374

13561375
assert(!local_users_supported || auth_client);
13571376

1358-
if (local_users_supported && !auth_client->kbdint_method) {
1359-
VRB(session, "User \"%s\" does not have Keyboard-interactive method configured, but a request was received.", session->username);
1360-
return 1;
1361-
} else if (server_opts.interactive_auth_clb) {
1362-
rc = server_opts.interactive_auth_clb(session, session->ti.libssh.session, msg, server_opts.interactive_auth_data);
1363-
} else if (!local_users_supported) {
1377+
if (!local_users_supported) {
13641378
/* no local users supported, use the system method */
1365-
rc = nc_server_ssh_auth_kbdint_system(session, msg);
1379+
r = nc_server_ssh_auth_kbdint_system(session, msg);
13661380
} else {
1367-
/* perform the authentication based on the configured method */
1368-
if (auth_client->kbdint_method == NC_KBDINT_AUTH_METHOD_SYSTEM) {
1369-
rc = nc_server_ssh_auth_kbdint_system(session, msg);
1381+
if (auth_client->kbdint_method == NC_KBDINT_AUTH_METHOD_NONE) {
1382+
/* client requested kbdint auth, but it is not configured for this user, so just deny */
1383+
DBG(session,
1384+
"User \"%s\" does not have kbdint method configured, but a request was received.", session->username);
1385+
return 1;
1386+
}
1387+
1388+
if (server_opts.interactive_auth_clb) {
1389+
/* custom callback has higher priority */
1390+
r = server_opts.interactive_auth_clb(session,
1391+
session->ti.libssh.session, msg, server_opts.interactive_auth_data);
13701392
} else {
1371-
ERR(session, "Keyboard-interactive authentication method not supported.");
1372-
rc = 1;
1393+
/* perform the authentication based on the configured method */
1394+
if (auth_client->kbdint_method == NC_KBDINT_AUTH_METHOD_SYSTEM) {
1395+
r = nc_server_ssh_auth_kbdint_system(session, msg);
1396+
} else {
1397+
/* add future methods here */
1398+
ERR(session, "Keyboard-interactive authentication method not supported.");
1399+
return 1;
1400+
}
13731401
}
13741402
}
13751403

1376-
return rc ? 1 : 0;
1404+
return r ? 1 : 0;
13771405
}
13781406

13791407
/**

0 commit comments

Comments
 (0)