Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vncpasswd add pwquality complexity rule check #1762

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions BUILDING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Build Requirements (Unix)
* You might have to enable additional repositories for this. E.g.,
on RHEL, EPEL and RPMFusion (free + nonfree) need to be enabled.

-- If building vncpasswd with password quality check support:
* libpwquality

============================
Build Requirements (Windows)
============================
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,20 @@ if(UNIX AND NOT APPLE)
endif()
endif()

# check for password pwquality check support
option(ENABLE_PWQUALITY "Enable password pwquality check" ON)
if(ENABLE_PWQUALITY)
if(UNIX)
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PWQUALITY pwquality)
if(PWQUALITY_FOUND)
add_definitions(-DHAVE_PWQUALITY)
endif()
endif()
endif()
endif()

# Generate config.h and make sure the source finds it
configure_file(config.h.in config.h)
add_definitions(-DHAVE_CONFIG_H)
Expand Down
4 changes: 4 additions & 0 deletions unix/vncpasswd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ add_executable(vncpasswd
target_include_directories(vncpasswd PUBLIC ${CMAKE_SOURCE_DIR}/common)
target_link_libraries(vncpasswd tx rfb os)

if(PWQUALITY_FOUND)
target_link_libraries(vncpasswd pwquality)
endif()

install(TARGETS vncpasswd DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
install(FILES vncpasswd.man DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man1 RENAME vncpasswd.1)
47 changes: 47 additions & 0 deletions unix/vncpasswd/vncpasswd.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

#include <termios.h>

#ifdef HAVE_PWQUALITY
#include <pwquality.h>
#endif

using namespace rfb;

Expand Down Expand Up @@ -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:");
Expand All @@ -116,6 +149,20 @@ static std::vector<uint8_t> readpassword() {
continue;
}

if (first.size() > 8) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! But could you split this to a separate commit? It's independent of using pwquality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps they should be submitted separately

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate commit, yes. But you don't need to open a separate PR for such a small fix.

fprintf(stderr,"Password should not be greater than 8 characters\nBecause only 8 valid characters are used - try again\n");
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");
Expand Down
Loading