@@ -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); |
@@ -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,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 | 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 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $keyBytes, |
38 | 38 | $text) |
39 | 39 | { |
40 | - $hash = hash_hmac ($crypto, $text, $keyBytes); |
|
40 | + $hash = hash_hmac($crypto, $text, $keyBytes); |
|
41 | 41 | return $hash; |
42 | 42 | } |
43 | 43 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return String a string with raw bytes |
50 | 50 | */ |
51 | - private static function _hexStr2Bytes($hex){ |
|
51 | + private static function _hexStr2Bytes($hex) { |
|
52 | 52 | return pack("H*", $hex); |
53 | 53 | } |
54 | 54 | |
@@ -97,95 +97,95 @@ discard block |
||
97 | 97 | $cryptoFunction = $components[1]; |
98 | 98 | $dataInput = strtolower($components[2]); // lower here so we can do case insensitive comparisons |
99 | 99 | |
100 | - if(stripos($cryptoFunction, "sha1")!==false) |
|
100 | + if (stripos($cryptoFunction, "sha1") !== false) |
|
101 | 101 | $crypto = "sha1"; |
102 | - if(stripos($cryptoFunction, "sha256")!==false) |
|
102 | + if (stripos($cryptoFunction, "sha256") !== false) |
|
103 | 103 | $crypto = "sha256"; |
104 | - if(stripos($cryptoFunction, "sha512")!==false) |
|
104 | + if (stripos($cryptoFunction, "sha512") !== false) |
|
105 | 105 | $crypto = "sha512"; |
106 | 106 | |
107 | - $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1); |
|
107 | + $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-") + 1); |
|
108 | 108 | |
109 | 109 | // The size of the byte array message to be encrypted |
110 | 110 | // Counter |
111 | - if($dataInput[0] == "c" ) { |
|
111 | + if ($dataInput[0] == "c") { |
|
112 | 112 | // Fix the length of the HEX string |
113 | - while(strlen($counter) < 16) |
|
114 | - $counter = "0" . $counter; |
|
115 | - $counterLength=8; |
|
113 | + while (strlen($counter) < 16) |
|
114 | + $counter = "0".$counter; |
|
115 | + $counterLength = 8; |
|
116 | 116 | } |
117 | 117 | // Question |
118 | - if($dataInput[0] == "q" || |
|
119 | - stripos($dataInput, "-q")!==false) { |
|
120 | - while(strlen($question) < 256) |
|
121 | - $question = $question . "0"; |
|
122 | - $questionLength=128; |
|
118 | + if ($dataInput[0] == "q" || |
|
119 | + stripos($dataInput, "-q") !== false) { |
|
120 | + while (strlen($question) < 256) |
|
121 | + $question = $question."0"; |
|
122 | + $questionLength = 128; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // Password |
126 | - if(stripos($dataInput, "psha1")!==false) { |
|
127 | - while(strlen($password) < 40) |
|
128 | - $password = "0" . $password; |
|
129 | - $passwordLength=20; |
|
126 | + if (stripos($dataInput, "psha1") !== false) { |
|
127 | + while (strlen($password) < 40) |
|
128 | + $password = "0".$password; |
|
129 | + $passwordLength = 20; |
|
130 | 130 | } |
131 | 131 | |
132 | - if(stripos($dataInput, "psha256")!==false) { |
|
133 | - while(strlen($password) < 64) |
|
134 | - $password = "0" . $password; |
|
135 | - $passwordLength=32; |
|
132 | + if (stripos($dataInput, "psha256") !== false) { |
|
133 | + while (strlen($password) < 64) |
|
134 | + $password = "0".$password; |
|
135 | + $passwordLength = 32; |
|
136 | 136 | } |
137 | 137 | |
138 | - if(stripos($dataInput, "psha512")!==false) { |
|
139 | - while(strlen($password) < 128) |
|
140 | - $password = "0" . $password; |
|
141 | - $passwordLength=64; |
|
138 | + if (stripos($dataInput, "psha512") !== false) { |
|
139 | + while (strlen($password) < 128) |
|
140 | + $password = "0".$password; |
|
141 | + $passwordLength = 64; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | // sessionInformation |
145 | - if(stripos($dataInput, "s064") !==false) { |
|
146 | - while(strlen($sessionInformation) < 128) |
|
147 | - $sessionInformation = "0" . $sessionInformation; |
|
145 | + if (stripos($dataInput, "s064") !== false) { |
|
146 | + while (strlen($sessionInformation) < 128) |
|
147 | + $sessionInformation = "0".$sessionInformation; |
|
148 | 148 | |
149 | - $sessionInformationLength=64; |
|
150 | - } else if(stripos($dataInput, "s128") !==false) { |
|
151 | - while(strlen($sessionInformation) < 256) |
|
152 | - $sessionInformation = "0" . $sessionInformation; |
|
149 | + $sessionInformationLength = 64; |
|
150 | + } else if (stripos($dataInput, "s128") !== false) { |
|
151 | + while (strlen($sessionInformation) < 256) |
|
152 | + $sessionInformation = "0".$sessionInformation; |
|
153 | 153 | |
154 | - $sessionInformationLength=128; |
|
155 | - } else if(stripos($dataInput, "s256") !==false) { |
|
156 | - while(strlen($sessionInformation) < 512) |
|
157 | - $sessionInformation = "0" . $sessionInformation; |
|
154 | + $sessionInformationLength = 128; |
|
155 | + } else if (stripos($dataInput, "s256") !== false) { |
|
156 | + while (strlen($sessionInformation) < 512) |
|
157 | + $sessionInformation = "0".$sessionInformation; |
|
158 | 158 | |
159 | - $sessionInformationLength=256; |
|
160 | - } else if(stripos($dataInput, "s512") !==false) { |
|
161 | - while(strlen($sessionInformation) < 128) |
|
162 | - $sessionInformation = "0" . $sessionInformation; |
|
159 | + $sessionInformationLength = 256; |
|
160 | + } else if (stripos($dataInput, "s512") !== false) { |
|
161 | + while (strlen($sessionInformation) < 128) |
|
162 | + $sessionInformation = "0".$sessionInformation; |
|
163 | 163 | |
164 | - $sessionInformationLength=64; |
|
165 | - } else if (stripos($dataInput, "s") !== false ) { |
|
164 | + $sessionInformationLength = 64; |
|
165 | + } else if (stripos($dataInput, "s") !== false) { |
|
166 | 166 | // deviation from spec. Officially 's' without a length indicator is not in the reference implementation. |
167 | 167 | // RFC is ambigious. However we have supported this in Tiqr since day 1, so we continue to support it. |
168 | - while(strlen($sessionInformation) < 128) |
|
169 | - $sessionInformation = "0" . $sessionInformation; |
|
168 | + while (strlen($sessionInformation) < 128) |
|
169 | + $sessionInformation = "0".$sessionInformation; |
|
170 | 170 | |
171 | - $sessionInformationLength=64; |
|
171 | + $sessionInformationLength = 64; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
175 | 175 | |
176 | 176 | // TimeStamp |
177 | - if($dataInput[0] == "t" || |
|
177 | + if ($dataInput[0] == "t" || |
|
178 | 178 | stripos($dataInput, "-t") !== false) { |
179 | - while(strlen($timeStamp) < 16) |
|
180 | - $timeStamp = "0" . $timeStamp; |
|
181 | - $timeStampLength=8; |
|
179 | + while (strlen($timeStamp) < 16) |
|
180 | + $timeStamp = "0".$timeStamp; |
|
181 | + $timeStampLength = 8; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // Put the bytes of "ocraSuite" parameters into the message |
185 | 185 | |
186 | - $msg = array_fill(0,$ocraSuiteLength+$counterLength+$questionLength+$passwordLength+$sessionInformationLength+$timeStampLength+1, 0); |
|
186 | + $msg = array_fill(0, $ocraSuiteLength + $counterLength + $questionLength + $passwordLength + $sessionInformationLength + $timeStampLength + 1, 0); |
|
187 | 187 | |
188 | - for($i=0;$i<strlen($ocraSuite);$i++) { |
|
188 | + for ($i = 0; $i < strlen($ocraSuite); $i++) { |
|
189 | 189 | $msg[$i] = $ocraSuite[$i]; |
190 | 190 | } |
191 | 191 | |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | |
195 | 195 | // Put the bytes of "Counter" to the message |
196 | 196 | // Input is HEX encoded |
197 | - if($counterLength > 0 ) { |
|
197 | + if ($counterLength > 0) { |
|
198 | 198 | $bArray = self::_hexStr2Bytes($counter); |
199 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
199 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
200 | 200 | $msg [$i + $ocraSuiteLength + 1] = $bArray[$i]; |
201 | 201 | } |
202 | 202 | } |
@@ -204,36 +204,36 @@ discard block |
||
204 | 204 | |
205 | 205 | // Put the bytes of "question" to the message |
206 | 206 | // Input is text encoded |
207 | - if($questionLength > 0 ) { |
|
207 | + if ($questionLength > 0) { |
|
208 | 208 | $bArray = self::_hexStr2Bytes($question); |
209 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
209 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
210 | 210 | $msg [$i + $ocraSuiteLength + 1 + $counterLength] = $bArray[$i]; |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | 214 | // Put the bytes of "password" to the message |
215 | 215 | // Input is HEX encoded |
216 | - if($passwordLength > 0){ |
|
216 | + if ($passwordLength > 0) { |
|
217 | 217 | $bArray = self::_hexStr2Bytes($password); |
218 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
218 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
219 | 219 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength] = $bArray[$i]; |
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Put the bytes of "sessionInformation" to the message |
224 | 224 | // Input is text encoded |
225 | - if($sessionInformationLength > 0 ){ |
|
225 | + if ($sessionInformationLength > 0) { |
|
226 | 226 | $bArray = self::_hexStr2Bytes($sessionInformation); |
227 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
227 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
228 | 228 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength] = $bArray[$i]; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | // Put the bytes of "time" to the message |
233 | 233 | // Input is text value of minutes |
234 | - if($timeStampLength > 0){ |
|
234 | + if ($timeStampLength > 0) { |
|
235 | 235 | $bArray = self::_hexStr2Bytes($timeStamp); |
236 | - for ($i=0;$i<strlen($bArray);$i++) { |
|
236 | + for ($i = 0; $i < strlen($bArray); $i++) { |
|
237 | 237 | $msg [$i + $ocraSuiteLength + 1 + $counterLength + $questionLength + $passwordLength + $sessionInformationLength] = $bArray[$i]; |
238 | 238 | } |
239 | 239 | } |
@@ -255,19 +255,19 @@ discard block |
||
255 | 255 | static function _oath_truncate($hash, $length = 6) |
256 | 256 | { |
257 | 257 | // Convert to dec |
258 | - foreach(str_split($hash,2) as $hex) |
|
258 | + foreach (str_split($hash, 2) as $hex) |
|
259 | 259 | { |
260 | - $hmac_result[]=hexdec($hex); |
|
260 | + $hmac_result[] = hexdec($hex); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | // Find offset |
264 | 264 | $offset = $hmac_result[count($hmac_result) - 1] & 0xf; |
265 | 265 | |
266 | 266 | $v = strval( |
267 | - (($hmac_result[$offset+0] & 0x7f) << 24 ) | |
|
268 | - (($hmac_result[$offset+1] & 0xff) << 16 ) | |
|
269 | - (($hmac_result[$offset+2] & 0xff) << 8 ) | |
|
270 | - ($hmac_result[$offset+3] & 0xff) |
|
267 | + (($hmac_result[$offset + 0] & 0x7f) << 24) | |
|
268 | + (($hmac_result[$offset + 1] & 0xff) << 16) | |
|
269 | + (($hmac_result[$offset + 2] & 0xff) << 8) | |
|
270 | + ($hmac_result[$offset + 3] & 0xff) |
|
271 | 271 | ); |
272 | 272 | |
273 | 273 | $v = substr($v, strlen($v) - $length); |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | /** |
69 | 69 | * Enrollment status codes |
70 | 70 | */ |
71 | - const ENROLLMENT_STATUS_IDLE = 1; // Nothing happens |
|
71 | + const ENROLLMENT_STATUS_IDLE = 1; // Nothing happens |
|
72 | 72 | const ENROLLMENT_STATUS_INITIALIZED = 2; // An enrollment session has begun |
73 | - const ENROLLMENT_STATUS_RETRIEVED = 3; // The device has retrieved the metadata |
|
74 | - const ENROLLMENT_STATUS_PROCESSED = 4; // The device has snet back a secret |
|
75 | - const ENROLLMENT_STATUS_FINALIZED = 5; // The application has stored the secret |
|
76 | - const ENROLLMENT_STATUS_VALIDATED = 6; // A first succesful authentication was performed |
|
73 | + const ENROLLMENT_STATUS_RETRIEVED = 3; // The device has retrieved the metadata |
|
74 | + const ENROLLMENT_STATUS_PROCESSED = 4; // The device has snet back a secret |
|
75 | + const ENROLLMENT_STATUS_FINALIZED = 5; // The application has stored the secret |
|
76 | + const ENROLLMENT_STATUS_VALIDATED = 6; // A first succesful authentication was performed |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Default timeout values |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param array $options |
153 | 153 | * @param int $version The protocol version to use (defaults to the latest) |
154 | 154 | */ |
155 | - public function __construct($options=array(), $version = 2) |
|
155 | + public function __construct($options = array(), $version = 2) |
|
156 | 156 | { |
157 | 157 | $this->_options = $options; |
158 | 158 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | |
291 | 291 | $message = new $class($this->_options); |
292 | 292 | $message->setId(time()); |
293 | - $message->setText("Please authenticate for " . $this->_name); |
|
293 | + $message->setText("Please authenticate for ".$this->_name); |
|
294 | 294 | $message->setAddress($notificationAddress); |
295 | 295 | $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey)); |
296 | 296 | $message->send(); |
@@ -358,13 +358,13 @@ discard block |
||
358 | 358 | * @param String $spIdentifier If SP and IDP are 2 different things, pass the url/identifier of the SP the user is logging into. |
359 | 359 | * For setups where IDP==SP, just leave this blank. |
360 | 360 | */ |
361 | - public function startAuthenticationSession($userId="", $sessionId="", $spIdentifier="") |
|
361 | + public function startAuthenticationSession($userId = "", $sessionId = "", $spIdentifier = "") |
|
362 | 362 | { |
363 | - if ($sessionId=="") { |
|
363 | + if ($sessionId == "") { |
|
364 | 364 | $sessionId = session_id(); |
365 | 365 | } |
366 | 366 | |
367 | - if ($spIdentifier=="") { |
|
367 | + if ($spIdentifier == "") { |
|
368 | 368 | $spIdentifier = $this->_identifier; |
369 | 369 | } |
370 | 370 | |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | |
375 | 375 | $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier); |
376 | 376 | |
377 | - if ($userId!="") { |
|
377 | + if ($userId != "") { |
|
378 | 378 | $data["userId"] = $userId; |
379 | 379 | } |
380 | 380 | |
@@ -398,9 +398,9 @@ discard block |
||
398 | 398 | * to php session) |
399 | 399 | * @return String The enrollment key |
400 | 400 | */ |
401 | - public function startEnrollmentSession($userId, $displayName, $sessionId="") |
|
401 | + public function startEnrollmentSession($userId, $displayName, $sessionId = "") |
|
402 | 402 | { |
403 | - if ($sessionId=="") { |
|
403 | + if ($sessionId == "") { |
|
404 | 404 | $sessionId = session_id(); |
405 | 405 | } |
406 | 406 | |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | * @param $sessionId The application's session identifier (defaults |
418 | 418 | * to php session) |
419 | 419 | */ |
420 | - public function resetEnrollmentSession($sessionId="") |
|
420 | + public function resetEnrollmentSession($sessionId = "") |
|
421 | 421 | { |
422 | - if ($sessionId=="") { |
|
422 | + if ($sessionId == "") { |
|
423 | 423 | $sessionId = session_id(); |
424 | 424 | } |
425 | 425 | |
@@ -447,9 +447,9 @@ discard block |
||
447 | 447 | * A first successful authentication was performed |
448 | 448 | * (todo: currently not used) |
449 | 449 | */ |
450 | - public function getEnrollmentStatus($sessionId="") |
|
450 | + public function getEnrollmentStatus($sessionId = "") |
|
451 | 451 | { |
452 | - if ($sessionId=="") { |
|
452 | + if ($sessionId == "") { |
|
453 | 453 | $sessionId = session_id(); |
454 | 454 | } |
455 | 455 | $status = $this->_stateStorage->getValue("enrollstatus".$sessionId); |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | $challengeUserId = $state["userId"]; |
634 | 634 | } |
635 | 635 | // Check if we're dealing with a second factor |
636 | - if ($challengeUserId!=NULL && ($userId != $challengeUserId)) { |
|
636 | + if ($challengeUserId != NULL && ($userId != $challengeUserId)) { |
|
637 | 637 | return self::AUTH_RESULT_INVALID_USERID; // only allowed to authenticate against the user that's authenticated in the first factor |
638 | 638 | } |
639 | 639 | |
@@ -660,9 +660,9 @@ discard block |
||
660 | 660 | * @param String $sessionId The application's session identifier (defaults |
661 | 661 | * to the php session). |
662 | 662 | */ |
663 | - public function logout($sessionId="") |
|
663 | + public function logout($sessionId = "") |
|
664 | 664 | { |
665 | - if ($sessionId=="") { |
|
665 | + if ($sessionId == "") { |
|
666 | 666 | $sessionId = session_id(); |
667 | 667 | } |
668 | 668 | |
@@ -697,9 +697,9 @@ discard block |
||
697 | 697 | * @return mixed An array with user data if a user was logged in or NULL if |
698 | 698 | * no user is logged in. |
699 | 699 | */ |
700 | - public function getAuthenticatedUser($sessionId="") |
|
700 | + public function getAuthenticatedUser($sessionId = "") |
|
701 | 701 | { |
702 | - if ($sessionId=="") { |
|
702 | + if ($sessionId == "") { |
|
703 | 703 | $sessionId = session_id(); |
704 | 704 | } |
705 | 705 | |
@@ -722,7 +722,7 @@ discard block |
||
722 | 722 | return false; |
723 | 723 | } |
724 | 724 | |
725 | - $userId = NULL; |
|
725 | + $userId = NULL; |
|
726 | 726 | $challenge = $state["challenge"]; |
727 | 727 | if (isset($state["userId"])) { |
728 | 728 | $userId = $state["userId"]; |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | $spIdentifier = $state["spIdentifier"]; |
731 | 731 | |
732 | 732 | // Last bit is the spIdentifier |
733 | - return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
733 | + return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | /** |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | protected function _uniqueSessionKey($prefix) |
755 | 755 | { |
756 | 756 | $value = 1; |
757 | - while ($value!=NULL) { |
|
757 | + while ($value != NULL) { |
|
758 | 758 | $sessionKey = $this->_ocraWrapper->generateSessionKey(); |
759 | 759 | $value = $this->_stateStorage->getValue($prefix.$sessionKey); |
760 | 760 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | * @param boolean $temporary temporary failure? |
36 | 36 | * @param Exception $parent parent exception |
37 | 37 | */ |
38 | - public function __construct($message, $temporary=false, Exception $parent=null) |
|
38 | + public function __construct($message, $temporary = false, Exception $parent = null) |
|
39 | 39 | { |
40 | 40 | parent::__construct($message, $parent); |
41 | 41 | $this->_temporary = $temporary; |
@@ -35,7 +35,7 @@ |
||
35 | 35 | * @param boolean $temporary temporary failure? |
36 | 36 | * @param Exception $parent parent exception |
37 | 37 | */ |
38 | - public function __construct($message, $temporary=false, Exception $parent=null) |
|
38 | + public function __construct($message, $temporary = false, Exception $parent = null) |
|
39 | 39 | { |
40 | 40 | parent::__construct($message, $parent); |
41 | 41 | $this->_temporary = $temporary; |
@@ -102,7 +102,7 @@ |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | if ($error != null) { |
105 | - throw new Tiqr_Message_Exception_SendFailure("Error in GCM response: " . $error, true); |
|
105 | + throw new Tiqr_Message_Exception_SendFailure("Error in GCM response: ".$error, true); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | ); |
70 | 70 | |
71 | 71 | $headers = array( |
72 | - 'Authorization: key=' . $apiKey, |
|
72 | + 'Authorization: key='.$apiKey, |
|
73 | 73 | 'Content-Type: application/json', |
74 | 74 | ); |
75 | 75 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | if (!empty($errors)) { |
92 | - throw new Tiqr_Message_Exception_SendFailure("Http error occurred: ". $errors, true); |
|
92 | + throw new Tiqr_Message_Exception_SendFailure("Http error occurred: ".$errors, true); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | if ($statusCode !== 200) { |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | $response = json_decode($result, true); |
101 | 101 | foreach ($response['results'] as $k => $v) { |
102 | 102 | if (isset($v['error'])) { |
103 | - throw new Tiqr_Message_Exception_SendFailure("Error in GCM response: " . $v['error'], true); |
|
103 | + throw new Tiqr_Message_Exception_SendFailure("Error in GCM response: ".$v['error'], true); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |