1*e670fd5cSchristos#! /bin/sh 2*e670fd5cSchristos# $OpenLDAP$ 3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4*e670fd5cSchristos## 5*e670fd5cSchristos## Copyright 2016-2021 Ondřej Kuzník, Symas Corp. 6*e670fd5cSchristos## Copyright 2021 The OpenLDAP Foundation. 7*e670fd5cSchristos## All rights reserved. 8*e670fd5cSchristos## 9*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without 10*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP 11*e670fd5cSchristos## Public License. 12*e670fd5cSchristos## 13*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the 14*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at 15*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>. 16*e670fd5cSchristos 17*e670fd5cSchristosecho "running defines.sh" 18*e670fd5cSchristos. $SRCDIR/scripts/defines.sh 19*e670fd5cSchristos 20*e670fd5cSchristosif test $OTP = otpno; then 21*e670fd5cSchristos echo "OTP overlay not available, test skipped" 22*e670fd5cSchristos exit 0 23*e670fd5cSchristosfi 24*e670fd5cSchristos 25*e670fd5cSchristosOTP_DATA=$DATADIR/otp/hotp.ldif 26*e670fd5cSchristos 27*e670fd5cSchristos# OTPs for this token 28*e670fd5cSchristosTOKEN_0=818800 29*e670fd5cSchristosTOKEN_1=320382 30*e670fd5cSchristosTOKEN_2=404533 31*e670fd5cSchristosTOKEN_3=127122 32*e670fd5cSchristosTOKEN_4=892599 33*e670fd5cSchristosTOKEN_5=407030 34*e670fd5cSchristosTOKEN_6=880935 35*e670fd5cSchristosTOKEN_7=920291 36*e670fd5cSchristosTOKEN_8=145192 37*e670fd5cSchristosTOKEN_9=316404 38*e670fd5cSchristosTOKEN_10=409144 39*e670fd5cSchristos 40*e670fd5cSchristos# OTPs for the second set of parameters 41*e670fd5cSchristosTOKEN_SHA512_11=17544155 42*e670fd5cSchristosTOKEN_SHA512_12=48953477 43*e670fd5cSchristos 44*e670fd5cSchristosmkdir -p $TESTDIR $DBDIR1 45*e670fd5cSchristos 46*e670fd5cSchristosecho "Running slapadd to build slapd database..." 47*e670fd5cSchristos. $CONFFILTER $BACKEND < $CONF > $ADDCONF 48*e670fd5cSchristos$SLAPADD -f $ADDCONF -l $LDIFORDERED 49*e670fd5cSchristosRC=$? 50*e670fd5cSchristosif test $RC != 0 ; then 51*e670fd5cSchristos echo "slapadd failed ($RC)!" 52*e670fd5cSchristos exit $RC 53*e670fd5cSchristosfi 54*e670fd5cSchristos 55*e670fd5cSchristosmkdir $TESTDIR/confdir 56*e670fd5cSchristos. $CONFFILTER $BACKEND < $CONF > $CONF1 57*e670fd5cSchristos 58*e670fd5cSchristos$SLAPPASSWD -g -n >$CONFIGPWF 59*e670fd5cSchristosecho "database config" >>$CONF1 60*e670fd5cSchristosecho "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF1 61*e670fd5cSchristos 62*e670fd5cSchristosecho "Starting slapd on TCP/IP port $PORT1..." 63*e670fd5cSchristos$SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL > $LOG1 2>&1 & 64*e670fd5cSchristosPID=$! 65*e670fd5cSchristosif test $WAIT != 0 ; then 66*e670fd5cSchristos echo PID $PID 67*e670fd5cSchristos read foo 68*e670fd5cSchristosfi 69*e670fd5cSchristosKILLPIDS="$PID" 70*e670fd5cSchristos 71*e670fd5cSchristossleep $SLEEP0 72*e670fd5cSchristos 73*e670fd5cSchristosfor i in 0 1 2 3 4 5; do 74*e670fd5cSchristos $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 75*e670fd5cSchristos 'objectclass=*' > /dev/null 2>&1 76*e670fd5cSchristos RC=$? 77*e670fd5cSchristos if test $RC = 0 ; then 78*e670fd5cSchristos break 79*e670fd5cSchristos fi 80*e670fd5cSchristos echo "Waiting ${SLEEP1} seconds for slapd to start..." 81*e670fd5cSchristos sleep ${SLEEP1} 82*e670fd5cSchristosdone 83*e670fd5cSchristos 84*e670fd5cSchristosif [ "$OTP" = otpmod ]; then 85*e670fd5cSchristos$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF \ 86*e670fd5cSchristos >> $TESTOUT 2>&1 <<EOMOD 87*e670fd5cSchristosdn: cn=module,cn=config 88*e670fd5cSchristosobjectClass: olcModuleList 89*e670fd5cSchristoscn: module 90*e670fd5cSchristosolcModulePath: $TESTWD/../servers/slapd/overlays 91*e670fd5cSchristosolcModuleLoad: otp.la 92*e670fd5cSchristosEOMOD 93*e670fd5cSchristosRC=$? 94*e670fd5cSchristosif test $RC != 0 ; then 95*e670fd5cSchristos echo "ldapmodify failed ($RC)!" 96*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 97*e670fd5cSchristos exit $RC 98*e670fd5cSchristosfi 99*e670fd5cSchristosfi 100*e670fd5cSchristos 101*e670fd5cSchristosecho "Loading test otp configuration..." 102*e670fd5cSchristos$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \ 103*e670fd5cSchristos >> $TESTOUT 2>&1 <<EOMOD 104*e670fd5cSchristosdn: olcOverlay={0}otp,olcDatabase={1}$BACKEND,cn=config 105*e670fd5cSchristoschangetype: add 106*e670fd5cSchristosobjectClass: olcOverlayConfig 107*e670fd5cSchristosEOMOD 108*e670fd5cSchristosRC=$? 109*e670fd5cSchristosif test $RC != 0 ; then 110*e670fd5cSchristos echo "ldapmodify failed ($RC)!" 111*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 112*e670fd5cSchristos exit $RC 113*e670fd5cSchristosfi 114*e670fd5cSchristos 115*e670fd5cSchristosecho "Provisioning tokens and configuration..." 116*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 117*e670fd5cSchristos >> $TESTOUT 2>&1 < $OTP_DATA 118*e670fd5cSchristosRC=$? 119*e670fd5cSchristosif test $RC != 0 ; then 120*e670fd5cSchristos echo "ldapmodify failed ($RC)!" 121*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 122*e670fd5cSchristos exit $RC 123*e670fd5cSchristosfi 124*e670fd5cSchristos 125*e670fd5cSchristos 126*e670fd5cSchristosecho "Authentication tests:" 127*e670fd5cSchristosecho "\ttoken that's not valid yet..." 128*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w "bjensen$TOKEN_10" \ 129*e670fd5cSchristos >> $TESTOUT 2>&1 130*e670fd5cSchristosRC=$? 131*e670fd5cSchristosif test $RC != 49 ; then 132*e670fd5cSchristos echo "ldapwhoami should have failed ($RC)!" 133*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 134*e670fd5cSchristos exit $RC 135*e670fd5cSchristosfi 136*e670fd5cSchristos 137*e670fd5cSchristosecho "\ta valid and expected token..." 138*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w "bjensen$TOKEN_4" \ 139*e670fd5cSchristos >> $TESTOUT 2>&1 140*e670fd5cSchristosRC=$? 141*e670fd5cSchristosif test $RC != 0 ; then 142*e670fd5cSchristos echo "ldapwhoami failed ($RC)!" 143*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 144*e670fd5cSchristos exit $RC 145*e670fd5cSchristosfi 146*e670fd5cSchristos 147*e670fd5cSchristosecho "\ta valid token skipping some..." 148*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w "bjensen$TOKEN_6" \ 149*e670fd5cSchristos >> $TESTOUT 2>&1 150*e670fd5cSchristosRC=$? 151*e670fd5cSchristosif test $RC != 0 ; then 152*e670fd5cSchristos echo "ldapwhoami failed ($RC)!" 153*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 154*e670fd5cSchristos exit $RC 155*e670fd5cSchristosfi 156*e670fd5cSchristos 157*e670fd5cSchristosecho "\treusing the same token..." 158*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w "bjensen$TOKEN_6" \ 159*e670fd5cSchristos >> $TESTOUT 2>&1 160*e670fd5cSchristosRC=$? 161*e670fd5cSchristosif test $RC != 49 ; then 162*e670fd5cSchristos echo "ldapwhoami should have failed ($RC)!" 163*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 164*e670fd5cSchristos exit $RC 165*e670fd5cSchristosfi 166*e670fd5cSchristos 167*e670fd5cSchristosecho "\tanother account sharing the same token..." 168*e670fd5cSchristos$LDAPWHOAMI -D "$BJORNSDN" -H $URI1 -w "bjorn$TOKEN_7" \ 169*e670fd5cSchristos >> $TESTOUT 2>&1 170*e670fd5cSchristosRC=$? 171*e670fd5cSchristosif test $RC != 0 ; then 172*e670fd5cSchristos echo "ldapwhoami failed ($RC)!" 173*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 174*e670fd5cSchristos exit $RC 175*e670fd5cSchristosfi 176*e670fd5cSchristos 177*e670fd5cSchristosecho "\ttrying an old token..." 178*e670fd5cSchristos$LDAPWHOAMI -D "$BJORNSDN" -H $URI1 -w "bjorn$TOKEN_5" \ 179*e670fd5cSchristos >> $TESTOUT 2>&1 180*e670fd5cSchristosRC=$? 181*e670fd5cSchristosif test $RC != 49 ; then 182*e670fd5cSchristos echo "ldapwhoami should have failed ($RC)!" 183*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 184*e670fd5cSchristos exit $RC 185*e670fd5cSchristosfi 186*e670fd5cSchristos 187*e670fd5cSchristosecho "\tright token, wrong password..." 188*e670fd5cSchristos$LDAPWHOAMI -D "$BJORNSDN" -H $URI1 -w "bjensen$TOKEN_8" \ 189*e670fd5cSchristos >> $TESTOUT 2>&1 190*e670fd5cSchristosRC=$? 191*e670fd5cSchristosif test $RC != 49 ; then 192*e670fd5cSchristos echo "ldapwhoami should have failed ($RC)!" 193*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 194*e670fd5cSchristos exit $RC 195*e670fd5cSchristosfi 196*e670fd5cSchristos 197*e670fd5cSchristosecho "\tmaking sure previous token has been retired too..." 198*e670fd5cSchristos$LDAPWHOAMI -D "$BJORNSDN" -H $URI1 -w "bjorn$TOKEN_8" \ 199*e670fd5cSchristos >> $TESTOUT 2>&1 200*e670fd5cSchristosRC=$? 201*e670fd5cSchristosif test $RC != 49 ; then 202*e670fd5cSchristos echo "ldapwhoami should have failed ($RC)!" 203*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 204*e670fd5cSchristos exit $RC 205*e670fd5cSchristosfi 206*e670fd5cSchristos 207*e670fd5cSchristosecho "\tthe first token we tested that's just become valid..." 208*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w "bjensen$TOKEN_10" \ 209*e670fd5cSchristos >> $TESTOUT 2>&1 210*e670fd5cSchristosRC=$? 211*e670fd5cSchristosif test $RC != 0 ; then 212*e670fd5cSchristos echo "ldapwhoami failed ($RC)!" 213*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 214*e670fd5cSchristos exit $RC 215*e670fd5cSchristosfi 216*e670fd5cSchristos 217*e670fd5cSchristosecho "Reconfiguring token parameters..." 218*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 219*e670fd5cSchristos >/dev/null 2>&1 << EOMODS 220*e670fd5cSchristosdn: ou=Information Technology Division,ou=People,dc=example,dc=com 221*e670fd5cSchristoschangetype: modify 222*e670fd5cSchristosreplace: oathHOTPParams 223*e670fd5cSchristosoathHOTPParams: ou=Alumni Association,ou=People,dc=example,dc=com 224*e670fd5cSchristosEOMODS 225*e670fd5cSchristosRC=$? 226*e670fd5cSchristosif test $RC != 0 ; then 227*e670fd5cSchristos echo "ldapmodify failed ($RC)!" 228*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 229*e670fd5cSchristos exit $RC 230*e670fd5cSchristosfi 231*e670fd5cSchristos 232*e670fd5cSchristosecho "A new round of tests:" 233*e670fd5cSchristos 234*e670fd5cSchristosecho "\ta long token that's not valid yet..." 235*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w "bjensen$TOKEN_SHA512_12" \ 236*e670fd5cSchristos >> $TESTOUT 2>&1 237*e670fd5cSchristosRC=$? 238*e670fd5cSchristosif test $RC != 49 ; then 239*e670fd5cSchristos echo "ldapwhoami should have failed ($RC)!" 240*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 241*e670fd5cSchristos exit $RC 242*e670fd5cSchristosfi 243*e670fd5cSchristos 244*e670fd5cSchristosecho "\ta valid and expected token..." 245*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w "bjensen$TOKEN_SHA512_11" \ 246*e670fd5cSchristos >> $TESTOUT 2>&1 247*e670fd5cSchristosRC=$? 248*e670fd5cSchristosif test $RC != 0 ; then 249*e670fd5cSchristos echo "ldapwhoami failed ($RC)!" 250*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 251*e670fd5cSchristos exit $RC 252*e670fd5cSchristosfi 253*e670fd5cSchristos 254*e670fd5cSchristosecho "\tthe previous long token that's just become valid..." 255*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w "bjensen$TOKEN_SHA512_12" \ 256*e670fd5cSchristos >> $TESTOUT 2>&1 257*e670fd5cSchristosRC=$? 258*e670fd5cSchristosif test $RC != 0 ; then 259*e670fd5cSchristos echo "ldapwhoami failed ($RC)!" 260*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 261*e670fd5cSchristos exit $RC 262*e670fd5cSchristosfi 263*e670fd5cSchristos 264*e670fd5cSchristosecho "Retrieving token status..." 265*e670fd5cSchristos$LDAPSEARCH -b "ou=Information Technology Division,ou=People,dc=example,dc=com" \ 266*e670fd5cSchristos -H $URI1 objectclass=oathHOTPToken '@oathHOTPToken' \ 267*e670fd5cSchristos >> $SEARCHOUT 2>&1 268*e670fd5cSchristosRC=$? 269*e670fd5cSchristosif test $RC != 0 ; then 270*e670fd5cSchristos echo "ldapsearch failed ($RC)!" 271*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 272*e670fd5cSchristos exit $RC 273*e670fd5cSchristosfi 274*e670fd5cSchristos 275*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS 276*e670fd5cSchristos 277*e670fd5cSchristosLDIF=$DATADIR/otp/test001-out.ldif 278*e670fd5cSchristos 279*e670fd5cSchristosecho "Filtering ldapsearch results..." 280*e670fd5cSchristos$LDIFFILTER < $SEARCHOUT > $SEARCHFLT 281*e670fd5cSchristosecho "Filtering ldif with expected data..." 282*e670fd5cSchristos$LDIFFILTER < $LDIF > $LDIFFLT 283*e670fd5cSchristosecho "Comparing filter output..." 284*e670fd5cSchristos$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 285*e670fd5cSchristos 286*e670fd5cSchristosif test $? != 0 ; then 287*e670fd5cSchristos echo "Comparison failed" 288*e670fd5cSchristos exit 1 289*e670fd5cSchristosfi 290*e670fd5cSchristos 291*e670fd5cSchristosecho ">>>>> Test succeeded" 292*e670fd5cSchristos 293*e670fd5cSchristostest $KILLSERVERS != no && wait 294*e670fd5cSchristos 295*e670fd5cSchristosexit 0 296