@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function setBaseURL($apiBaseURL) |
| 27 | 27 | { |
| 28 | - $this->_apiBaseURL = rtrim($apiBaseURL, '/') . '/'; |
|
| 28 | + $this->_apiBaseURL = rtrim($apiBaseURL, '/').'/'; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | protected function callAPI($resource, $method = "GET", $data = array(), $headers = array()) |
| 79 | 79 | { |
| 80 | 80 | $ch = curl_init(); |
| 81 | - curl_setopt($ch, CURLOPT_URL, $this->_apiBaseURL . ltrim($resource, '/')); |
|
| 81 | + curl_setopt($ch, CURLOPT_URL, $this->_apiBaseURL.ltrim($resource, '/')); |
|
| 82 | 82 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 83 | 83 | |
| 84 | 84 | // Explicitly empty null values, because http_build_query will throw away |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $headerArray = array(); |
| 109 | 109 | foreach ($headers as $key => $value) { |
| 110 | - $headerArray[] = $key . ': ' . $value; |
|
| 110 | + $headerArray[] = $key.': '.$value; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | public function encrypt($data); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Decrypts the given data. |
|
| 44 | + * Decrypts the given data. |
|
| 45 | 45 | * |
| 46 | 46 | * @param String $data Data to decrypt. |
| 47 | 47 | * |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | - * Decrypts the given data. |
|
| 60 | + * Decrypts the given data. |
|
| 61 | 61 | * |
| 62 | 62 | * @param String $data Data to decrypt. |
| 63 | 63 | * |
@@ -127,7 +127,7 @@ |
||
| 127 | 127 | */ |
| 128 | 128 | public function __construct($config, $secretconfig = array()) |
| 129 | 129 | { |
| 130 | - parent::__construct($config, $secretconfig); |
|
| 130 | + parent::__construct($config, $secretconfig); |
|
| 131 | 131 | |
| 132 | 132 | $this->_userClass = isset($config['userClass']) ? $config['userClass'] : "tiqrPerson"; |
| 133 | 133 | $this->_dnPattern = isset($config['dnPattern']) ? $config['dnPattern'] : "%s"; |
@@ -162,7 +162,7 @@ |
||
| 162 | 162 | * |
| 163 | 163 | * @return mixed LDAP attribute value |
| 164 | 164 | */ |
| 165 | - protected function _getLDAPAttribute($entry, $attribName, $index=0) |
|
| 165 | + protected function _getLDAPAttribute($entry, $attribName, $index = 0) |
|
| 166 | 166 | { |
| 167 | 167 | $attribName = strtolower($attribName); |
| 168 | 168 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | public function userExists($userId) |
| 55 | 55 | { |
| 56 | 56 | $user = $this->_loadUser($userId, FALSE); |
| 57 | - return (is_array($user)||is_object($user)); |
|
| 57 | + return (is_array($user) || is_object($user)); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | if ($data = $this->_loadUser($userId)) { |
| 154 | 154 | $timestamp = $this->getTemporaryBlockTimestamp($userId); |
| 155 | 155 | // if not blocked or block is expired, return false |
| 156 | - if (!isset($data["blocked"]) || $data["blocked"]==false || (false !== $timestamp && false != $duration && (strtotime($timestamp) + $duration * 60) < time())) { |
|
| 156 | + if (!isset($data["blocked"]) || $data["blocked"] == false || (false !== $timestamp && false != $duration && (strtotime($timestamp) + $duration * 60) < time())) { |
|
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public function createUser($userId, $displayName) |
| 44 | 44 | { |
| 45 | 45 | $user = array("userId"=>$userId, |
| 46 | - "displayName"=>$displayName); |
|
| 46 | + "displayName"=>$displayName); |
|
| 47 | 47 | return $this->_saveUser($userId, $user); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | if ($data = $this->_loadUser($userId)) { |
| 79 | 79 | if (isset($data["notificationType"])) { |
| 80 | - return $data["notificationType"]; |
|
| 80 | + return $data["notificationType"]; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | return NULL; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | if ($data = $this->_loadUser($userId)) { |
| 104 | 104 | if (isset($data["notificationAddress"])) { |
| 105 | - return $data["notificationAddress"]; |
|
| 105 | + return $data["notificationAddress"]; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | $this->logger->info('Unable to find notification address for user'); |
@@ -94,8 +94,8 @@ |
||
| 94 | 94 | */ |
| 95 | 95 | public function getPath() |
| 96 | 96 | { |
| 97 | - if (substr($this->_path, -1)!="/") return $this->_path."/"; |
|
| 98 | - return $this->_path; |
|
| 97 | + if (substr($this->_path, -1)!="/") return $this->_path."/"; |
|
| 98 | + return $this->_path; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | } |
@@ -94,7 +94,9 @@ |
||
| 94 | 94 | */ |
| 95 | 95 | public function getPath() |
| 96 | 96 | { |
| 97 | - if (substr($this->_path, -1)!="/") return $this->_path."/"; |
|
| 97 | + if (substr($this->_path, -1)!="/") { |
|
| 98 | + return $this->_path."/"; |
|
| 99 | + } |
|
| 98 | 100 | return $this->_path; |
| 99 | 101 | } |
| 100 | 102 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | if ($data === NULL) { |
| 74 | 74 | if ($failIfNotFound) { |
| 75 | - throw new Exception('Error loading data for user: ' . var_export($userId, TRUE)); |
|
| 75 | + throw new Exception('Error loading data for user: '.var_export($userId, TRUE)); |
|
| 76 | 76 | } else { |
| 77 | 77 | $this->logger->error('Error loading data for user from user storage (file storage)'); |
| 78 | 78 | return false; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function getPath() |
| 104 | 104 | { |
| 105 | - if (substr($this->_path, -1)!="/") return $this->_path."/"; |
|
| 105 | + if (substr($this->_path, -1) != "/") return $this->_path."/"; |
|
| 106 | 106 | return $this->_path; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -90,9 +90,9 @@ |
||
| 90 | 90 | */ |
| 91 | 91 | public function verifyResponse($response, $secret, $challenge, $sessionKey) |
| 92 | 92 | { |
| 93 | - $expected = $this->calculateResponse($secret, $challenge, $sessionKey); |
|
| 93 | + $expected = $this->calculateResponse($secret, $challenge, $sessionKey); |
|
| 94 | 94 | |
| 95 | - return ($expected == $response); |
|
| 95 | + return ($expected == $response); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -107,7 +107,9 @@ |
||
| 107 | 107 | { |
| 108 | 108 | // find the :QN10, -QN10, QH10 etc. bit |
| 109 | 109 | $pos = stripos($ocraSuite, ":q"); |
| 110 | - if ($pos===false) $pos = stripos($ocraSuite, "-q"); |
|
| 110 | + if ($pos===false) { |
|
| 111 | + $pos = stripos($ocraSuite, "-q"); |
|
| 112 | + } |
|
| 111 | 113 | if ($pos===false) { |
| 112 | 114 | // No challenge config specified. Since we only support challenge based OCRA, we fallback to default 10 digit hexadecimal. |
| 113 | 115 | return array("format"=>"H", "length"=>10); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function generateSessionKey() |
| 65 | 65 | { |
| 66 | - return bin2hex( Tiqr_Random::randomBytes(self::SESSIONKEY_SIZE) ); |
|
| 66 | + return bin2hex(Tiqr_Random::randomBytes(self::SESSIONKEY_SIZE)); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -107,19 +107,19 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | // find the :QN10, -QN10, QH10 etc. bit |
| 109 | 109 | $pos = stripos($ocraSuite, ":q"); |
| 110 | - if ($pos===false) $pos = stripos($ocraSuite, "-q"); |
|
| 111 | - if ($pos===false) { |
|
| 110 | + if ($pos === false) $pos = stripos($ocraSuite, "-q"); |
|
| 111 | + if ($pos === false) { |
|
| 112 | 112 | // No challenge config specified. Since we only support challenge based OCRA, we fallback to default 10 digit hexadecimal. |
| 113 | 113 | return array("format"=>"H", "length"=>10); |
| 114 | 114 | } |
| 115 | - $format = substr($ocraSuite, $pos+2, 1); |
|
| 115 | + $format = substr($ocraSuite, $pos + 2, 1); |
|
| 116 | 116 | if (!in_array($format, array("N", "A", "H"))) { |
| 117 | 117 | $format = "H"; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $length = (int)substr($ocraSuite, $pos+3, 2); |
|
| 120 | + $length = (int) substr($ocraSuite, $pos + 3, 2); |
|
| 121 | 121 | |
| 122 | - if ($length<=0) { |
|
| 122 | + if ($length <= 0) { |
|
| 123 | 123 | $length = 10; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | protected function _calculateResponse($ocraSuite, $secret, $challenge, $sessionKey) |
| 192 | 192 | { |
| 193 | - if (strpos(strtolower($ocraSuite), "qn")!==false) { |
|
| 193 | + if (strpos(strtolower($ocraSuite), "qn") !== false) { |
|
| 194 | 194 | |
| 195 | 195 | // challenge is decimal, but generateOcra always wants it in hex. |
| 196 | 196 | $challenge = dechex($challenge); |
@@ -48,24 +48,24 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | protected function _getHash ($secret, $counter) |
| 50 | 50 | { |
| 51 | - // Counter |
|
| 52 | - //the counter value can be more than one byte long, so we need to go multiple times |
|
| 53 | - $cur_counter = array(0,0,0,0,0,0,0,0); |
|
| 54 | - for($i=7;$i>=0;$i--) |
|
| 55 | - { |
|
| 56 | - $cur_counter[$i] = pack ('C*', $counter); |
|
| 57 | - $counter = $counter >> 8; |
|
| 58 | - } |
|
| 59 | - $bin_counter = implode($cur_counter); |
|
| 60 | - // Pad to 8 chars |
|
| 61 | - if (strlen ($bin_counter) < 8) |
|
| 62 | - { |
|
| 63 | - $bin_counter = str_repeat (chr(0), 8 - strlen ($bin_counter)) . $bin_counter; |
|
| 64 | - } |
|
| 51 | + // Counter |
|
| 52 | + //the counter value can be more than one byte long, so we need to go multiple times |
|
| 53 | + $cur_counter = array(0,0,0,0,0,0,0,0); |
|
| 54 | + for($i=7;$i>=0;$i--) |
|
| 55 | + { |
|
| 56 | + $cur_counter[$i] = pack ('C*', $counter); |
|
| 57 | + $counter = $counter >> 8; |
|
| 58 | + } |
|
| 59 | + $bin_counter = implode($cur_counter); |
|
| 60 | + // Pad to 8 chars |
|
| 61 | + if (strlen ($bin_counter) < 8) |
|
| 62 | + { |
|
| 63 | + $bin_counter = str_repeat (chr(0), 8 - strlen ($bin_counter)) . $bin_counter; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - // HMAC |
|
| 67 | - $hash = hash_hmac ('sha1', $bin_counter, $secret); |
|
| 68 | - return $hash; |
|
| 66 | + // HMAC |
|
| 67 | + $hash = hash_hmac ('sha1', $bin_counter, $secret); |
|
| 68 | + return $hash; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -76,22 +76,22 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | protected function _truncate($hash, $length = 6) |
| 78 | 78 | { |
| 79 | - // Convert to dec |
|
| 80 | - foreach(str_split($hash,2) as $hex) |
|
| 81 | - { |
|
| 82 | - $hmac_result[]=hexdec($hex); |
|
| 83 | - } |
|
| 79 | + // Convert to dec |
|
| 80 | + foreach(str_split($hash,2) as $hex) |
|
| 81 | + { |
|
| 82 | + $hmac_result[]=hexdec($hex); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // Find offset |
|
| 86 | - $offset = $hmac_result[19] & 0xf; |
|
| 85 | + // Find offset |
|
| 86 | + $offset = $hmac_result[19] & 0xf; |
|
| 87 | 87 | |
| 88 | - // Algorithm from RFC |
|
| 89 | - return |
|
| 90 | - ( |
|
| 91 | - (($hmac_result[$offset+0] & 0x7f) << 24 ) | |
|
| 92 | - (($hmac_result[$offset+1] & 0xff) << 16 ) | |
|
| 93 | - (($hmac_result[$offset+2] & 0xff) << 8 ) | |
|
| 94 | - ($hmac_result[$offset+3] & 0xff) |
|
| 95 | - ) % pow(10,$length); |
|
| 88 | + // Algorithm from RFC |
|
| 89 | + return |
|
| 90 | + ( |
|
| 91 | + (($hmac_result[$offset+0] & 0x7f) << 24 ) | |
|
| 92 | + (($hmac_result[$offset+1] & 0xff) << 16 ) | |
|
| 93 | + (($hmac_result[$offset+2] & 0xff) << 8 ) | |
|
| 94 | + ($hmac_result[$offset+3] & 0xff) |
|
| 95 | + ) % pow(10,$length); |
|
| 96 | 96 | } |
| 97 | 97 | } |
@@ -46,25 +46,25 @@ discard block |
||
| 46 | 46 | * @param String $counter |
| 47 | 47 | * @return String hash |
| 48 | 48 | */ |
| 49 | - protected function _getHash ($secret, $counter) |
|
| 49 | + protected function _getHash($secret, $counter) |
|
| 50 | 50 | { |
| 51 | 51 | // Counter |
| 52 | 52 | //the counter value can be more than one byte long, so we need to go multiple times |
| 53 | - $cur_counter = array(0,0,0,0,0,0,0,0); |
|
| 54 | - for($i=7;$i>=0;$i--) |
|
| 53 | + $cur_counter = array(0, 0, 0, 0, 0, 0, 0, 0); |
|
| 54 | + for ($i = 7; $i >= 0; $i--) |
|
| 55 | 55 | { |
| 56 | - $cur_counter[$i] = pack ('C*', $counter); |
|
| 56 | + $cur_counter[$i] = pack('C*', $counter); |
|
| 57 | 57 | $counter = $counter >> 8; |
| 58 | 58 | } |
| 59 | 59 | $bin_counter = implode($cur_counter); |
| 60 | 60 | // Pad to 8 chars |
| 61 | - if (strlen ($bin_counter) < 8) |
|
| 61 | + if (strlen($bin_counter) < 8) |
|
| 62 | 62 | { |
| 63 | - $bin_counter = str_repeat (chr(0), 8 - strlen ($bin_counter)) . $bin_counter; |
|
| 63 | + $bin_counter = str_repeat(chr(0), 8 - strlen($bin_counter)).$bin_counter; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // HMAC |
| 67 | - $hash = hash_hmac ('sha1', $bin_counter, $secret); |
|
| 67 | + $hash = hash_hmac('sha1', $bin_counter, $secret); |
|
| 68 | 68 | return $hash; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | protected function _truncate($hash, $length = 6) |
| 78 | 78 | { |
| 79 | 79 | // Convert to dec |
| 80 | - foreach(str_split($hash,2) as $hex) |
|
| 80 | + foreach (str_split($hash, 2) as $hex) |
|
| 81 | 81 | { |
| 82 | - $hmac_result[]=hexdec($hex); |
|
| 82 | + $hmac_result[] = hexdec($hex); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // Find offset |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | // Algorithm from RFC |
| 89 | 89 | return |
| 90 | 90 | ( |
| 91 | - (($hmac_result[$offset+0] & 0x7f) << 24 ) | |
|
| 92 | - (($hmac_result[$offset+1] & 0xff) << 16 ) | |
|
| 93 | - (($hmac_result[$offset+2] & 0xff) << 8 ) | |
|
| 94 | - ($hmac_result[$offset+3] & 0xff) |
|
| 95 | - ) % pow(10,$length); |
|
| 91 | + (($hmac_result[$offset + 0] & 0x7f) << 24) | |
|
| 92 | + (($hmac_result[$offset + 1] & 0xff) << 16) | |
|
| 93 | + (($hmac_result[$offset + 2] & 0xff) << 8) | |
|
| 94 | + ($hmac_result[$offset + 3] & 0xff) |
|
| 95 | + ) % pow(10, $length); |
|
| 96 | 96 | } |
| 97 | 97 | } |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | $keyBytes, |
| 47 | 47 | $text) |
| 48 | 48 | { |
| 49 | - $hash = hash_hmac ($crypto, $text, $keyBytes); |
|
| 50 | - return $hash; |
|
| 49 | + $hash = hash_hmac ($crypto, $text, $keyBytes); |
|
| 50 | + return $hash; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | * {@link truncationDigits} digits |
| 84 | 84 | */ |
| 85 | 85 | static function generateOCRA($ocraSuite, |
| 86 | - $key, |
|
| 87 | - $counter, |
|
| 88 | - $question, |
|
| 89 | - $password, |
|
| 90 | - $sessionInformation, |
|
| 91 | - $timeStamp) |
|
| 86 | + $key, |
|
| 87 | + $counter, |
|
| 88 | + $question, |
|
| 89 | + $password, |
|
| 90 | + $sessionInformation, |
|
| 91 | + $timeStamp) |
|
| 92 | 92 | { |
| 93 | 93 | $codeDigits = 0; |
| 94 | 94 | $crypto = ""; |
@@ -101,12 +101,15 @@ discard block |
||
| 101 | 101 | $sessionInformationLength = 0; |
| 102 | 102 | $timeStampLength = 0; |
| 103 | 103 | |
| 104 | - if(stripos($ocraSuite, "sha1")!==false) |
|
| 105 | - $crypto = "sha1"; |
|
| 106 | - if(stripos($ocraSuite, "sha256")!==false) |
|
| 107 | - $crypto = "sha256"; |
|
| 108 | - if(stripos($ocraSuite, "sha512")!==false) |
|
| 109 | - $crypto = "sha512"; |
|
| 104 | + if(stripos($ocraSuite, "sha1")!==false) { |
|
| 105 | + $crypto = "sha1"; |
|
| 106 | + } |
|
| 107 | + if(stripos($ocraSuite, "sha256")!==false) { |
|
| 108 | + $crypto = "sha256"; |
|
| 109 | + } |
|
| 110 | + if(stripos($ocraSuite, "sha512")!==false) { |
|
| 111 | + $crypto = "sha512"; |
|
| 112 | + } |
|
| 110 | 113 | |
| 111 | 114 | // How many digits should we return |
| 112 | 115 | $oS = substr($ocraSuite, strpos($ocraSuite, ":")+1, strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1) -strpos($ocraSuite, ":")-1); |
@@ -116,31 +119,35 @@ discard block |
||
| 116 | 119 | // Counter |
| 117 | 120 | if(stripos($ocraSuite, ":c") !==false) { |
| 118 | 121 | // Fix the length of the HEX string |
| 119 | - while(strlen($counter) < 16) |
|
| 120 | - $counter = "0" . $counter; |
|
| 122 | + while(strlen($counter) < 16) { |
|
| 123 | + $counter = "0" . $counter; |
|
| 124 | + } |
|
| 121 | 125 | $counterLength=8; |
| 122 | 126 | } |
| 123 | 127 | // Question |
| 124 | 128 | if(stripos($ocraSuite, ":q")!==false || |
| 125 | 129 | stripos($ocraSuite, "-q")!==false) { |
| 126 | - while(strlen($question) < 256) |
|
| 127 | - $question = $question . "0"; |
|
| 130 | + while(strlen($question) < 256) { |
|
| 131 | + $question = $question . "0"; |
|
| 132 | + } |
|
| 128 | 133 | $questionLength=128; |
| 129 | 134 | } |
| 130 | 135 | |
| 131 | 136 | // Password |
| 132 | 137 | if(stripos($ocraSuite, ":p")!==false || |
| 133 | 138 | stripos($ocraSuite, "-p") !==false) { |
| 134 | - while(strlen($password) < 40) |
|
| 135 | - $password = "0" . $password; |
|
| 139 | + while(strlen($password) < 40) { |
|
| 140 | + $password = "0" . $password; |
|
| 141 | + } |
|
| 136 | 142 | $passwordLength=20; |
| 137 | 143 | } |
| 138 | 144 | |
| 139 | 145 | // sessionInformation |
| 140 | 146 | if(stripos($ocraSuite, ":s") !==false || |
| 141 | 147 | stripos($ocraSuite, "-s", strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1)) !== false) { |
| 142 | - while(strlen($sessionInformation) < 128) |
|
| 143 | - $sessionInformation = "0" . $sessionInformation; |
|
| 148 | + while(strlen($sessionInformation) < 128) { |
|
| 149 | + $sessionInformation = "0" . $sessionInformation; |
|
| 150 | + } |
|
| 144 | 151 | |
| 145 | 152 | $sessionInformationLength=64; |
| 146 | 153 | } |
@@ -148,8 +155,9 @@ discard block |
||
| 148 | 155 | // TimeStamp |
| 149 | 156 | if(stripos($ocraSuite, ":t") !==false || |
| 150 | 157 | stripos($ocraSuite, "-t") !== false) { |
| 151 | - while(strlen($timeStamp) < 16) |
|
| 152 | - $timeStamp = "0" . $timeStamp; |
|
| 158 | + while(strlen($timeStamp) < 16) { |
|
| 159 | + $timeStamp = "0" . $timeStamp; |
|
| 160 | + } |
|
| 153 | 161 | $timeStampLength=8; |
| 154 | 162 | } |
| 155 | 163 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $keyBytes, |
| 47 | 47 | $text) |
| 48 | 48 | { |
| 49 | - $hash = hash_hmac ($crypto, $text, $keyBytes); |
|
| 49 | + $hash = hash_hmac($crypto, $text, $keyBytes); |
|
| 50 | 50 | return $hash; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @return String a string with raw bytes |
| 59 | 59 | */ |
| 60 | - private static function _hexStr2Bytes($hex){ |
|
| 60 | + private static function _hexStr2Bytes($hex) { |
|
| 61 | 61 | return pack("H*", $hex); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -101,63 +101,63 @@ discard block |
||
| 101 | 101 | $sessionInformationLength = 0; |
| 102 | 102 | $timeStampLength = 0; |
| 103 | 103 | |
| 104 | - if(stripos($ocraSuite, "sha1")!==false) |
|
| 104 | + if (stripos($ocraSuite, "sha1") !== false) |
|
| 105 | 105 | $crypto = "sha1"; |
| 106 | - if(stripos($ocraSuite, "sha256")!==false) |
|
| 106 | + if (stripos($ocraSuite, "sha256") !== false) |
|
| 107 | 107 | $crypto = "sha256"; |
| 108 | - if(stripos($ocraSuite, "sha512")!==false) |
|
| 108 | + if (stripos($ocraSuite, "sha512") !== false) |
|
| 109 | 109 | $crypto = "sha512"; |
| 110 | 110 | |
| 111 | 111 | // How many digits should we return |
| 112 | - $oS = substr($ocraSuite, strpos($ocraSuite, ":")+1, strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1) -strpos($ocraSuite, ":")-1); |
|
| 113 | - $codeDigits = substr($oS, strrpos($oS, "-")+1); |
|
| 112 | + $oS = substr($ocraSuite, strpos($ocraSuite, ":") + 1, strpos($ocraSuite, ":", strpos($ocraSuite, ":") + 1) - strpos($ocraSuite, ":") - 1); |
|
| 113 | + $codeDigits = substr($oS, strrpos($oS, "-") + 1); |
|
| 114 | 114 | |
| 115 | 115 | // The size of the byte array message to be encrypted |
| 116 | 116 | // Counter |
| 117 | - if(stripos($ocraSuite, ":c") !==false) { |
|
| 117 | + if (stripos($ocraSuite, ":c") !== false) { |
|
| 118 | 118 | // Fix the length of the HEX string |
| 119 | - while(strlen($counter) < 16) |
|
| 120 | - $counter = "0" . $counter; |
|
| 121 | - $counterLength=8; |
|
| 119 | + while (strlen($counter) < 16) |
|
| 120 | + $counter = "0".$counter; |
|
| 121 | + $counterLength = 8; |
|
| 122 | 122 | } |
| 123 | 123 | // Question |
| 124 | - if(stripos($ocraSuite, ":q")!==false || |
|
| 125 | - stripos($ocraSuite, "-q")!==false) { |
|
| 126 | - while(strlen($question) < 256) |
|
| 127 | - $question = $question . "0"; |
|
| 128 | - $questionLength=128; |
|
| 124 | + if (stripos($ocraSuite, ":q") !== false || |
|
| 125 | + stripos($ocraSuite, "-q") !== false) { |
|
| 126 | + while (strlen($question) < 256) |
|
| 127 | + $question = $question."0"; |
|
| 128 | + $questionLength = 128; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Password |
| 132 | - if(stripos($ocraSuite, ":p")!==false || |
|
| 133 | - stripos($ocraSuite, "-p") !==false) { |
|
| 134 | - while(strlen($password) < 40) |
|
| 135 | - $password = "0" . $password; |
|
| 136 | - $passwordLength=20; |
|
| 132 | + if (stripos($ocraSuite, ":p") !== false || |
|
| 133 | + stripos($ocraSuite, "-p") !== false) { |
|
| 134 | + while (strlen($password) < 40) |
|
| 135 | + $password = "0".$password; |
|
| 136 | + $passwordLength = 20; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // sessionInformation |
| 140 | - if(stripos($ocraSuite, ":s") !==false || |
|
| 141 | - stripos($ocraSuite, "-s", strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1)) !== false) { |
|
| 142 | - while(strlen($sessionInformation) < 128) |
|
| 143 | - $sessionInformation = "0" . $sessionInformation; |
|
| 140 | + if (stripos($ocraSuite, ":s") !== false || |
|
| 141 | + stripos($ocraSuite, "-s", strpos($ocraSuite, ":", strpos($ocraSuite, ":") + 1)) !== false) { |
|
| 142 | + while (strlen($sessionInformation) < 128) |
|
| 143 | + $sessionInformation = "0".$sessionInformation; |
|
| 144 | 144 | |
| 145 | - $sessionInformationLength=64; |
|
| 145 | + $sessionInformationLength = 64; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // TimeStamp |
| 149 | - if(stripos($ocraSuite, ":t") !==false || |
|
| 149 | + if (stripos($ocraSuite, ":t") !== false || |
|
| 150 | 150 | stripos($ocraSuite, "-t") !== false) { |
| 151 | - while(strlen($timeStamp) < 16) |
|
| 152 | - $timeStamp = "0" . $timeStamp; |
|
| 153 | - $timeStampLength=8; |
|
| 151 | + while (strlen($timeStamp) < 16) |
|
| 152 | + $timeStamp = "0".$timeStamp; |
|
| 153 | + $timeStampLength = 8; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // Put the bytes of "ocraSuite" parameters into the message |
| 157 | 157 | |
| 158 | - $msg = array_fill(0,$ocraSuiteLength+$counterLength+$questionLength+$passwordLength+$sessionInformationLength+$timeStampLength+1, 0); |
|
| 158 | + $msg = array_fill(0, $ocraSuiteLength + $counterLength + $questionLength + $passwordLength + $sessionInformationLength + $timeStampLength + 1, 0); |
|
| 159 | 159 | |
| 160 | - for($i=0;$i<strlen($ocraSuite);$i++) { |
|
| 160 | + for ($i = 0; $i < strlen($ocraSuite); $i++) { |
|
| 161 | 161 | $msg[$i] = $ocraSuite[$i]; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | // Put the bytes of "Counter" to the message |
| 168 | 168 | // Input is HEX encoded |
| 169 | - if($counterLength > 0 ) { |
|
| 169 | + if ($counterLength > 0) { |
|
| 170 | 170 | $bArray = self::_hexStr2Bytes($counter); |
| 171 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 171 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 172 | 172 | $msg [$i + $ocraSuiteLength + 1] = $bArray[$i]; |
| 173 | 173 | } |
| 174 | 174 | } |
@@ -176,36 +176,36 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | // Put the bytes of "question" to the message |
| 178 | 178 | // Input is text encoded |
| 179 | - if($questionLength > 0 ) { |
|
| 179 | + if ($questionLength > 0) { |
|
| 180 | 180 | $bArray = self::_hexStr2Bytes($question); |
| 181 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 181 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 182 | 182 | $msg [$i + $ocraSuiteLength + 1 + $counterLength] = $bArray[$i]; |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // Put the bytes of "password" to the message |
| 187 | 187 | // Input is HEX encoded |
| 188 | - if($passwordLength > 0){ |
|
| 188 | + if ($passwordLength > 0) { |
|
| 189 | 189 | $bArray = self::_hexStr2Bytes($password); |
| 190 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 190 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 191 | 191 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength] = $bArray[$i]; |
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // Put the bytes of "sessionInformation" to the message |
| 196 | 196 | // Input is text encoded |
| 197 | - if($sessionInformationLength > 0 ){ |
|
| 197 | + if ($sessionInformationLength > 0) { |
|
| 198 | 198 | $bArray = self::_hexStr2Bytes($sessionInformation); |
| 199 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 199 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 200 | 200 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength] = $bArray[$i]; |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Put the bytes of "time" to the message |
| 205 | 205 | // Input is text value of minutes |
| 206 | - if($timeStampLength > 0){ |
|
| 206 | + if ($timeStampLength > 0) { |
|
| 207 | 207 | $bArray = self::_hexStr2Bytes($timestamp); |
| 208 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
| 208 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
| 209 | 209 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength + $sessionInformationLength] = $bArray[$i]; |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | static function _oath_truncate($hash, $length = 6) |
| 228 | 228 | { |
| 229 | 229 | // Convert to dec |
| 230 | - foreach(str_split($hash,2) as $hex) |
|
| 230 | + foreach (str_split($hash, 2) as $hex) |
|
| 231 | 231 | { |
| 232 | - $hmac_result[]=hexdec($hex); |
|
| 232 | + $hmac_result[] = hexdec($hex); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | // Find offset |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | // Algorithm from RFC |
| 239 | 239 | return |
| 240 | 240 | ( |
| 241 | - (($hmac_result[$offset+0] & 0x7f) << 24 ) | |
|
| 242 | - (($hmac_result[$offset+1] & 0xff) << 16 ) | |
|
| 243 | - (($hmac_result[$offset+2] & 0xff) << 8 ) | |
|
| 244 | - ($hmac_result[$offset+3] & 0xff) |
|
| 245 | - ) % pow(10,$length); |
|
| 241 | + (($hmac_result[$offset + 0] & 0x7f) << 24) | |
|
| 242 | + (($hmac_result[$offset + 1] & 0xff) << 16) | |
|
| 243 | + (($hmac_result[$offset + 2] & 0xff) << 8) | |
|
| 244 | + ($hmac_result[$offset + 3] & 0xff) |
|
| 245 | + ) % pow(10, $length); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | } |