17
17
* under the License.
18
18
*/
19
19
20
+ #include "common/string.h"
21
+
20
22
#include "common-ssh/key.h"
21
23
#include "common-ssh/ssh.h"
22
24
#include "common-ssh/user.h"
41
43
#include <netinet/in.h>
42
44
#include <pthread.h>
43
45
#include <pwd.h>
46
+ #include <stdbool.h>
44
47
#include <stddef.h>
45
48
#include <stdlib.h>
46
49
#include <string.h>
@@ -64,7 +67,7 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
64
67
/**
65
68
* A list of ciphers that are both FIPS-compliant, and OpenSSL-supported.
66
69
*/
67
- #define FIPS_COMPLIANT_CIPHERS "aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc"
70
+ #define FIPS_COMPLIANT_CIPHERS "
[email protected] ,[email protected] ,aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc"
68
71
69
72
#ifdef OPENSSL_REQUIRES_THREADING_CALLBACKS
70
73
/**
@@ -412,6 +415,59 @@ static int guac_common_ssh_authenticate(guac_common_ssh_session* common_session)
412
415
413
416
}
414
417
418
+ /**
419
+ * Verifies if given algorithms are supported by libssh2.
420
+ * Writes log messages if an algorithm is not supported or
421
+ * could not get the list of supported algorithms from libssh2.
422
+ *
423
+ * @param client
424
+ * The Guacamole client that is using SSH.
425
+ *
426
+ * @param session
427
+ * The session associated with the user to be authenticated.
428
+ *
429
+ * @param method_type
430
+ * One of the libssh2 Method Type constants for libssh2_session_method_pref().
431
+ *
432
+ * @param algs
433
+ * A string with preferred list of algorithms, for example FIPS_COMPLIANT_CIPHERS.
434
+ *
435
+ */
436
+ static void check_if_algs_are_supported (guac_client * client , LIBSSH2_SESSION * session ,
437
+ int method_type , const char * algs ) {
438
+
439
+ /* Request the list of supported algorithms/cyphers from libssh2. */
440
+ const char * * supported_algs ;
441
+ int supported_algs_count =
442
+ libssh2_session_supported_algs (session , method_type , & supported_algs );
443
+
444
+ if (supported_algs_count > 0 ) {
445
+ char * * preferred_algs = guac_split (algs , ',' );
446
+ for (int i = 0 ; preferred_algs [i ]; i ++ ) {
447
+ bool found = false;
448
+ /* Check if the algorithm is found in the libssh2 supported list. */
449
+ for (int j = 0 ; j < supported_algs_count ; j ++ ) {
450
+ if (strcmp (preferred_algs [i ], supported_algs [j ]) == 0 ) {
451
+ found = true;
452
+ break ;
453
+ }
454
+ }
455
+ if (!found ) {
456
+ guac_client_log (client , GUAC_LOG_WARNING ,
457
+ "Preferred algorithm/cipher '%s' is not supported by libssh2" , preferred_algs [i ]);
458
+ }
459
+ }
460
+ guac_mem_free (preferred_algs );
461
+ /* should free if supported_algs_count is a positive number. */
462
+ libssh2_free (session , supported_algs );
463
+ }
464
+ else {
465
+ guac_client_log (client , GUAC_LOG_WARNING ,
466
+ "libssh2 reports that no ciphers/algorithms are supported. This may be a bug in libssh2. "
467
+ "If the SSH connection fails, it may not be possible to log the cause here." );
468
+ }
469
+ }
470
+
415
471
guac_common_ssh_session * guac_common_ssh_create_session (guac_client * client ,
416
472
const char * hostname , const char * port , guac_common_ssh_user * user ,
417
473
int timeout , int keepalive , const char * host_key ,
@@ -445,8 +501,16 @@ guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client,
445
501
* https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp2906.pdf
446
502
*/
447
503
if (guac_fips_enabled ()) {
504
+ /*
505
+ * The following algorithm check is only to simplify debugging.
506
+ * libssh2_session_method_pref() ignores unsupported methods.
507
+ * So they are not sent to the remote host during protocol negotiation anyways.
508
+ */
509
+ check_if_algs_are_supported (client , session , LIBSSH2_METHOD_KEX , FIPS_COMPLIANT_KEX_ALGORITHMS );
448
510
libssh2_session_method_pref (session , LIBSSH2_METHOD_KEX , FIPS_COMPLIANT_KEX_ALGORITHMS );
511
+ check_if_algs_are_supported (client , session , LIBSSH2_METHOD_CRYPT_CS , FIPS_COMPLIANT_CIPHERS );
449
512
libssh2_session_method_pref (session , LIBSSH2_METHOD_CRYPT_CS , FIPS_COMPLIANT_CIPHERS );
513
+ check_if_algs_are_supported (client , session , LIBSSH2_METHOD_CRYPT_SC , FIPS_COMPLIANT_CIPHERS );
450
514
libssh2_session_method_pref (session , LIBSSH2_METHOD_CRYPT_SC , FIPS_COMPLIANT_CIPHERS );
451
515
}
452
516
0 commit comments