mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-08-09 09:51:49 +08:00
auto-select group when a certificate provides enough information
When a certificate contains a single group there is no need to request the user to select. Auto-select the group. Resolves: #692 Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDXDCCAhSgAwIBAgIEaps0ATANBgkqhkiG9w0BAQsFADANMQswCQYDVQQDEwJD
|
||||
QTAgFw0xMzA2MDYxMjUxMjlaGA85OTk5MTIzMTIzNTk1OVowKjESMBAGA1UECxMJ
|
||||
b25seWdyb3VwMRQwEgYKCZImiZPyLGQBARMEdGVzdDCCASIwDQYJKoZIhvcNAQEB
|
||||
BQADggEPADCCAQoCggEBAN6qw04hFLOC2MRJ/D8+Cj5L3t8+8vDlPkRwyNdAFuaH
|
||||
GPloxK+AiFGXM/sH578/SjogH1FzfcKWH2RXlsPY7WH5sZy6wifOJ4vxKMcPKzDX
|
||||
RuPp/Nfte3vXpnuoTEwqHFXwjdgFb/RsgpRPKFyQACe0RmB6cEXkFk9m5nzWaX53
|
||||
KcfoYq9dfoQjQLodMf4ChS0Ig5EWM+9eukIACmN6lAyxkZ0T7lqj+yEG4Ab8hVvr
|
||||
U2v3A0okDnfxTYSjZ2FOOBoRkrtdQGosDScfOLKEGwtHfPP0tf5epddCMiqy9rIq
|
||||
ghU7TyjBRizaa5v1hbsHGG/O/r4bhAwMW387q0yyv8MCAwEAAaN1MHMwDAYDVR0T
|
||||
AQH/BAIwADATBgNVHSUEDDAKBggrBgEFBQcDAjAOBgNVHQ8BAf8EBAMCBaAwHQYD
|
||||
VR0OBBYEFNTtPyhLkhtMtVfBy+qKOOLovVgqMB8GA1UdIwQYMBaAFEgjNFMKiTE4
|
||||
SlrqyrbSpt7OHSsYMA0GCSqGSIb3DQEBCwUAA4IBMQBzkegY41jO5wFik/u6lzKH
|
||||
Bz9UZMxKO21++MN5HOWIvY4+PaQIJl9ozF+DKCp1jFDq52llxRw4jFgiwSmy0vZ8
|
||||
StVgteq83+QFTWAiTw37t1dRW/30mdlqYSMd5/LZQ/s3sCt0q8fApa0jrzx6XQuZ
|
||||
DAhUW4olcl9lBbC4CH929TpawgurBn1PTpBQQKoMugSPb8eGmL/lymSdmvSp4rbu
|
||||
hU48hv6jaN8k9IcM5A72xGYODnaI5F3PHeXP9DzQRsyGnrVbIswJMDhVYFnSCA4c
|
||||
SX2+bk4iY5Oh5HszdNorYDJ0/dNW0/ifYw7btfECZ/59t37DHP6kQU9RrGKXnJKj
|
||||
XZ3DNGI3m0dZt5ZTSdrOD1/3APLyRiVomOHoaioVS0E58bh+OS5svTL9oMONhDSV
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,7 @@
|
||||
dn = "uid=test,ou=onlygroup"
|
||||
tls_www_client
|
||||
signing_key
|
||||
encryption_key
|
||||
expiration_days = -1
|
||||
activation_date = "2013-06-06 14:51:29"
|
||||
serial = 0x6a9b3401
|
||||
@@ -0,0 +1,179 @@
|
||||
# User authentication method. Could be set multiple times and in that case
|
||||
# all should succeed.
|
||||
# Options: certificate, pam.
|
||||
auth = "certificate"
|
||||
#auth = "plain[@SRCDIR@/data/test-group.passwd]"
|
||||
#auth = "pam"
|
||||
|
||||
isolate-workers = @ISOLATE_WORKERS@
|
||||
|
||||
# A banner to be displayed on clients
|
||||
#banner = "Welcome"
|
||||
|
||||
# Use listen-host to limit to a specific IP or to the IPs of a provided hostname.
|
||||
#listen-host = [IP|HOSTNAME]
|
||||
|
||||
use-dbus = no
|
||||
|
||||
# Limit the number of clients. Unset or set to zero for unlimited.
|
||||
#max-clients = 1024
|
||||
max-clients = 16
|
||||
|
||||
# Limit the number of client connections to one every X milliseconds
|
||||
# (X is the provided value). Set to zero for no limit.
|
||||
#rate-limit-ms = 100
|
||||
|
||||
# Limit the number of identical clients (i.e., users connecting multiple times)
|
||||
# Unset or set to zero for unlimited.
|
||||
max-same-clients = 2
|
||||
|
||||
# TCP and UDP port number
|
||||
tcp-port = @PORT@
|
||||
udp-port = @PORT@
|
||||
|
||||
# Keepalive in seconds
|
||||
keepalive = 32400
|
||||
|
||||
# Dead peer detection in seconds
|
||||
dpd = 440
|
||||
|
||||
# MTU discovery (DPD must be enabled)
|
||||
try-mtu-discovery = false
|
||||
|
||||
# The key and the certificates of the server
|
||||
# The key may be a file, or any URL supported by GnuTLS (e.g.,
|
||||
# tpmkey:uuid=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx;storage=user
|
||||
# or pkcs11:object=my-vpn-key;object-type=private)
|
||||
#
|
||||
# There may be multiple certificate and key pairs and each key
|
||||
# should correspond to the preceding certificate.
|
||||
server-cert = @SRCDIR@/certs/server-cert.pem
|
||||
server-key = @SRCDIR@/certs/server-key.pem
|
||||
|
||||
# Diffie-Hellman parameters. Only needed if you require support
|
||||
# for the DHE ciphersuites (by default this server supports ECDHE).
|
||||
# Can be generated using:
|
||||
# certtool --generate-dh-params --outfile /path/to/dh.pem
|
||||
#dh-params = /path/to/dh.pem
|
||||
|
||||
# If you have a certificate from a CA that provides an OCSP
|
||||
# service you may provide a fresh OCSP status response within
|
||||
# the TLS handshake. That will prevent the client from connecting
|
||||
# independently on the OCSP server.
|
||||
# You can update this response periodically using:
|
||||
# ocsptool --ask --load-cert=your_cert --load-issuer=your_ca --outfile response
|
||||
# Make sure that you replace the following file in an atomic way.
|
||||
#ocsp-response = /path/to/ocsp.der
|
||||
|
||||
# In case PKCS #11 or TPM keys are used the PINs should be available
|
||||
# in files. The srk-pin-file is applicable to TPM keys only (It's the storage
|
||||
# root key).
|
||||
#pin-file = /path/to/pin.txt
|
||||
#srk-pin-file = /path/to/srkpin.txt
|
||||
|
||||
# The Certificate Authority that will be used
|
||||
# to verify clients if certificate authentication
|
||||
# is set.
|
||||
ca-cert = @SRCDIR@/certs/ca.pem
|
||||
|
||||
# The object identifier that will be used to read the user ID in the client certificate.
|
||||
# The object identifier should be part of the certificate's DN
|
||||
# Useful OIDs are:
|
||||
# CN = 2.5.4.3, UID = 0.9.2342.19200300.100.1.1
|
||||
cert-user-oid = 0.9.2342.19200300.100.1.1
|
||||
|
||||
# The object identifier that will be used to read the user group in the client
|
||||
# certificate. The object identifier should be part of the certificate's DN
|
||||
# Useful OIDs are:
|
||||
# OU (organizational unit) = 2.5.4.11
|
||||
cert-group-oid = 2.5.4.11
|
||||
|
||||
# Only "onlygroup" is an eligible group. Used to test that auto_select_cert_group()
|
||||
# correctly filters cert groups against the configured list.
|
||||
select-group = onlygroup
|
||||
|
||||
# A revocation list of ca-cert is set
|
||||
#crl = /path/to/crl.pem
|
||||
|
||||
# GnuTLS priority string
|
||||
tls-priorities = "PERFORMANCE:%SERVER_PRECEDENCE:%COMPAT"
|
||||
|
||||
# To enforce perfect forward secrecy (PFS) on the main channel.
|
||||
#tls-priorities = "NORMAL:%SERVER_PRECEDENCE:%COMPAT:-RSA"
|
||||
|
||||
# The time (in seconds) that a client is allowed to stay connected prior
|
||||
# to authentication
|
||||
auth-timeout = 40
|
||||
|
||||
# Script to call when a client connects and obtains an IP
|
||||
# Parameters are passed on the environment.
|
||||
# REASON, USERNAME, GROUPNAME, HOSTNAME (the hostname selected by client),
|
||||
# DEVICE, IP_REAL (the real IP of the client), IP_LOCAL (the local IP
|
||||
# in the P-t-P connection), IP_REMOTE (the VPN IP of the client). REASON
|
||||
# may be "connect" or "disconnect".
|
||||
#connect-script = /usr/bin/myscript
|
||||
#disconnect-script = /usr/bin/myscript
|
||||
|
||||
# UTMP
|
||||
use-utmp = true
|
||||
|
||||
# PID file
|
||||
pid-file = ./ocserv.pid
|
||||
|
||||
# The default server directory. Does not require any devices present.
|
||||
#chroot-dir = /path/to/chroot
|
||||
|
||||
# socket file used for IPC, will be appended with .PID
|
||||
# It must be accessible within the chroot environment (if any)
|
||||
socket-file = ./ocserv-socket
|
||||
|
||||
# The user the worker processes will be run as. It should be
|
||||
# unique (no other services run as this user).
|
||||
run-as-user = @USERNAME@
|
||||
run-as-group = @GROUP@
|
||||
|
||||
# Network settings
|
||||
|
||||
device = vpns
|
||||
|
||||
# The default domain to be advertised
|
||||
default-domain = example.com
|
||||
|
||||
ipv4-network = 192.168.1.0
|
||||
ipv4-netmask = 255.255.255.0
|
||||
# Use the keyword local to advertise the local P-t-P address as DNS server
|
||||
ipv4-dns = 192.168.1.1
|
||||
|
||||
# The NBNS server (if any)
|
||||
#ipv4-nbns = 192.168.2.3
|
||||
|
||||
#ipv6-address =
|
||||
#ipv6-mask =
|
||||
#ipv6-dns =
|
||||
|
||||
# Prior to leasing any IP from the pool ping it to verify that
|
||||
# it is not in use by another (unrelated to this server) host.
|
||||
ping-leases = false
|
||||
|
||||
# Leave empty to assign the default MTU of the device
|
||||
# mtu =
|
||||
|
||||
route = 192.168.1.0/255.255.255.0
|
||||
#route = 192.168.5.0/255.255.255.0
|
||||
|
||||
#
|
||||
# The following options are for (experimental) AnyConnect client
|
||||
# compatibility. They are only available if the server is built
|
||||
# with --enable-anyconnect
|
||||
#
|
||||
|
||||
# Client profile xml. A sample file exists in doc/profile.xml.
|
||||
# This file must be accessible from inside the worker's chroot.
|
||||
# The profile is ignored by the openconnect client.
|
||||
#user-profile = profile.xml
|
||||
|
||||
# Unless set to false it is required for clients to present their
|
||||
# certificate even if they are authenticating via a previously granted
|
||||
# cookie. Legacy CISCO clients do not do that, and thus this option
|
||||
# should be set for them.
|
||||
cisco-client-compat = true
|
||||
@@ -0,0 +1,175 @@
|
||||
# User authentication method. Could be set multiple times and in that case
|
||||
# all should succeed.
|
||||
# Options: certificate, pam.
|
||||
auth = "certificate"
|
||||
#auth = "plain[@SRCDIR@/data/test-group.passwd]"
|
||||
#auth = "pam"
|
||||
|
||||
isolate-workers = @ISOLATE_WORKERS@
|
||||
|
||||
# A banner to be displayed on clients
|
||||
#banner = "Welcome"
|
||||
|
||||
# Use listen-host to limit to a specific IP or to the IPs of a provided hostname.
|
||||
#listen-host = [IP|HOSTNAME]
|
||||
|
||||
use-dbus = no
|
||||
|
||||
# Limit the number of clients. Unset or set to zero for unlimited.
|
||||
#max-clients = 1024
|
||||
max-clients = 16
|
||||
|
||||
# Limit the number of client connections to one every X milliseconds
|
||||
# (X is the provided value). Set to zero for no limit.
|
||||
#rate-limit-ms = 100
|
||||
|
||||
# Limit the number of identical clients (i.e., users connecting multiple times)
|
||||
# Unset or set to zero for unlimited.
|
||||
max-same-clients = 2
|
||||
|
||||
# TCP and UDP port number
|
||||
tcp-port = @PORT@
|
||||
udp-port = @PORT@
|
||||
|
||||
# Keepalive in seconds
|
||||
keepalive = 32400
|
||||
|
||||
# Dead peer detection in seconds
|
||||
dpd = 440
|
||||
|
||||
# MTU discovery (DPD must be enabled)
|
||||
try-mtu-discovery = false
|
||||
|
||||
# The key and the certificates of the server
|
||||
# The key may be a file, or any URL supported by GnuTLS (e.g.,
|
||||
# tpmkey:uuid=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx;storage=user
|
||||
# or pkcs11:object=my-vpn-key;object-type=private)
|
||||
#
|
||||
# There may be multiple certificate and key pairs and each key
|
||||
# should correspond to the preceding certificate.
|
||||
server-cert = @SRCDIR@/certs/server-cert.pem
|
||||
server-key = @SRCDIR@/certs/server-key.pem
|
||||
|
||||
# Diffie-Hellman parameters. Only needed if you require support
|
||||
# for the DHE ciphersuites (by default this server supports ECDHE).
|
||||
# Can be generated using:
|
||||
# certtool --generate-dh-params --outfile /path/to/dh.pem
|
||||
#dh-params = /path/to/dh.pem
|
||||
|
||||
# If you have a certificate from a CA that provides an OCSP
|
||||
# service you may provide a fresh OCSP status response within
|
||||
# the TLS handshake. That will prevent the client from connecting
|
||||
# independently on the OCSP server.
|
||||
# You can update this response periodically using:
|
||||
# ocsptool --ask --load-cert=your_cert --load-issuer=your_ca --outfile response
|
||||
# Make sure that you replace the following file in an atomic way.
|
||||
#ocsp-response = /path/to/ocsp.der
|
||||
|
||||
# In case PKCS #11 or TPM keys are used the PINs should be available
|
||||
# in files. The srk-pin-file is applicable to TPM keys only (It's the storage
|
||||
# root key).
|
||||
#pin-file = /path/to/pin.txt
|
||||
#srk-pin-file = /path/to/srkpin.txt
|
||||
|
||||
# The Certificate Authority that will be used
|
||||
# to verify clients if certificate authentication
|
||||
# is set.
|
||||
ca-cert = @SRCDIR@/certs/ca.pem
|
||||
|
||||
# The object identifier that will be used to read the user ID in the client certificate.
|
||||
# The object identifier should be part of the certificate's DN
|
||||
# Useful OIDs are:
|
||||
# CN = 2.5.4.3, UID = 0.9.2342.19200300.100.1.1
|
||||
cert-user-oid = 0.9.2342.19200300.100.1.1
|
||||
|
||||
# The object identifier that will be used to read the user group in the client
|
||||
# certificate. The object identifier should be part of the certificate's DN
|
||||
# Useful OIDs are:
|
||||
# OU (organizational unit) = 2.5.4.11
|
||||
cert-group-oid = 2.5.4.11
|
||||
|
||||
# A revocation list of ca-cert is set
|
||||
#crl = /path/to/crl.pem
|
||||
|
||||
# GnuTLS priority string
|
||||
tls-priorities = "PERFORMANCE:%SERVER_PRECEDENCE:%COMPAT"
|
||||
|
||||
# To enforce perfect forward secrecy (PFS) on the main channel.
|
||||
#tls-priorities = "NORMAL:%SERVER_PRECEDENCE:%COMPAT:-RSA"
|
||||
|
||||
# The time (in seconds) that a client is allowed to stay connected prior
|
||||
# to authentication
|
||||
auth-timeout = 40
|
||||
|
||||
# Script to call when a client connects and obtains an IP
|
||||
# Parameters are passed on the environment.
|
||||
# REASON, USERNAME, GROUPNAME, HOSTNAME (the hostname selected by client),
|
||||
# DEVICE, IP_REAL (the real IP of the client), IP_LOCAL (the local IP
|
||||
# in the P-t-P connection), IP_REMOTE (the VPN IP of the client). REASON
|
||||
# may be "connect" or "disconnect".
|
||||
#connect-script = /usr/bin/myscript
|
||||
#disconnect-script = /usr/bin/myscript
|
||||
|
||||
# UTMP
|
||||
use-utmp = true
|
||||
|
||||
# PID file
|
||||
pid-file = ./ocserv.pid
|
||||
|
||||
# The default server directory. Does not require any devices present.
|
||||
#chroot-dir = /path/to/chroot
|
||||
|
||||
# socket file used for IPC, will be appended with .PID
|
||||
# It must be accessible within the chroot environment (if any)
|
||||
socket-file = ./ocserv-socket
|
||||
|
||||
# The user the worker processes will be run as. It should be
|
||||
# unique (no other services run as this user).
|
||||
run-as-user = @USERNAME@
|
||||
run-as-group = @GROUP@
|
||||
|
||||
# Network settings
|
||||
|
||||
device = vpns
|
||||
|
||||
# The default domain to be advertised
|
||||
default-domain = example.com
|
||||
|
||||
ipv4-network = 192.168.1.0
|
||||
ipv4-netmask = 255.255.255.0
|
||||
# Use the keyword local to advertise the local P-t-P address as DNS server
|
||||
ipv4-dns = 192.168.1.1
|
||||
|
||||
# The NBNS server (if any)
|
||||
#ipv4-nbns = 192.168.2.3
|
||||
|
||||
#ipv6-address =
|
||||
#ipv6-mask =
|
||||
#ipv6-dns =
|
||||
|
||||
# Prior to leasing any IP from the pool ping it to verify that
|
||||
# it is not in use by another (unrelated to this server) host.
|
||||
ping-leases = false
|
||||
|
||||
# Leave empty to assign the default MTU of the device
|
||||
# mtu =
|
||||
|
||||
route = 192.168.1.0/255.255.255.0
|
||||
#route = 192.168.5.0/255.255.255.0
|
||||
|
||||
#
|
||||
# The following options are for (experimental) AnyConnect client
|
||||
# compatibility. They are only available if the server is built
|
||||
# with --enable-anyconnect
|
||||
#
|
||||
|
||||
# Client profile xml. A sample file exists in doc/profile.xml.
|
||||
# This file must be accessible from inside the worker's chroot.
|
||||
# The profile is ignored by the openconnect client.
|
||||
#user-profile = profile.xml
|
||||
|
||||
# Unless set to false it is required for clients to present their
|
||||
# certificate even if they are authenticating via a previously granted
|
||||
# cookie. Legacy CISCO clients do not do that, and thus this option
|
||||
# should be set for them.
|
||||
cisco-client-compat = true
|
||||
+2
-1
@@ -147,7 +147,8 @@ if have_cwrap
|
||||
'haproxy-proxyproto', 'haproxy-proxyproto-v1',
|
||||
'drain-server', 'drain-server-fail',
|
||||
'test-ignore-querystring-of-post',
|
||||
'test-group-cert', 'test-fork', 'test-pass-svc', 'test-cert-svc',
|
||||
'test-group-cert', 'test-group-cert-autoselect',
|
||||
'test-fork', 'test-pass-svc', 'test-cert-svc',
|
||||
'test-secmod-kill', 'test-syslog-facility',
|
||||
]
|
||||
|
||||
|
||||
Executable
+291
@@ -0,0 +1,291 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2026 Nikos Mavrogiannopoulos
|
||||
#
|
||||
# This file is part of ocserv.
|
||||
#
|
||||
# ocserv is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2 of the License, or (at
|
||||
# your option) any later version.
|
||||
#
|
||||
# ocserv is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with GnuTLS; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
SERV="${SERV:-../src/ocserv}"
|
||||
srcdir=${srcdir:-.}
|
||||
NO_NEED_ROOT=1
|
||||
HEAD=$(mktemp)
|
||||
POST=$(mktemp)
|
||||
OUTFILE=$(mktemp)
|
||||
|
||||
. `dirname $0`/common.sh
|
||||
|
||||
eval "${GETPORT}"
|
||||
|
||||
echo "Testing cert-group auto-selection (#692)"
|
||||
|
||||
# Reproducer for #692: when cert-group-oid is configured and the client
|
||||
# certificate carries exactly one group, and no "select-group" list is
|
||||
# configured (so there is nothing to disambiguate), the server must not
|
||||
# force an extra "select your group" round trip before completing
|
||||
# authentication.
|
||||
|
||||
function finish {
|
||||
set +e
|
||||
echo " * Cleaning up..."
|
||||
test -n "${CONFIG}" && rm -f ${CONFIG} >/dev/null 2>&1
|
||||
rm -f $HEAD $POST $OUTFILE >/dev/null 2>&1
|
||||
cleanup
|
||||
}
|
||||
trap finish EXIT
|
||||
|
||||
update_config test-group-cert-autoselect.config
|
||||
launch_simple_sr_server -d 1 -f -c ${CONFIG}
|
||||
PID=$!
|
||||
wait_server $PID
|
||||
|
||||
TARGET=https://$ADDRESS:$PORT
|
||||
|
||||
cat >$HEAD <<_EOF
|
||||
Accept-Encoding:identity
|
||||
X-Transcend-Version:1
|
||||
X-Aggregate-Auth:1
|
||||
Connection:close
|
||||
_EOF
|
||||
|
||||
echo " * Sanity check: explicit group-select with a single certificate group"
|
||||
|
||||
# Sanity check: explicitly selecting the (only) certificate group works
|
||||
# and completes authentication immediately.
|
||||
cat >$POST <<_EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-auth client="vpn" type="init" aggregate-auth-version="2">
|
||||
<group-select>onlygroup</group-select>
|
||||
</config-auth>
|
||||
_EOF
|
||||
|
||||
LD_PRELOAD=libsocket_wrapper.so curl -i -A 'OpenConnect VPN Agent v9.12' \
|
||||
-H @$HEAD -k \
|
||||
--cert ${srcdir}/certs/user-group-single-cert.pem \
|
||||
--key ${srcdir}/certs/user-group-key.pem \
|
||||
-d@$POST $TARGET >$OUTFILE
|
||||
|
||||
grep 'auth id="success"' $OUTFILE >/dev/null
|
||||
if test $? != 0; then
|
||||
echo "Explicit group selection did not complete authentication"
|
||||
echo "==========================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grep "Set-Cookie: webvpncontext=" $OUTFILE >/dev/null
|
||||
if test $? != 0; then
|
||||
echo "Explicit group selection did not result in a session cookie"
|
||||
echo "============================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " * OK: explicit group selection completed authentication"
|
||||
|
||||
echo " * Reproducer: single eligible certificate group, no group-select sent"
|
||||
|
||||
# The actual reproducer: the client certificate has exactly one group
|
||||
# (OU=onlygroup) and the server has no "select-group" list configured
|
||||
# (so the single certificate group is unambiguous). Authenticate without
|
||||
# sending a <group-select> at all, as a first-contact AnyConnect client
|
||||
# would. Authentication must complete directly, without an extra
|
||||
# "Please select your group" prompt.
|
||||
cat >$POST <<_EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-auth client="vpn" type="init" aggregate-auth-version="2">
|
||||
<version who="vpn">4.8.03036</version>
|
||||
</config-auth>
|
||||
_EOF
|
||||
|
||||
LD_PRELOAD=libsocket_wrapper.so curl -i -A 'OpenConnect VPN Agent v9.12' \
|
||||
-H @$HEAD -k \
|
||||
--cert ${srcdir}/certs/user-group-single-cert.pem \
|
||||
--key ${srcdir}/certs/user-group-key.pem \
|
||||
-d@$POST $TARGET >$OUTFILE
|
||||
|
||||
grep "Please select your group" $OUTFILE >/dev/null
|
||||
if test $? = 0; then
|
||||
echo "Server asked to select a group despite the certificate"
|
||||
echo "containing a single, unambiguous group and no configured"
|
||||
echo "select-group list (issue #692)"
|
||||
echo "=========================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grep 'auth id="success"' $OUTFILE >/dev/null
|
||||
if test $? != 0; then
|
||||
echo "Authentication did not complete with the certificate's"
|
||||
echo "sole group automatically selected"
|
||||
echo "========================================================"
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grep "Set-Cookie: webvpncontext=" $OUTFILE >/dev/null
|
||||
if test $? != 0; then
|
||||
echo "Automatic group selection did not result in a session cookie"
|
||||
echo "=============================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " * OK: certificate's sole group was auto-selected, no prompt sent"
|
||||
|
||||
echo " * Ambiguous case: multiple eligible certificate groups, no group-select sent"
|
||||
|
||||
# Ambiguous case: the client certificate carries multiple groups
|
||||
# (OU=group1, group2, group3, group4) and the server has no
|
||||
# "select-group" list configured, so all of them are eligible and there
|
||||
# is no single unambiguous group to auto-select. The server must still
|
||||
# prompt the client to select a group.
|
||||
cat >$POST <<_EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-auth client="vpn" type="init" aggregate-auth-version="2">
|
||||
<version who="vpn">4.8.03036</version>
|
||||
</config-auth>
|
||||
_EOF
|
||||
|
||||
LD_PRELOAD=libsocket_wrapper.so curl -i -A 'OpenConnect VPN Agent v9.12' \
|
||||
-H @$HEAD -k \
|
||||
--cert ${srcdir}/certs/user-group-cert.pem \
|
||||
--key ${srcdir}/certs/user-group-key.pem \
|
||||
-d@$POST $TARGET >$OUTFILE
|
||||
|
||||
grep "Please select your group" $OUTFILE >/dev/null
|
||||
if test $? != 0; then
|
||||
echo "Server did not ask to select a group despite the certificate"
|
||||
echo "containing multiple, ambiguous groups and no configured"
|
||||
echo "select-group list"
|
||||
echo "=========================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ocserv always sends a Set-Cookie: webvpncontext= header, even to clear
|
||||
# a non-existing one (webvpncontext=; expires=...1970...). Only a
|
||||
# non-empty cookie value indicates a completed session.
|
||||
grep -E "Set-Cookie: webvpncontext=[^;[:space:]]" $OUTFILE >/dev/null
|
||||
if test $? = 0; then
|
||||
echo "Ambiguous group selection unexpectedly resulted in a session cookie"
|
||||
echo "====================================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " * OK: ambiguous certificate groups still require group selection"
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Restart the server with select-group = onlygroup to exercise the inner
|
||||
# filtering loop in auto_select_cert_group().
|
||||
# -----------------------------------------------------------------------
|
||||
cleanup
|
||||
mkdir -p $SOCKDIR
|
||||
|
||||
echo "Testing cert-group auto-selection with select-group filter (#692)"
|
||||
|
||||
update_config test-group-cert-autoselect-filter.config
|
||||
launch_simple_sr_server -d 1 -f -c ${CONFIG}
|
||||
PID=$!
|
||||
wait_server $PID
|
||||
|
||||
TARGET=https://$ADDRESS:$PORT
|
||||
|
||||
echo " * Filtered match: cert group is in select-group list, no group-select sent"
|
||||
|
||||
# select-group = onlygroup is configured; the client certificate carries
|
||||
# exactly one group (OU=onlygroup) which is in the list. The eligible set
|
||||
# has exactly one entry, so the server must auto-select it and complete
|
||||
# authentication without an extra round trip.
|
||||
cat >$POST <<_EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-auth client="vpn" type="init" aggregate-auth-version="2">
|
||||
<version who="vpn">4.8.03036</version>
|
||||
</config-auth>
|
||||
_EOF
|
||||
|
||||
LD_PRELOAD=libsocket_wrapper.so curl -i -A 'OpenConnect VPN Agent v9.12' \
|
||||
-H @$HEAD -k \
|
||||
--cert ${srcdir}/certs/user-group-single-cert.pem \
|
||||
--key ${srcdir}/certs/user-group-key.pem \
|
||||
-d@$POST $TARGET >$OUTFILE
|
||||
|
||||
grep "Please select your group" $OUTFILE >/dev/null
|
||||
if test $? = 0; then
|
||||
echo "Server prompted for group despite cert's sole group being in"
|
||||
echo "the configured select-group list (select-group filter path)"
|
||||
echo "=========================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grep 'auth id="success"' $OUTFILE >/dev/null
|
||||
if test $? != 0; then
|
||||
echo "Authentication did not complete with cert group auto-selected"
|
||||
echo "from the configured select-group list"
|
||||
echo "=============================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grep "Set-Cookie: webvpncontext=" $OUTFILE >/dev/null
|
||||
if test $? != 0; then
|
||||
echo "Filtered auto-selection did not result in a session cookie"
|
||||
echo "============================================================"
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " * OK: cert group in select-group list was auto-selected"
|
||||
|
||||
echo " * Filtered non-match: cert groups not in select-group list, no group-select sent"
|
||||
|
||||
# select-group = onlygroup is configured; the client certificate carries
|
||||
# four groups (OU=group1..4), none of which match "onlygroup". The eligible
|
||||
# set is empty, so the server must fall back to the group selection prompt.
|
||||
cat >$POST <<_EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config-auth client="vpn" type="init" aggregate-auth-version="2">
|
||||
<version who="vpn">4.8.03036</version>
|
||||
</config-auth>
|
||||
_EOF
|
||||
|
||||
LD_PRELOAD=libsocket_wrapper.so curl -i -A 'OpenConnect VPN Agent v9.12' \
|
||||
-H @$HEAD -k \
|
||||
--cert ${srcdir}/certs/user-group-cert.pem \
|
||||
--key ${srcdir}/certs/user-group-key.pem \
|
||||
-d@$POST $TARGET >$OUTFILE
|
||||
|
||||
grep "Please select your group" $OUTFILE >/dev/null
|
||||
if test $? != 0; then
|
||||
echo "Server did not prompt for group despite none of the cert's"
|
||||
echo "groups matching the configured select-group list"
|
||||
echo "=========================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grep -E "Set-Cookie: webvpncontext=[^;[:space:]]" $OUTFILE >/dev/null
|
||||
if test $? = 0; then
|
||||
echo "Non-matching cert groups unexpectedly resulted in a session cookie"
|
||||
echo "==================================================================="
|
||||
cat $OUTFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " * OK: cert groups not in select-group list still require group selection"
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user