1
0
mirror of https://github.com/Yubico/yubikey-ksm.git synced 2024-11-29 00:24:14 +01:00
yubikey-ksm/selftest.sh

74 lines
2.1 KiB
Bash
Raw Normal View History

2013-11-06 14:54:42 +01:00
#!/bin/bash
set -e
set -x
if [ "x$DB" = "xmysql" ]; then
dbuser=travis
mysql -u $dbuser -e 'create database ykksm;'
mysql -u $dbuser ykksm < ykksm-db.sql
dbrun="mysql -u $dbuser ykksm -e"
2013-11-06 14:57:39 +01:00
elif [ "x$DB" = "xpgsql" ]; then
2013-11-06 14:54:42 +01:00
dbuser=postgres
psql -U $dbuser -c 'create database ykksm;'
psql -U $dbuser ykksm < ykksm-db.sql
dbrun="psql -U $dbuser ykksm -c"
2013-11-08 13:01:17 +01:00
elif [ "x$DB" = "xsqlite" ]; then
dbuser=""
dbfile=`mktemp`
sqlite3 $dbfile < ykksm-db.sql
sed -i "s,^.*db_dsn.*$,\$db_dsn = \"sqlite:$dbfile\";," ykksm-config.php
dbrun="sqlite3 $dbfile"
2013-11-06 14:57:39 +01:00
else
echo "unknown DB $DB"
exit 1
2013-11-06 14:54:42 +01:00
fi
cat > config-db.php << EOF
<?php
\$dbuser = '$dbuser';
\$dbpass = '';
\$dbname = 'ykksm';
\$dbtype = '$DB';
?>
EOF
2013-11-07 08:37:32 +01:00
sudo mkdir -p /etc/yubico/ksm/
sudo chmod 0755 /etc/yubico/ksm/
2013-11-06 14:54:42 +01:00
sudo mv config-db.php /etc/yubico/ksm/
$dbrun "insert into yubikeys (publicname,internalname,aeskey,serialnr,created,lockcode,creator) values('idkfefrdhtru','609963eae7b5','c68c9df8cbfe7d2f994cb904046c7218',0,0,'','');"
2013-11-06 14:54:42 +01:00
2013-11-06 15:09:01 +01:00
set +e
2013-11-07 09:30:59 +01:00
echo '' | php -B "\$_REQUEST = array('otp' => 'idkfefrdhtrutjduvtcjbfeuvhehdvjjlbchtlenfgku');" -F ykksm-decrypt.php | grep -q "^OK counter=0001 low=8d40 high=0f use=00"
2013-11-06 15:05:26 +01:00
if [ $? != 0 ]; then
2013-11-07 09:30:59 +01:00
echo '' | php -B "\$_REQUEST = array('otp' => 'idkfefrdhtrutjduvtcjbfeuvhehdvjjlbchtlenfgku');" -F ykksm-decrypt.php
2013-11-07 10:14:24 +01:00
sudo tail /var/log/auth.log
2013-11-06 15:05:26 +01:00
exit 1
else
2013-11-07 10:14:24 +01:00
echo "Success 1"
fi
echo '' | php -B "\$_REQUEST = array('otp' => 'idkfefrdhtrutjduvtcjbfeuvhehdvjjlbchtlenfgkv');" -F ykksm-decrypt.php | grep -q "^ERR Corrupt OTP"
if [ $? != 0 ]; then
echo '' | php -B "\$_REQUEST = array('otp' => 'idkfefrdhtrutjduvtcjbfeuvhehdvjjlbchtlenfgkv');" -F ykksm-decrypt.php
sudo tail /var/log/auth.log
exit 1
else
echo "Success 2"
fi
echo '' | php -B "\$_REQUEST = array('otp' => 'cdkfefrdhtrutjduvtcjbfeuvhehdvjjlbchtlenfgkv');" -F ykksm-decrypt.php | grep -q "^ERR Unknown yubikey"
if [ $? != 0 ]; then
echo '' | php -B "\$_REQUEST = array('otp' => 'cdkfefrdhtrutjduvtcjbfeuvhehdvjjlbchtlenfgkv');" -F ykksm-decrypt.php
sudo tail /var/log/auth.log
exit 1
else
echo "Success 3"
2013-11-06 15:05:26 +01:00
fi