I have successfully tried the following configuration:
...
verify-client-cert require
auth-user-pass-verify /etc/openvpn/auth-ldap-with-pam.pl via-file
script-security 3
...
and copied and patched the perl script to: /etc/openvpn/auth-ldap-with-pam.pl
# cp -a /usr/share/doc/openvpn/examples/sample-scripts/auth-pam.pl /etc/openvpn/auth-ldap-with-pam.pl
# cp -a /etc/openvpn/auth-ldap-with-pam.pl /etc/openvpn/auth-ldap-with-pam.pl.org
# vim /etc/openvpn/auth-ldap-with-pam.pl
# diff -c /etc/openvpn/auth-ldap-with-pam.pl /etc/openvpn/auth-ldap-with-pam.pl.org
*** /etc/openvpn/auth-ldap-with-pam.pl Fri Jun 23 09:16:44 2023
--- /etc/openvpn/auth-ldap-with-pam.pl.org Wed Dec 15 06:33:53 2021
***************
*** 76,91 ****
close (UPFILE);
- # check if the Common Name from the certificate is equal to the login name
- my $cn=$ENV{X509_0_CN};
- if ( "$username" ne "$cn" ) {
- print "ERROR OpenVPN login: the X509_0_CN '".$cn."' from the certificate is not equal to the login '".$username."' for the PAM authentication\n";
- exit 1;
- }
- else {
- print "DEBUG: the X509_0_CN '".$cn."' from the certificate was equal to the login '".$username."' for the PAM authentication\n";
- }
-
# Initialize PAM object
if (!ref($pamh = new Authen::PAM($service, $username, \&my_conv_func))) {
--- 76,81 ----
#
But this is using an authentification agains PAM and writes the login and password temporaerly in a text file, which is a security risk.
If anybody knows a better method (without "auth-user-pass-verify "), write it here please. Thanks.