1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-02-26 21:54:16 +01:00

Change PHP keywords to comply with PSR2

Signed-off-by: CodeLingoBot <bot@codelingo.io>
This commit is contained in:
CodeLingoBot 2019-04-05 20:13:25 +13:00
parent 18ced7b6e7
commit 3dcea401d0
14 changed files with 100 additions and 100 deletions

View File

@ -81,7 +81,7 @@ function sign($a, $apiKey, $logger)
$qs = utf8_encode($qs);
// base64 encoded binary digest
$hmac = hash_hmac('sha1', $qs, $apiKey, TRUE);
$hmac = hash_hmac('sha1', $qs, $apiKey, true);
$hmac = base64_encode($hmac);
$logger->log(LOG_DEBUG, "SIGN: $qs H=$hmac");
@ -96,17 +96,17 @@ function curl_settings($logger, $ident, $ch, $url, $timeout, $opts)
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, 'YK-VAL');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
if (is_array($opts) === FALSE)
if (is_array($opts) === false)
{
$logger->log(LOG_WARN, $ident . 'curl options must be an array');
return;
}
foreach ($opts as $key => $val)
if (curl_setopt($ch, $key, $val) === FALSE)
if (curl_setopt($ch, $key, $val) === false)
$logger->log(LOG_WARN, "$ident failed to set " . curl_opt_name($key));
}
@ -120,10 +120,10 @@ function curl_opt_name($opt)
$consts = get_defined_constants(true);
$consts = $consts['curl'];
$name = array_search($opt, $consts, TRUE);
$name = array_search($opt, $consts, true);
// array_search may return either on failure...
if ($name === FALSE || $name === NULL)
if ($name === false || $name === null)
return 'curl option';
return $name;
@ -136,7 +136,7 @@ function curl_opt_name($opt)
// long as one of the URLs given work, data will be returned. If all
// URLs fail, data from some URL that did not match parameter $match
// (defaults to ^OK) is returned, or if all URLs failed, false.
function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $returl=False, $timeout=10, $curlopts)
function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $returl=false, $timeout=10, $curlopts)
{
$mh = curl_multi_init();
$ch = array();
@ -216,9 +216,9 @@ function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $ret
function KSMdecryptOTP($urls, $logger, $curlopts)
{
$response = retrieveURLasync('YK-KSM', $urls, $logger, $ans_req=1, $match='^OK', $returl=False, $timeout=10, $curlopts);
$response = retrieveURLasync('YK-KSM', $urls, $logger, $ans_req=1, $match='^OK', $returl=false, $timeout=10, $curlopts);
if ($response === FALSE)
if ($response === false)
return false;
$response = array_shift($response);
@ -242,7 +242,7 @@ function KSMdecryptOTP($urls, $logger, $curlopts)
function sendResp($status, $logger, $apiKey = '', $extra = null)
{
if ($logger->request !== NULL)
if ($logger->request !== null)
$logger->request->set('status', $status);
$a['status'] = $status;
@ -272,7 +272,7 @@ function sendResp($status, $logger, $apiKey = '', $extra = null)
$logger->log(LOG_INFO, "Response: " . $str . " (at " . gmdate("c") . " " . microtime() . ")");
if ($logger->request !== NULL)
if ($logger->request !== null)
$logger->request->write();
echo $str;
@ -280,7 +280,7 @@ function sendResp($status, $logger, $apiKey = '', $extra = null)
}
// backport from PHP 5.6
if (function_exists('hash_equals') === FALSE)
if (function_exists('hash_equals') === false)
{
function hash_equals($a, $b)
{
@ -309,27 +309,27 @@ function total_time ($url)
$opts = array(
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 3,
CURLOPT_FORBID_REUSE => TRUE,
CURLOPT_FRESH_CONNECT => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FORBID_REUSE => true,
CURLOPT_FRESH_CONNECT => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'ykval-munin-vallatency/1.0',
);
if (($ch = curl_init()) === FALSE)
if (($ch = curl_init()) === false)
return false;
if (curl_setopt_array($ch, $opts) === FALSE)
if (curl_setopt_array($ch, $opts) === false)
return false;
// we don't care about the actual response
if (curl_exec($ch) === FALSE)
if (curl_exec($ch) === false)
return false;
$total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
curl_close($ch);
if (is_float($total_time) === FALSE)
if (is_float($total_time) === false)
return false;
return $total_time;
@ -355,7 +355,7 @@ function endpoints ($urls)
$internal = substr(sha1($url), 0, 20);
// actual label name shown for graph values
if (($label = hostport($url)) === FALSE)
if (($label = hostport($url)) === false)
{
return false;
}
@ -387,20 +387,20 @@ function endpoints ($urls)
*/
function hostport ($url)
{
if (($url = parse_url($url)) === FALSE)
if (($url = parse_url($url)) === false)
return false;
if (array_key_exists('host', $url) === FALSE || $url['host'] === NULL)
if (array_key_exists('host', $url) === false || $url['host'] === null)
return false;
if (array_key_exists('port', $url) === TRUE && $url['port'] !== NULL)
if (array_key_exists('port', $url) === true && $url['port'] !== null)
return $url['host'].':'.$url['port'];
if (array_key_exists('scheme', $url) === TRUE
if (array_key_exists('scheme', $url) === true
&& strtolower($url['scheme']) === 'http')
return $url['host'].':80';
if (array_key_exists('scheme', $url) === TRUE
if (array_key_exists('scheme', $url) === true
&& strtolower($url['scheme']) === 'https')
return $url['host'].':443';

View File

@ -72,7 +72,7 @@ class DbImpl extends Db
if (!$this->dbh) {
$error = oci_error();
$this->myLog->log(LOG_CRIT, "Database connection error: " . $error["message"]);
$this->dbh=Null;
$this->dbh=null;
return false;
}
return true;
@ -88,7 +88,7 @@ class DbImpl extends Db
$result = oci_parse($this->dbh, $query);
if(!oci_execute($result)) {
$this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r(oci_error($result), true)));
$this->dbh = Null;
$this->dbh = null;
return false;
}
$this->result = $result;

View File

@ -71,7 +71,7 @@ class DbImpl extends Db
$this->dbh = new PDO($this->db_dsn, $this->db_username, $this->db_password, $this->db_options);
} catch (PDOException $e) {
$this->myLog->log(LOG_CRIT, "Database connection error: " . $e->getMessage());
$this->dbh=Null;
$this->dbh=null;
return false;
}
return true;
@ -88,7 +88,7 @@ class DbImpl extends Db
$this->result = $this->dbh->query($query);
} catch (PDOException $e) {
$this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r($this->dbh->errorInfo(), true)));
$this->dbh = Null;
$this->dbh = null;
return false;
}
if ($returnresult) return $this->result;
@ -137,33 +137,33 @@ class DbImpl extends Db
*
* @return mixed Array with values from Db row or 2d-array with multiple rows
*/
public function findByMultiple($table, $where, $nr=NULL, $rev=NULL, $distinct=NULL)
public function findByMultiple($table, $where, $nr=null, $rev=null, $distinct=null)
{
$value = '';
$match = NULL;
$match = null;
$query = 'SELECT';
if ($distinct != NULL)
if ($distinct != null)
$query.= " DISTINCT " . $distinct;
else
$query.= " *";
$query.= " FROM " . $table;
if ($where != NULL)
if ($where != null)
{
foreach ($where as $key => $value)
{
if ($key != NULL)
if ($key != null)
{
if ($value != NULL)
if ($value != null)
$match .= " ". $key . " = '" . $value . "' and";
else
$match .= " ". $key . " is NULL and";
}
}
if ($match != NULL)
if ($match != null)
$query .= " WHERE" . $match;
$query = rtrim($query, "and");
@ -173,7 +173,7 @@ class DbImpl extends Db
if ($rev == 1)
$query.= " ORDER BY id DESC";
if ($nr != NULL)
if ($nr != null)
$query.= " LIMIT " . $nr;
$result = $this->query($query, true);

View File

@ -93,7 +93,7 @@ abstract class Db
*/
public function disconnect()
{
$this->dbh=NULL;
$this->dbh=null;
}
/**
@ -104,8 +104,8 @@ abstract class Db
*/
public function isConnected()
{
if ($this->dbh!=NULL) return True;
else return False;
if ($this->dbh!=null) return true;
else return false;
}
/**

View File

@ -31,27 +31,27 @@ require_once 'ykval-common.php';
class LogVerify
{
public $format = NULL;
public $format = null;
private $fields = array(
'time_start' => NULL,
'time_end' => NULL,
'time_taken' => NULL,
'ip' => NULL,
'client' => NULL,
'public_id' => NULL,
'otp' => NULL,
'status' => NULL,
'nonce' => NULL,
'signed' => NULL,
'counter' => NULL,
'low' => NULL,
'high' => NULL,
'use' => NULL,
'tls' => NULL,
'protocol' => NULL,
'sl' => NULL,
'timeout' => NULL,
'time_start' => null,
'time_end' => null,
'time_taken' => null,
'ip' => null,
'client' => null,
'public_id' => null,
'otp' => null,
'status' => null,
'nonce' => null,
'signed' => null,
'counter' => null,
'low' => null,
'high' => null,
'use' => null,
'tls' => null,
'protocol' => null,
'sl' => null,
'timeout' => null,
);
/**
@ -67,7 +67,7 @@ class LogVerify
if ($name === 'time_end' || $name === 'time_taken')
return false;
if (array_key_exists($name, $this->fields) === FALSE)
if (array_key_exists($name, $this->fields) === false)
return false;
$this->fields[$name] = $value;
@ -81,7 +81,7 @@ class LogVerify
*/
public function write()
{
if ($this->format === NULL)
if ($this->format === null)
return false;
$values = array();
@ -127,25 +127,25 @@ class LogVerify
if (preg_match('/^[0-9]+$/', $a['client']) !== 1)
$a['client'] = '-';
if (filter_var($a['ip'], FILTER_VALIDATE_IP) === FALSE)
if (filter_var($a['ip'], FILTER_VALIDATE_IP) === false)
$a['ip'] = '-';
if (is_int($a['counter']) === FALSE)
if (is_int($a['counter']) === false)
$a['counter'] = '-';
if (is_int($a['low']) === FALSE)
if (is_int($a['low']) === false)
$a['low'] = '-';
if (is_int($a['high']) === FALSE)
if (is_int($a['high']) === false)
$a['high'] = '-';
if (is_int($a['use']) === FALSE)
if (is_int($a['use']) === false)
$a['use'] = '-';
if (preg_match('/^[a-zA-Z0-9]{16,40}$/', $a['nonce']) !== 1)
$a['nonce'] = '-';
if (is_float($a['protocol']) === TRUE)
if (is_float($a['protocol']) === true)
$a['protocol'] = sprintf('%.1f', $a['protocol']);
else
$a['protocol'] = '-';

View File

@ -30,7 +30,7 @@
class Log
{
// request logger object
public $request = NULL;
public $request = null;
private $log_levels = array(
LOG_EMERG => 'LOG_EMERG',
@ -57,7 +57,7 @@ class Log
$this->fields[$name] = $value;
}
public function log ($priority, $message, $extra = NULL)
public function log ($priority, $message, $extra = null)
{
$prefix = '';
foreach ($this->fields as $val)

View File

@ -41,7 +41,7 @@ require_once 'ykval-common.php';
# otp and client ID should be moved to a munin environment variable
$urls = otp2ksmurls('ccccccccfnkjtvvijktfrvvginedlbvudjhjnggndtck', 16);
if (($endpoints = endpoints($urls)) === FALSE)
if (($endpoints = endpoints($urls)) === false)
{
echo "Cannot parse URLs from ksm url list\n";
exit(1);
@ -81,7 +81,7 @@ foreach ($endpoints as $endpoint)
{
list ($internal, $label, $url) = $endpoint;
if (($total_time = total_time($url)) === FALSE)
if (($total_time = total_time($url)) === false)
$total_time = 'error';
echo "${internal}_avgwait.value ${total_time}\n";

View File

@ -53,7 +53,7 @@ if ($argc == 2 && strcmp($argv[1], 'autoconf') == 0)
exit(0);
}
if (($endpoints = endpoints($urls)) === FALSE)
if (($endpoints = endpoints($urls)) === false)
{
echo "Cannot parse URLs from sync pool list\n";
exit(1);

View File

@ -52,7 +52,7 @@ if ($argc == 2 && strcmp($argv[1], 'autoconf') == 0)
exit(0);
}
if (($endpoints = endpoints($urls)) === FALSE)
if (($endpoints = endpoints($urls)) === false)
{
echo "Cannot parse URLs from sync pool list\n";
exit(1);
@ -86,7 +86,7 @@ foreach ($endpoints as $endpoint)
{
list ($internal, $label, $url) = $endpoint;
if (($total_time = total_time($url)) === FALSE)
if (($total_time = total_time($url)) === false)
$total_time = 'error';
echo "${internal}_avgwait.value ${total_time}\n";

View File

@ -81,7 +81,7 @@ function get_count($db, $table, $conditions)
return $r['count'];
}
return Null;
return null;
}
if ($count = get_count($db, 'yubikeys', 'active=true'))

View File

@ -84,7 +84,7 @@ if (! $sync->isConnected()) {
}
foreach($yubikeys as $key) {
if (($localParams = $sync->getLocalParams($key)) === FALSE) {
if (($localParams = $sync->getLocalParams($key)) === false) {
logdie($myLog, 'ERROR Invalid Yubikey ' . $key);
}

View File

@ -47,7 +47,7 @@ if (empty($_SERVER['QUERY_STRING']))
}
// verify request sent by whitelisted address
if (in_array($ipaddr, $allowed, TRUE) === FALSE)
if (in_array($ipaddr, $allowed, true) === false)
{
$myLog->log(LOG_NOTICE, "Operation not allowed from IP $ipaddr");
$myLog->log(LOG_DEBUG, "Remote IP $ipaddr not listed in allowed sync pool : " . implode(', ', $allowed));
@ -56,23 +56,23 @@ if (in_array($ipaddr, $allowed, TRUE) === FALSE)
// define requirements on protocol
$syncParams = array(
'modified' => NULL,
'otp' => NULL,
'nonce' => NULL,
'yk_publicname' => NULL,
'yk_counter' => NULL,
'yk_use' => NULL,
'yk_high' => NULL,
'yk_low' => NULL
'modified' => null,
'otp' => null,
'nonce' => null,
'yk_publicname' => null,
'yk_counter' => null,
'yk_use' => null,
'yk_high' => null,
'yk_low' => null
);
// extract values from HTTP request
$tmp_log = 'Received ';
foreach ($syncParams as $param => $value)
{
$value = getHttpVal($param, NULL, $_GET);
$value = getHttpVal($param, null, $_GET);
if ($value == NULL)
if ($value == null)
{
$myLog->log(LOG_NOTICE, "Received request with parameter[s] ($param) missing value");
sendResp(S_MISSING_PARAMETER, $myLog);
@ -114,7 +114,7 @@ foreach (array('modified','yk_counter', 'yk_use', 'yk_high', 'yk_low') as $param
// get local counter data
$yk_publicname = $syncParams['yk_publicname'];
if (($localParams = $sync->getLocalParams($yk_publicname)) === FALSE)
if (($localParams = $sync->getLocalParams($yk_publicname)) === false)
{
$myLog->log(LOG_NOTICE, "Invalid Yubikey $yk_publicname");
sendResp(S_BACKEND_ERROR, $myLog);

View File

@ -150,7 +150,7 @@ class SyncLib
return $result;
}
public function log($priority, $msg, $params=NULL)
public function log($priority, $msg, $params=null)
{
if ($params)
$msg .= ' modified=' . $params['modified'] .
@ -466,9 +466,9 @@ class SyncLib
}
// send out requests
$ans_arr = retrieveURLasync('YK-VAL sync', $urls, $this->myLog, $ans_req, $match='status=OK', $returl=True, $timeout, $this->curlopts);
$ans_arr = retrieveURLasync('YK-VAL sync', $urls, $this->myLog, $ans_req, $match='status=OK', $returl=true, $timeout, $this->curlopts);
if ($ans_arr === FALSE)
if ($ans_arr === false)
{
$this->log(LOG_WARNING, 'No responses from validation server pool');
$ans_arr = array();
@ -542,7 +542,7 @@ class SyncLib
* NULL queued_time for remaining entries in queue, to allow
* daemon to take care of them as soon as possible.
*/
$this->db->updateBy('queue', 'server_nonce', $this->server_nonce, array('queued'=>NULL));
$this->db->updateBy('queue', 'server_nonce', $this->server_nonce, array('queued'=>null));
/**
* Return true if valid answers equals required answers.

View File

@ -38,8 +38,8 @@ header('content-type: text/plain');
$ipaddr = $_SERVER['REMOTE_ADDR'];
$https = (array_key_exists('HTTPS', $_SERVER) === TRUE
&& strtolower($_SERVER['HTTPS']) !== 'off' ? TRUE : FALSE);
$https = (array_key_exists('HTTPS', $_SERVER) === true
&& strtolower($_SERVER['HTTPS']) !== 'off' ? true : false);
$myLog = new Log('ykval-verify');
$myLog->addField('ip', $ipaddr);
@ -255,7 +255,7 @@ if (! $sync->isConnected())
sendResp(S_BACKEND_ERROR, $myLog);
}
if (($cd = $sync->getClientData($client)) === FALSE)
if (($cd = $sync->getClientData($client)) === false)
{
$myLog->log(LOG_NOTICE, "Invalid client id $client");
sendResp(S_NO_SUCH_CLIENT, $myLog);
@ -277,7 +277,7 @@ if ($h != '')
$hmac = sign($request, $apiKey, $myLog);
if (hash_equals($hmac, $h) === FALSE)
if (hash_equals($hmac, $h) === false)
{
$myLog->log(LOG_DEBUG, "client hmac=$h, server hmac=$hmac");
sendResp(S_BAD_SIGNATURE, $myLog, $apiKey);
@ -308,7 +308,7 @@ if (array_key_exists('__YKVAL_KSM_CURL_OPTS__', $baseParams))
{
$curlopts = $baseParams['__YKVAL_KSM_CURL_OPTS__'];
}
if (($otpinfo = KSMdecryptOTP($urls, $myLog, $curlopts)) === FALSE)
if (($otpinfo = KSMdecryptOTP($urls, $myLog, $curlopts)) === false)
{
/**
* FIXME
@ -327,7 +327,7 @@ $myLog->log(LOG_DEBUG, 'Decrypted OTP:', $otpinfo);
// get Yubikey from DB
$public_id = substr($otp, 0, strlen ($otp) - TOKEN_LEN);
$myLog->request->set('public_id', $public_id);
if (($localParams = $sync->getLocalParams($public_id)) === FALSE)
if (($localParams = $sync->getLocalParams($public_id)) === false)
{
$myLog->log(LOG_NOTICE, "Invalid Yubikey $public_id");
sendResp(S_BACKEND_ERROR, $myLog, $apiKey);
@ -414,7 +414,7 @@ $myLog->log(LOG_INFO, '', array(
'timeout' => $timeout,
));
if ($syncres == False)
if ($syncres == false)
{
/* sync returned false, indicating that
either at least 1 answer marked OTP as invalid or