diff options
author | hanjinpeng <hanjinpeng@kylinos.cn> | 2024-06-02 17:42:17 +0800 |
---|---|---|
committer | hanjinpeng <hanjinpeng@kylinos.cn> | 2024-08-14 00:31:35 +0800 |
commit | 6e3b38286d3b4953033fe7a1c776d20f06de1cd7 (patch) | |
tree | f613b442b42f00b4feaa4f1a8efa0a66d233c5f9 /unix/vncpasswd/vncpasswd.cxx | |
parent | fb7b956cf6c6cf2d2550c25a7112999983dea96e (diff) | |
download | tigervnc-6e3b38286d3b4953033fe7a1c776d20f06de1cd7.tar.gz tigervnc-6e3b38286d3b4953033fe7a1c776d20f06de1cd7.zip |
vncpasswd add password complexity rule check to enhance security
Use the library pwquality to check password complexity and improve security.
Additionally, optional enable support is also set in CMake.
Diffstat (limited to 'unix/vncpasswd/vncpasswd.cxx')
-rw-r--r-- | unix/vncpasswd/vncpasswd.cxx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/unix/vncpasswd/vncpasswd.cxx b/unix/vncpasswd/vncpasswd.cxx index 30091a3d..eb8ad037 100644 --- a/unix/vncpasswd/vncpasswd.cxx +++ b/unix/vncpasswd/vncpasswd.cxx @@ -37,6 +37,9 @@ #include <termios.h> +#ifdef HAVE_PWQUALITY +#include <pwquality.h> +#endif using namespace rfb; @@ -99,6 +102,36 @@ static int encrypt_pipe() { return 0; } +#ifdef HAVE_PWQUALITY +static int check_passwd_pwquality(const char *password) +{ + int r; + void *auxerror; + pwquality_settings_t *pwq; + pwq = pwquality_default_settings(); + if (!pwq) + return -EINVAL; + r = pwquality_read_config(pwq, NULL, &auxerror); + if (r) { + printf("Cannot check password quality: %s \n", + pwquality_strerror(NULL, 0, r, auxerror)); + pwquality_free_settings(pwq); + return -EINVAL; + } + + r = pwquality_check(pwq, password, NULL, NULL, &auxerror); + if (r < 0) { + printf("Password quality check failed:\n %s \n", + pwquality_strerror(NULL, 0, r, auxerror)); + r = -EPERM; + } + pwquality_free_settings(pwq); + + //return the score of password quality + return r; +} +#endif + static std::vector<uint8_t> readpassword() { while (true) { const char *passwd = getpassword("Password:"); @@ -116,6 +149,15 @@ static std::vector<uint8_t> readpassword() { continue; } +#ifdef HAVE_PWQUALITY + //the function return score of password quality + int r = check_passwd_pwquality(passwd); + if (r < 0){ + printf("Password quality check failed, please set it correctly.\n"); + continue; + } +#endif + passwd = getpassword("Verify:"); if (passwd == NULL) { perror("getpass error"); |