@@ -39,10 +39,10 @@ |
||
| 39 | 39 | * @return Tiqr_OcraService_Interface |
| 40 | 40 | * @throws Exception An exception if an unknown orca service type is requested. |
| 41 | 41 | */ |
| 42 | - public static function getOcraService(string $type="tiqr", array $options=array(), LoggerInterface $logger=null) |
|
| 42 | + public static function getOcraService(string $type = "tiqr", array $options = array(), LoggerInterface $logger = null) |
|
| 43 | 43 | { |
| 44 | 44 | if (!$logger) |
| 45 | - $logger=new \Psr\Log\NullLogger(); |
|
| 45 | + $logger = new \Psr\Log\NullLogger(); |
|
| 46 | 46 | |
| 47 | 47 | switch ($type) { |
| 48 | 48 | case "tiqr": |
@@ -41,8 +41,9 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | public static function getOcraService(string $type="tiqr", array $options=array(), LoggerInterface $logger=null) |
| 43 | 43 | { |
| 44 | - if (!$logger) |
|
| 45 | - $logger=new \Psr\Log\NullLogger(); |
|
| 44 | + if (!$logger) { |
|
| 45 | + $logger=new \Psr\Log\NullLogger(); |
|
| 46 | + } |
|
| 46 | 47 | |
| 47 | 48 | switch ($type) { |
| 48 | 49 | case "tiqr": |
@@ -45,10 +45,10 @@ |
||
| 45 | 45 | * @param LoggerInterface $logger |
| 46 | 46 | * @throws Exception An exception if an unknown storage is requested. |
| 47 | 47 | */ |
| 48 | - public static function getStorage($type="dummy", $options=array(), LoggerInterface $logger=null) |
|
| 48 | + public static function getStorage($type = "dummy", $options = array(), LoggerInterface $logger = null) |
|
| 49 | 49 | { |
| 50 | 50 | if (!$logger) |
| 51 | - $logger=new \Psr\Log\NullLogger(); |
|
| 51 | + $logger = new \Psr\Log\NullLogger(); |
|
| 52 | 52 | |
| 53 | 53 | switch ($type) { |
| 54 | 54 | case "dummy": |
@@ -47,8 +47,9 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | public static function getStorage($type="dummy", $options=array(), LoggerInterface $logger=null) |
| 49 | 49 | { |
| 50 | - if (!$logger) |
|
| 51 | - $logger=new \Psr\Log\NullLogger(); |
|
| 50 | + if (!$logger) { |
|
| 51 | + $logger=new \Psr\Log\NullLogger(); |
|
| 52 | + } |
|
| 52 | 53 | |
| 53 | 54 | switch ($type) { |
| 54 | 55 | case "dummy": |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | private function parseOCRASuite($ocraSuite) { |
| 47 | 47 | if (!is_string($ocraSuite)) { |
| 48 | - throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE)); |
|
| 48 | + throw new Exception('OCRASuite not in string format: '.var_export($ocraSuite, TRUE)); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $ocraSuite = strtoupper($ocraSuite); |
@@ -53,54 +53,54 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | $s = explode(':', $ocraSuite); |
| 55 | 55 | if (count($s) != 3) { |
| 56 | - throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE)); |
|
| 56 | + throw new Exception('Invalid OCRASuite format: '.var_export($ocraSuite, TRUE)); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $algo = explode('-', $s[0]); |
| 60 | 60 | if (count($algo) != 2) { |
| 61 | - throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE)); |
|
| 61 | + throw new Exception('Invalid OCRA version: '.var_export($s[0], TRUE)); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | if ($algo[0] !== 'OCRA') { |
| 65 | - throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE)); |
|
| 65 | + throw new Exception('Unsupported OCRA algorithm: '.var_export($algo[0], TRUE)); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | if ($algo[1] !== '1') { |
| 69 | - throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE)); |
|
| 69 | + throw new Exception('Unsupported OCRA version: '.var_export($algo[1], TRUE)); |
|
| 70 | 70 | } |
| 71 | 71 | $this->OCRAVersion = $algo[1]; |
| 72 | 72 | |
| 73 | 73 | $cf = explode('-', $s[1]); |
| 74 | 74 | if (count($cf) != 3) { |
| 75 | - throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE)); |
|
| 75 | + throw new Exception('Invalid OCRA suite crypto function: '.var_export($s[1], TRUE)); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | if ($cf[0] !== 'HOTP') { |
| 79 | - throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE)); |
|
| 79 | + throw new Exception('Unsupported OCRA suite crypto function: '.var_export($cf[0], TRUE)); |
|
| 80 | 80 | } |
| 81 | 81 | $this->CryptoFunctionType = $cf[0]; |
| 82 | 82 | |
| 83 | 83 | if (!array_key_exists($cf[1], $this->supportedHashFunctions)) { |
| 84 | - throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE)); |
|
| 84 | + throw new Exception('Unsupported hash function in OCRA suite crypto function: '.var_export($cf[1], TRUE)); |
|
| 85 | 85 | } |
| 86 | 86 | $this->CryptoFunctionHash = $cf[1]; |
| 87 | 87 | $this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]]; |
| 88 | 88 | |
| 89 | 89 | if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) { |
| 90 | - throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE)); |
|
| 90 | + throw new Exception('Invalid OCRA suite crypto function truncation length: '.var_export($cf[2], TRUE)); |
|
| 91 | 91 | } |
| 92 | 92 | $this->CryptoFunctionTruncation = intval($cf[2]); |
| 93 | 93 | |
| 94 | 94 | $di = explode('-', $s[2]); |
| 95 | 95 | if (count($cf) == 0) { |
| 96 | - throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE)); |
|
| 96 | + throw new Exception('Invalid OCRA suite data input: '.var_export($s[2], TRUE)); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | $data_input = array(); |
| 100 | - foreach($di as $elem) { |
|
| 100 | + foreach ($di as $elem) { |
|
| 101 | 101 | $letter = $elem[0]; |
| 102 | 102 | if (array_key_exists($letter, $data_input)) { |
| 103 | - throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE)); |
|
| 103 | + throw new Exception('Duplicate field in OCRA suite data input: '.var_export($elem, TRUE)); |
|
| 104 | 104 | } |
| 105 | 105 | $data_input[$letter] = 1; |
| 106 | 106 | |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | } elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) { |
| 113 | 113 | $q_len = intval($match[2]); |
| 114 | 114 | if ($q_len < 4 || $q_len > 64) { |
| 115 | - throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE)); |
|
| 115 | + throw new Exception('Invalid OCRA suite data input question length: '.var_export($q_len, TRUE)); |
|
| 116 | 116 | } |
| 117 | 117 | $this->Q = TRUE; |
| 118 | 118 | $this->QType = $match[1]; |
| 119 | 119 | $this->QLength = $q_len; |
| 120 | 120 | } else { |
| 121 | - throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE)); |
|
| 121 | + throw new Exception('Invalid OCRA suite data input question: '.var_export($elem, TRUE)); |
|
| 122 | 122 | } |
| 123 | 123 | } elseif ($letter === 'P') { |
| 124 | 124 | if (strlen($elem) == 1) { |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } else { |
| 127 | 127 | $p_algo = substr($elem, 1); |
| 128 | 128 | if (!array_key_exists($p_algo, $this->supportedHashFunctions)) { |
| 129 | - throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE)); |
|
| 129 | + throw new Exception('Unsupported OCRA suite PIN hash function: '.var_export($elem, TRUE)); |
|
| 130 | 130 | } |
| 131 | 131 | $this->P = TRUE; |
| 132 | 132 | $this->PType = $p_algo; |
@@ -138,13 +138,13 @@ discard block |
||
| 138 | 138 | } elseif (preg_match('/^S(\d+)$/', $elem, $match)) { |
| 139 | 139 | $s_len = intval($match[1]); |
| 140 | 140 | if ($s_len <= 0 || $s_len > 512) { |
| 141 | - throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE)); |
|
| 141 | + throw new Exception('Invalid OCRA suite data input session information length: '.var_export($s_len, TRUE)); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $this->S = TRUE; |
| 145 | 145 | $this->SLength = $s_len; |
| 146 | 146 | } else { |
| 147 | - throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE)); |
|
| 147 | + throw new Exception('Invalid OCRA suite data input session information length: '.var_export($elem, TRUE)); |
|
| 148 | 148 | } |
| 149 | 149 | } elseif ($letter === 'T') { |
| 150 | 150 | if (strlen($elem) == 1) { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | preg_match_all('/(\d+)([HMS])/', $elem, $match); |
| 154 | 154 | |
| 155 | 155 | if (count($match[1]) !== count(array_unique($match[2]))) { |
| 156 | - throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE)); |
|
| 156 | + throw new Exception('Duplicate definitions in OCRA suite data input timestamp: '.var_export($elem, TRUE)); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $length = 0; |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | $length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]]; |
| 162 | 162 | } |
| 163 | 163 | if ($length <= 0) { |
| 164 | - throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE)); |
|
| 164 | + throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE)); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $this->T = TRUE; |
| 168 | 168 | $this->TLength = $length; |
| 169 | 169 | } else { |
| 170 | - throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE)); |
|
| 170 | + throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE)); |
|
| 171 | 171 | } |
| 172 | 172 | } else { |
| 173 | - throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE)); |
|
| 173 | + throw new Exception('Unsupported OCRA suite data input field: '.var_export($elem, TRUE)); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | if (!$this->Q) { |
| 178 | - throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE)); |
|
| 178 | + throw new Exception('OCRA suite data input question not defined: '.var_export($s[2], TRUE)); |
|
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | $bytes = Tiqr_Random::randomBytes($q_length); |
| 198 | 198 | |
| 199 | - switch($q_type) { |
|
| 199 | + switch ($q_type) { |
|
| 200 | 200 | case 'A': |
| 201 | 201 | $challenge = base64_encode($bytes); |
| 202 | 202 | $tr = implode("", unpack('H*', $bytes)); |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | $challenge = implode("", unpack('N*', $bytes)); |
| 210 | 210 | break; |
| 211 | 211 | default: |
| 212 | - throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE)); |
|
| 212 | + throw new Exception('Unsupported OCRASuite challenge type: '.var_export($q_type, TRUE)); |
|
| 213 | 213 | break; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | $result &= ($s1[$i] == $s2[$i]); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - return (boolean)$result; |
|
| 236 | + return (boolean) $result; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | $this->logger = $logger; |
| 36 | 36 | |
| 37 | 37 | // Set the OCRA suite |
| 38 | - $this->_ocraSuite = $config['ocra.suite'] ?? 'OCRA-1:HOTP-SHA1-6:QH10-S'; // Use tiqr server default suite |
|
| 38 | + $this->_ocraSuite = $config['ocra.suite'] ?? 'OCRA-1:HOTP-SHA1-6:QH10-S'; // Use tiqr server default suite |
|
| 39 | 39 | $this->_ocraParser = new OATH_OCRAParser($this->_ocraSuite); |
| 40 | 40 | } |
| 41 | 41 | |