Passed
Pull Request — develop (#31)
by Pieter van der
06:27 queued 10s
created
library/tiqr/Tiqr/OATH/OCRA.php 3 patches
Braces   +42 added lines, -28 removed lines patch added patch discarded remove patch
@@ -97,12 +97,15 @@  discard block
 block discarded – undo
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)
101
-            $crypto = "sha1";
102
-        if(stripos($cryptoFunction, "sha256")!==false)
103
-            $crypto = "sha256";
104
-        if(stripos($cryptoFunction, "sha512")!==false)
105
-            $crypto = "sha512";
100
+        if(stripos($cryptoFunction, "sha1")!==false) {
101
+                    $crypto = "sha1";
102
+        }
103
+        if(stripos($cryptoFunction, "sha256")!==false) {
104
+                    $crypto = "sha256";
105
+        }
106
+        if(stripos($cryptoFunction, "sha512")!==false) {
107
+                    $crypto = "sha512";
108
+        }
106 109
         
107 110
         $codeDigits = substr($cryptoFunction, strrpos($cryptoFunction, "-")+1);
108 111
                 
@@ -110,63 +113,73 @@  discard block
 block discarded – undo
110 113
         // Counter
111 114
         if($dataInput[0] == "c" ) {
112 115
             // Fix the length of the HEX string
113
-            while(strlen($counter) < 16)
114
-                $counter = "0" . $counter;
116
+            while(strlen($counter) < 16) {
117
+                            $counter = "0" . $counter;
118
+            }
115 119
             $counterLength=8;
116 120
         }
117 121
         // Question
118 122
         if($dataInput[0] == "q" ||
119 123
                 stripos($dataInput, "-q")!==false) {
120
-            while(strlen($question) < 256)
121
-                $question = $question . "0";
124
+            while(strlen($question) < 256) {
125
+                            $question = $question . "0";
126
+            }
122 127
             $questionLength=128;
123 128
         }
124 129
 
125 130
         // Password
126 131
         if(stripos($dataInput, "psha1")!==false) {
127
-            while(strlen($password) < 40)
128
-                $password = "0" . $password;
132
+            while(strlen($password) < 40) {
133
+                            $password = "0" . $password;
134
+            }
129 135
             $passwordLength=20;
130 136
         }
131 137
     
132 138
         if(stripos($dataInput, "psha256")!==false) {
133
-            while(strlen($password) < 64)
134
-                $password = "0" . $password;
139
+            while(strlen($password) < 64) {
140
+                            $password = "0" . $password;
141
+            }
135 142
             $passwordLength=32;
136 143
         }
137 144
         
138 145
         if(stripos($dataInput, "psha512")!==false) {
139
-            while(strlen($password) < 128)
140
-                $password = "0" . $password;
146
+            while(strlen($password) < 128) {
147
+                            $password = "0" . $password;
148
+            }
141 149
             $passwordLength=64;
142 150
         }
143 151
         
144 152
         // sessionInformation
145 153
         if(stripos($dataInput, "s064") !==false) {
146
-            while(strlen($sessionInformation) < 128)
147
-                $sessionInformation = "0" . $sessionInformation;
154
+            while(strlen($sessionInformation) < 128) {
155
+                            $sessionInformation = "0" . $sessionInformation;
156
+            }
148 157
 
149 158
             $sessionInformationLength=64;
150 159
         } else if(stripos($dataInput, "s128") !==false) {
151
-            while(strlen($sessionInformation) < 256)
152
-                $sessionInformation = "0" . $sessionInformation;
160
+            while(strlen($sessionInformation) < 256) {
161
+                            $sessionInformation = "0" . $sessionInformation;
162
+            }
153 163
         
154 164
             $sessionInformationLength=128;
155 165
         } else if(stripos($dataInput, "s256") !==false) {
156
-            while(strlen($sessionInformation) < 512)
157
-                $sessionInformation = "0" . $sessionInformation;
166
+            while(strlen($sessionInformation) < 512) {
167
+                            $sessionInformation = "0" . $sessionInformation;
168
+            }
158 169
         
159 170
             $sessionInformationLength=256;
160 171
         } else if(stripos($dataInput, "s512") !==false) {
161
-            while(strlen($sessionInformation) < 128)
162
-                $sessionInformation = "0" . $sessionInformation;
172
+            while(strlen($sessionInformation) < 128) {
173
+                            $sessionInformation = "0" . $sessionInformation;
174
+            }
163 175
         
164 176
             $sessionInformationLength=64;
165 177
         } else if (stripos($dataInput, "s") !== false ) {
166 178
             // deviation from spec. Officially 's' without a length indicator is not in the reference implementation.
167 179
             // 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;
180
+            while(strlen($sessionInformation) < 128) {
181
+                            $sessionInformation = "0" . $sessionInformation;
182
+            }
170 183
             
171 184
             $sessionInformationLength=64;
172 185
         }
@@ -176,8 +189,9 @@  discard block
 block discarded – undo
176 189
         // TimeStamp
177 190
         if($dataInput[0] == "t" ||
178 191
                 stripos($dataInput, "-t") !== false) {
179
-            while(strlen($timeStamp) < 16)
180
-                $timeStamp = "0" . $timeStamp;
192
+            while(strlen($timeStamp) < 16) {
193
+                            $timeStamp = "0" . $timeStamp;
194
+            }
181 195
             $timeStampLength=8;
182 196
         }
183 197
 
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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 = "";
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
@@ -260,23 +260,23 @@  discard block
 block discarded – undo
260 260
     static function _oath_truncate($hash, $length = 6)
261 261
     {
262 262
         // Convert to dec
263
-        foreach(str_split($hash,2) as $hex)
263
+        foreach (str_split($hash, 2) as $hex)
264 264
         {
265
-            $hmac_result[]=hexdec($hex);
265
+            $hmac_result[] = hexdec($hex);
266 266
         }
267 267
     
268 268
         // Find offset
269 269
         $offset = $hmac_result[count($hmac_result) - 1] & 0xf;
270 270
     
271 271
         $v = strval(
272
-            (($hmac_result[$offset+0] & 0x7f) << 24 ) |
273
-            (($hmac_result[$offset+1] & 0xff) << 16 ) |
274
-            (($hmac_result[$offset+2] & 0xff) << 8 ) |
275
-            ($hmac_result[$offset+3] & 0xff)
272
+            (($hmac_result[$offset + 0] & 0x7f) << 24) |
273
+            (($hmac_result[$offset + 1] & 0xff) << 16) |
274
+            (($hmac_result[$offset + 2] & 0xff) << 8) |
275
+            ($hmac_result[$offset + 3] & 0xff)
276 276
         );
277 277
 
278 278
         // Prefix truncated string with 0's to ensure it always has the required length
279
-        $v=str_pad($v, $length, "0", STR_PAD_LEFT);
279
+        $v = str_pad($v, $length, "0", STR_PAD_LEFT);
280 280
 
281 281
         $v = substr($v, strlen($v) - $length);
282 282
         return $v;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Service.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -453,7 +453,9 @@
 block discarded – undo
453 453
             $sessionId = session_id(); 
454 454
         }
455 455
         $status = $this->_stateStorage->getValue("enrollstatus".$sessionId);
456
-        if (is_null($status)) return self::ENROLLMENT_STATUS_IDLE;
456
+        if (is_null($status)) {
457
+            return self::ENROLLMENT_STATUS_IDLE;
458
+        }
457 459
         return $status;
458 460
     }
459 461
         
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -538,17 +538,17 @@  discard block
 block discarded – undo
538 538
         }
539 539
 
540 540
         $metadata = array("service"=>
541
-                               array("displayName"       => $this->_name,
542
-                                     "identifier"        => $this->_identifier,
543
-                                     "logoUrl"           => $this->_logoUrl,
544
-                                     "infoUrl"           => $this->_infoUrl,
545
-                                     "authenticationUrl" => $authenticationUrl,
546
-                                     "ocraSuite"         => $this->_ocraSuite,
547
-                                     "enrollmentUrl"     => $enrollmentUrl
548
-                               ),
549
-                          "identity"=>
550
-                               array("identifier" =>$data["userId"],
551
-                                     "displayName"=>$data["displayName"]));
541
+                                array("displayName"       => $this->_name,
542
+                                        "identifier"        => $this->_identifier,
543
+                                        "logoUrl"           => $this->_logoUrl,
544
+                                        "infoUrl"           => $this->_infoUrl,
545
+                                        "authenticationUrl" => $authenticationUrl,
546
+                                        "ocraSuite"         => $this->_ocraSuite,
547
+                                        "enrollmentUrl"     => $enrollmentUrl
548
+                                ),
549
+                            "identity"=>
550
+                                array("identifier" =>$data["userId"],
551
+                                        "displayName"=>$data["displayName"]));
552 552
 
553 553
         $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT . $enrollmentKey);
554 554
 
@@ -571,18 +571,18 @@  discard block
 block discarded – undo
571 571
      */
572 572
     public function getEnrollmentSecret($enrollmentKey)
573 573
     {
574
-         $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey);
575
-         $secret = $this->_uniqueSessionKey(self::PREFIX_ENROLLMENT_SECRET);
576
-         $enrollmentData = [
577
-             "userId" => $data["userId"],
578
-             "sessionId" => $data["sessionId"]
579
-         ];
580
-         $this->_stateStorage->setValue(
581
-             self::PREFIX_ENROLLMENT_SECRET . $secret,
582
-             $enrollmentData,
583
-             self::ENROLLMENT_EXPIRE
584
-         );
585
-         return $secret;
574
+            $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey);
575
+            $secret = $this->_uniqueSessionKey(self::PREFIX_ENROLLMENT_SECRET);
576
+            $enrollmentData = [
577
+                "userId" => $data["userId"],
578
+                "sessionId" => $data["sessionId"]
579
+            ];
580
+            $this->_stateStorage->setValue(
581
+                self::PREFIX_ENROLLMENT_SECRET . $secret,
582
+                $enrollmentData,
583
+                self::ENROLLMENT_EXPIRE
584
+            );
585
+            return $secret;
586 586
     } 
587 587
 
588 588
     /**
@@ -597,13 +597,13 @@  discard block
 block discarded – undo
597 597
      */
598 598
     public function validateEnrollmentSecret($enrollmentSecret)
599 599
     {
600
-         $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret);
601
-         if (is_array($data)) { 
602
-             // Secret is valid, application may accept the user secret. 
603
-             $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_PROCESSED);
604
-             return $data["userId"];
605
-         }
606
-         return false;
600
+            $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret);
601
+            if (is_array($data)) { 
602
+                // Secret is valid, application may accept the user secret. 
603
+                $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_PROCESSED);
604
+                return $data["userId"];
605
+            }
606
+            return false;
607 607
     }
608 608
     
609 609
     /**
@@ -620,13 +620,13 @@  discard block
 block discarded – undo
620 620
      */
621 621
     public function finalizeEnrollment($enrollmentSecret) 
622 622
     {
623
-         $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret);
624
-         if (is_array($data)) {
625
-             // Enrollment is finalized, destroy our session data.
626
-             $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED);
627
-             $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret);
628
-         }
629
-         return true;
623
+            $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret);
624
+            if (is_array($data)) {
625
+                // Enrollment is finalized, destroy our session data.
626
+                $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED);
627
+                $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret);
628
+            }
629
+            return true;
630 630
     }
631 631
 
632 632
     /**
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
 
663 663
         $challengeUserId = NULL;
664 664
         if (isset($state["userId"])) {
665
-          $challengeUserId = $state["userId"];
665
+            $challengeUserId = $state["userId"];
666 666
         }
667 667
         // Check if we're dealing with a second factor
668 668
         if ($challengeUserId!=NULL && ($userId != $challengeUserId)) {
@@ -801,6 +801,6 @@  discard block
 block discarded – undo
801 801
      */
802 802
     protected function _setEnrollmentStatus($sessionId, $status)
803 803
     {
804
-       $this->_stateStorage->setValue("enrollstatus".$sessionId, $status, self::ENROLLMENT_EXPIRE);
804
+        $this->_stateStorage->setValue("enrollstatus".$sessionId, $status, self::ENROLLMENT_EXPIRE);
805 805
     }
806 806
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
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
     const PREFIX_ENROLLMENT_SECRET = 'enrollsecret';
79 79
     const PREFIX_ENROLLMENT = 'enroll';
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      * @param array $options
157 157
      * @param int $version The protocol version to use (defaults to the latest)
158 158
      */
159
-    public function __construct($options=array(), $version = 2)
159
+    public function __construct($options = array(), $version = 2)
160 160
     {
161 161
         $this->_options = $options;
162 162
         
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 
295 295
             $message = new $class($this->_options);
296 296
             $message->setId(time());
297
-            $message->setText("Please authenticate for " . $this->_name);
297
+            $message->setText("Please authenticate for ".$this->_name);
298 298
             $message->setAddress($notificationAddress);
299 299
             $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey));
300 300
             $message->send();
@@ -362,13 +362,13 @@  discard block
 block discarded – undo
362 362
      * @param String $spIdentifier If SP and IDP are 2 different things, pass the url/identifier of the SP the user is logging into.
363 363
      *                             For setups where IDP==SP, just leave this blank.
364 364
      */
365
-    public function startAuthenticationSession($userId="", $sessionId="", $spIdentifier="")
365
+    public function startAuthenticationSession($userId = "", $sessionId = "", $spIdentifier = "")
366 366
     {
367
-        if ($sessionId=="") {
367
+        if ($sessionId == "") {
368 368
             $sessionId = session_id();
369 369
         }
370 370
 
371
-        if ($spIdentifier=="") {
371
+        if ($spIdentifier == "") {
372 372
             $spIdentifier = $this->_identifier;
373 373
         }
374 374
 
@@ -378,11 +378,11 @@  discard block
 block discarded – undo
378 378
         
379 379
         $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier);
380 380
         
381
-        if ($userId!="") {
381
+        if ($userId != "") {
382 382
             $data["userId"] = $userId;
383 383
         }
384 384
         
385
-        $this->_stateStorage->setValue(self::PREFIX_CHALLENGE . $sessionKey, $data, self::CHALLENGE_EXPIRE);
385
+        $this->_stateStorage->setValue(self::PREFIX_CHALLENGE.$sessionKey, $data, self::CHALLENGE_EXPIRE);
386 386
        
387 387
         return $sessionKey;
388 388
     }
@@ -402,9 +402,9 @@  discard block
 block discarded – undo
402 402
      *                           to php session)
403 403
      * @return String The enrollment key
404 404
      */
405
-    public function startEnrollmentSession($userId, $displayName, $sessionId="")
405
+    public function startEnrollmentSession($userId, $displayName, $sessionId = "")
406 406
     {
407
-        if ($sessionId=="") {
407
+        if ($sessionId == "") {
408 408
             $sessionId = session_id();
409 409
         }
410 410
         $enrollmentKey = $this->_uniqueSessionKey(self::PREFIX_ENROLLMENT);
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
             "displayName" => $displayName,
414 414
             "sessionId" => $sessionId
415 415
         ];
416
-        $this->_stateStorage->setValue(self::PREFIX_ENROLLMENT . $enrollmentKey, $data, self::ENROLLMENT_EXPIRE);
416
+        $this->_stateStorage->setValue(self::PREFIX_ENROLLMENT.$enrollmentKey, $data, self::ENROLLMENT_EXPIRE);
417 417
         $this->_setEnrollmentStatus($sessionId, self::ENROLLMENT_STATUS_INITIALIZED);
418 418
 
419 419
         return $enrollmentKey;
@@ -424,9 +424,9 @@  discard block
 block discarded – undo
424 424
      * @param $sessionId The application's session identifier (defaults
425 425
      *                   to php session)
426 426
      */
427
-    public function resetEnrollmentSession($sessionId="")
427
+    public function resetEnrollmentSession($sessionId = "")
428 428
     {
429
-        if ($sessionId=="") {
429
+        if ($sessionId == "") {
430 430
             $sessionId = session_id();
431 431
         }
432 432
 
@@ -471,9 +471,9 @@  discard block
 block discarded – undo
471 471
      *               A first successful authentication was performed 
472 472
      *               (todo: currently not used)
473 473
      */
474
-    public function getEnrollmentStatus($sessionId="")
474
+    public function getEnrollmentStatus($sessionId = "")
475 475
     { 
476
-        if ($sessionId=="") {
476
+        if ($sessionId == "") {
477 477
             $sessionId = session_id(); 
478 478
         }
479 479
         $status = $this->_stateStorage->getValue("enrollstatus".$sessionId);
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
      */
533 533
     public function getEnrollmentMetadata($enrollmentKey, $authenticationUrl, $enrollmentUrl)
534 534
     {
535
-        $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey);
535
+        $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT.$enrollmentKey);
536 536
         if (!is_array($data)) {
537 537
             return false;
538 538
         }
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
                                array("identifier" =>$data["userId"],
551 551
                                      "displayName"=>$data["displayName"]));
552 552
 
553
-        $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT . $enrollmentKey);
553
+        $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT.$enrollmentKey);
554 554
 
555 555
         $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_RETRIEVED);
556 556
         return $metadata;
@@ -571,14 +571,14 @@  discard block
 block discarded – undo
571 571
      */
572 572
     public function getEnrollmentSecret($enrollmentKey)
573 573
     {
574
-         $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey);
574
+         $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT.$enrollmentKey);
575 575
          $secret = $this->_uniqueSessionKey(self::PREFIX_ENROLLMENT_SECRET);
576 576
          $enrollmentData = [
577 577
              "userId" => $data["userId"],
578 578
              "sessionId" => $data["sessionId"]
579 579
          ];
580 580
          $this->_stateStorage->setValue(
581
-             self::PREFIX_ENROLLMENT_SECRET . $secret,
581
+             self::PREFIX_ENROLLMENT_SECRET.$secret,
582 582
              $enrollmentData,
583 583
              self::ENROLLMENT_EXPIRE
584 584
          );
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
      */
653 653
     public function authenticate($userId, $userSecret, $sessionKey, $response)
654 654
     {
655
-        $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE . $sessionKey);
655
+        $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE.$sessionKey);
656 656
         if (is_null($state)) {
657 657
             return self::AUTH_RESULT_INVALID_CHALLENGE;
658 658
         }
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
           $challengeUserId = $state["userId"];
666 666
         }
667 667
         // Check if we're dealing with a second factor
668
-        if ($challengeUserId!=NULL && ($userId != $challengeUserId)) {
668
+        if ($challengeUserId != NULL && ($userId != $challengeUserId)) {
669 669
             return self::AUTH_RESULT_INVALID_USERID; // only allowed to authenticate against the user that's authenticated in the first factor
670 670
         }
671 671
 
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
             $this->_stateStorage->setValue("authenticated_".$sessionId, $userId, self::LOGIN_EXPIRE);
681 681
             
682 682
             // Clean up the challenge.
683
-            $this->_stateStorage->unsetValue(self::PREFIX_CHALLENGE . $sessionKey);
683
+            $this->_stateStorage->unsetValue(self::PREFIX_CHALLENGE.$sessionKey);
684 684
             
685 685
             return self::AUTH_RESULT_AUTHENTICATED;
686 686
         }
@@ -692,9 +692,9 @@  discard block
 block discarded – undo
692 692
      * @param String $sessionId The application's session identifier (defaults
693 693
      *                          to the php session).
694 694
      */
695
-    public function logout($sessionId="")
695
+    public function logout($sessionId = "")
696 696
     {
697
-        if ($sessionId=="") {
697
+        if ($sessionId == "") {
698 698
             $sessionId = session_id(); 
699 699
         }
700 700
         
@@ -729,9 +729,9 @@  discard block
 block discarded – undo
729 729
      * @return mixed An array with user data if a user was logged in or NULL if
730 730
      *               no user is logged in.
731 731
      */
732
-    public function getAuthenticatedUser($sessionId="")
732
+    public function getAuthenticatedUser($sessionId = "")
733 733
     {
734
-        if ($sessionId=="") {
734
+        if ($sessionId == "") {
735 735
             $sessionId = session_id(); 
736 736
         }
737 737
         
@@ -749,12 +749,12 @@  discard block
 block discarded – undo
749 749
      */
750 750
     protected function _getChallengeUrl($sessionKey)
751 751
     {                
752
-        $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE . $sessionKey);
752
+        $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE.$sessionKey);
753 753
         if (is_null($state)) {
754 754
             return false;
755 755
         }
756 756
         
757
-        $userId   = NULL;
757
+        $userId = NULL;
758 758
         $challenge = $state["challenge"];
759 759
         if (isset($state["userId"])) {
760 760
             $userId = $state["userId"];
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
         $spIdentifier = $state["spIdentifier"];
763 763
         
764 764
         // Last bit is the spIdentifier
765
-        return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion;
765
+        return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion;
766 766
     }
767 767
 
768 768
     /**
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
     protected function _uniqueSessionKey($prefix)
787 787
     {      
788 788
         $value = 1;
789
-        while ($value!=NULL) {
789
+        while ($value != NULL) {
790 790
             $sessionKey = $this->_ocraWrapper->generateSessionKey();
791 791
             $value = $this->_stateStorage->getValue($prefix.$sessionKey);
792 792
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Message/Exception/MismatchSenderId.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Message/Exception.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
      * @param string    $message    exception message
30 30
      * @param Exception $parent     parent exception
31 31
      */
32
-     public function __construct($message, $parent=null)
33
-     {
34
-         parent::__construct($message, 0, $parent);
35
-     }
32
+        public function __construct($message, $parent=null)
33
+        {
34
+            parent::__construct($message, 0, $parent);
35
+        }
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
      * @param string    $message    exception message
30 30
      * @param Exception $parent     parent exception
31 31
      */
32
-     public function __construct($message, $parent=null)
32
+     public function __construct($message, $parent = null)
33 33
      {
34 34
          parent::__construct($message, 0, $parent);
35 35
      }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Encryption/Dummy.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
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
      *
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Message/Exception/SendFailure.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Message/FCM.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -97,9 +97,9 @@
 block discarded – undo
97 97
 
98 98
         // Wait and retry once in case of a 502 Bad Gateway error
99 99
         if ($statusCode === 502 && !($retry)) {
100
-          sleep(2);
101
-          $this->_sendFirebase($deviceToken, $alert, $challenge, $apiKey, true);
102
-          return;
100
+            sleep(2);
101
+            $this->_sendFirebase($deviceToken, $alert, $challenge, $apiKey, true);
102
+            return;
103 103
         }
104 104
 
105 105
         if ($statusCode !== 200) {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @throws Tiqr_Message_Exception_SendFailure
59 59
      */
60
-    private function _sendFirebase($deviceToken, $alert, $challenge, $apiKey, $retry=false)
60
+    private function _sendFirebase($deviceToken, $alert, $challenge, $apiKey, $retry = false)
61 61
     {
62 62
         $msg = array(
63 63
             'challenge' => $challenge,
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         );
72 72
 
73 73
         $headers = array(
74
-            'Authorization: key=' . $apiKey,
74
+            'Authorization: key='.$apiKey,
75 75
             'Content-Type: application/json',
76 76
         );
77 77
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         $result = curl_exec($ch);
85 85
         $errors = curl_error($ch);
86 86
         $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
87
-        $remoteip = curl_getinfo($ch,CURLINFO_PRIMARY_IP);
87
+        $remoteip = curl_getinfo($ch, CURLINFO_PRIMARY_IP);
88 88
         curl_close($ch);
89 89
 
90 90
         if ($result === false) {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         }
93 93
 
94 94
         if (!empty($errors)) {
95
-            throw new Tiqr_Message_Exception_SendFailure("Http error occurred: ". $errors, true);
95
+            throw new Tiqr_Message_Exception_SendFailure("Http error occurred: ".$errors, true);
96 96
         }
97 97
 
98 98
         // Wait and retry once in case of a 502 Bad Gateway error
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         $response = json_decode($result, true);
111 111
         foreach ($response['results'] as $k => $v) {
112 112
             if (isset($v['error'])) {
113
-                throw new Tiqr_Message_Exception_SendFailure("Error in FCM response: " . $v['error'], true);
113
+                throw new Tiqr_Message_Exception_SendFailure("Error in FCM response: ".$v['error'], true);
114 114
             }
115 115
         }
116 116
     }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/AutoLoader.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -1,100 +1,100 @@
 block discarded – undo
1 1
 <?php
2 2
 class Tiqr_AutoLoader {
3 3
 
4
-	protected static $instance;
5
-
6
-	protected $tiqrPath;
7
-	protected $qrcodePath;
8
-	protected $zendPath;
9
-
10
-	protected function __construct($options) {
11
-		if ($options !== NULL) {
12
-			$this->setOptions($options);
13
-		}
14
-		spl_autoload_register(array(__CLASS__, 'autoload'));
15
-	}
16
-
17
-	public static function getInstance($options = NULL) {
18
-		if (null === self::$instance) {
19
-			self::$instance = new self($options);
20
-		}
21
-
22
-		return self::$instance;
23
-	}
24
-
25
-	public static function autoload($className) {
26
-		if($className === NULL) {
27
-			return;
28
-		}
29
-
30
-		$self = self::getInstance();
31
-
32
-		$substr5 = substr($className, 0, 5);
33
-
34
-		if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') {
35
-			$file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
36
-		} elseif ($className === 'QRcode') {
37
-			$file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php';
38
-		} elseif ($substr5 === 'Zend_') {
39
-			$file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
40
-		} else {
41
-			return;
42
-		}
43
-
44
-		if (file_exists($file)) {
45
-			require_once($file);
46
-		}
47
-	}
48
-
49
-	public function setOptions($options) {
50
-		if (isset($options["tiqr.path"])) {
51
-			$tiqr_dir = $options["tiqr.path"];
52
-			$tiqr_path = realpath($tiqr_dir);
53
-		} else {
54
-			$tiqr_dir = dirname(__FILE__);
55
-			$tiqr_path = $tiqr_dir;
56
-		}
57
-		if (is_dir($tiqr_path)) {
58
-			$this->tiqrPath = $tiqr_path;
59
-		} else {
60
-			throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE));
61
-		}
62
-
63
-		if (isset($options["phpqrcode.path"])) {
64
-			$qrcode_dir = $options["phpqrcode.path"];
65
-			$qrcode_path = realpath($qrcode_dir);
66
-		} else {
67
-			$qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode';
68
-			$qrcode_path = $qrcode_dir;
69
-		}
70
-
71
-		if (is_dir($qrcode_path)) {
72
-			$this->qrcodePath = $qrcode_path;
73
-		} else {
74
-			throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE));
75
-		}
76
-
77
-		if (isset($options["zend.path"])) {
78
-			$zend_dir = $options["zend.path"];
79
-			$zend_path = realpath($zend_dir);
80
-		} else {
81
-			$zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend";
82
-			$zend_path = $zend_dir;
83
-		}
84
-		if (is_dir($zend_path)) {
85
-			$this->zendPath = $zend_path;
86
-		} else {
87
-			throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE));
88
-		}
89
-	}
90
-
91
-
92
-	public function setIncludePath() {
93
-		set_include_path(implode(PATH_SEPARATOR, array(
94
-			$this->tiqrPath,
95
-			$this->zendPath,
96
-			$this->qrcodePath,
97
-			get_include_path(),
98
-		)));
99
-	}
4
+    protected static $instance;
5
+
6
+    protected $tiqrPath;
7
+    protected $qrcodePath;
8
+    protected $zendPath;
9
+
10
+    protected function __construct($options) {
11
+        if ($options !== NULL) {
12
+            $this->setOptions($options);
13
+        }
14
+        spl_autoload_register(array(__CLASS__, 'autoload'));
15
+    }
16
+
17
+    public static function getInstance($options = NULL) {
18
+        if (null === self::$instance) {
19
+            self::$instance = new self($options);
20
+        }
21
+
22
+        return self::$instance;
23
+    }
24
+
25
+    public static function autoload($className) {
26
+        if($className === NULL) {
27
+            return;
28
+        }
29
+
30
+        $self = self::getInstance();
31
+
32
+        $substr5 = substr($className, 0, 5);
33
+
34
+        if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') {
35
+            $file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
36
+        } elseif ($className === 'QRcode') {
37
+            $file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php';
38
+        } elseif ($substr5 === 'Zend_') {
39
+            $file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
40
+        } else {
41
+            return;
42
+        }
43
+
44
+        if (file_exists($file)) {
45
+            require_once($file);
46
+        }
47
+    }
48
+
49
+    public function setOptions($options) {
50
+        if (isset($options["tiqr.path"])) {
51
+            $tiqr_dir = $options["tiqr.path"];
52
+            $tiqr_path = realpath($tiqr_dir);
53
+        } else {
54
+            $tiqr_dir = dirname(__FILE__);
55
+            $tiqr_path = $tiqr_dir;
56
+        }
57
+        if (is_dir($tiqr_path)) {
58
+            $this->tiqrPath = $tiqr_path;
59
+        } else {
60
+            throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE));
61
+        }
62
+
63
+        if (isset($options["phpqrcode.path"])) {
64
+            $qrcode_dir = $options["phpqrcode.path"];
65
+            $qrcode_path = realpath($qrcode_dir);
66
+        } else {
67
+            $qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode';
68
+            $qrcode_path = $qrcode_dir;
69
+        }
70
+
71
+        if (is_dir($qrcode_path)) {
72
+            $this->qrcodePath = $qrcode_path;
73
+        } else {
74
+            throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE));
75
+        }
76
+
77
+        if (isset($options["zend.path"])) {
78
+            $zend_dir = $options["zend.path"];
79
+            $zend_path = realpath($zend_dir);
80
+        } else {
81
+            $zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend";
82
+            $zend_path = $zend_dir;
83
+        }
84
+        if (is_dir($zend_path)) {
85
+            $this->zendPath = $zend_path;
86
+        } else {
87
+            throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE));
88
+        }
89
+    }
90
+
91
+
92
+    public function setIncludePath() {
93
+        set_include_path(implode(PATH_SEPARATOR, array(
94
+            $this->tiqrPath,
95
+            $this->zendPath,
96
+            $this->qrcodePath,
97
+            get_include_path(),
98
+        )));
99
+    }
100 100
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	}
24 24
 
25 25
 	public static function autoload($className) {
26
-		if($className === NULL) {
26
+		if ($className === NULL) {
27 27
 			return;
28 28
 		}
29 29
 
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
 		$substr5 = substr($className, 0, 5);
33 33
 
34 34
 		if ($substr5 === 'Tiqr_' || $substr5 === 'OATH_') {
35
-			$file = $self->tiqrPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
35
+			$file = $self->tiqrPath.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
36 36
 		} elseif ($className === 'QRcode') {
37
-			$file = $self->qrcodePath . DIRECTORY_SEPARATOR . 'qrlib.php';
37
+			$file = $self->qrcodePath.DIRECTORY_SEPARATOR.'qrlib.php';
38 38
 		} elseif ($substr5 === 'Zend_') {
39
-			$file = $self->zendPath . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
39
+			$file = $self->zendPath.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
40 40
 		} else {
41 41
 			return;
42 42
 		}
@@ -57,34 +57,34 @@  discard block
 block discarded – undo
57 57
 		if (is_dir($tiqr_path)) {
58 58
 			$this->tiqrPath = $tiqr_path;
59 59
 		} else {
60
-			throw new Exception('Directory not found: ' . var_export($tiqr_dir, TRUE));
60
+			throw new Exception('Directory not found: '.var_export($tiqr_dir, TRUE));
61 61
 		}
62 62
 
63 63
 		if (isset($options["phpqrcode.path"])) {
64 64
 			$qrcode_dir = $options["phpqrcode.path"];
65 65
 			$qrcode_path = realpath($qrcode_dir);
66 66
 		} else {
67
-			$qrcode_dir = dirname(dirname(dirname(__FILE__))) . '/phpqrcode';
67
+			$qrcode_dir = dirname(dirname(dirname(__FILE__))).'/phpqrcode';
68 68
 			$qrcode_path = $qrcode_dir;
69 69
 		}
70 70
 
71 71
 		if (is_dir($qrcode_path)) {
72 72
 			$this->qrcodePath = $qrcode_path;
73 73
 		} else {
74
-			throw new Exception('Directory not found: ' . var_export($qrcode_dir, TRUE));
74
+			throw new Exception('Directory not found: '.var_export($qrcode_dir, TRUE));
75 75
 		}
76 76
 
77 77
 		if (isset($options["zend.path"])) {
78 78
 			$zend_dir = $options["zend.path"];
79 79
 			$zend_path = realpath($zend_dir);
80 80
 		} else {
81
-			$zend_dir = dirname(dirname(dirname(__FILE__))) . "/zend";
81
+			$zend_dir = dirname(dirname(dirname(__FILE__)))."/zend";
82 82
 			$zend_path = $zend_dir;
83 83
 		}
84 84
 		if (is_dir($zend_path)) {
85 85
 			$this->zendPath = $zend_path;
86 86
 		} else {
87
-			throw new Exception('Directory not found: ' . var_export($zend_dir, TRUE));
87
+			throw new Exception('Directory not found: '.var_export($zend_dir, TRUE));
88 88
 		}
89 89
 	}
90 90
 
Please login to merge, or discard this patch.
library/tiqr/OATH/OCRAParser.php 2 patches
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -4,241 +4,241 @@
 block discarded – undo
4 4
 
5 5
 class OATH_OCRAParser {
6 6
 
7
-	private $key = NULL;
8
-
9
-	private $OCRASuite = NULL;
10
-
11
-	private $OCRAVersion = NULL;
12
-
13
-	private $CryptoFunctionType = NULL;
14
-	private $CryptoFunctionHash = NULL;
15
-	private $CryptoFunctionHashLength = NULL;
16
-	private $CryptoFunctionTruncation = NULL;
17
-
18
-	private $C = FALSE;
19
-	private $Q = FALSE;
20
-	private $QType = 'N';
21
-	private $QLength = 8;
22
-
23
-	private $P = FALSE;
24
-	private $PType = 'SHA1';
25
-	private $PLength = 20;
26
-
27
-	private $S = FALSE;
28
-	private $SLength = 64;
29
-
30
-	private $T = FALSE;
31
-	private $TLength = 60; // 1M
32
-	private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
33
-
34
-	private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
35
-
36
-
37
-	public function __construct($ocraSuite) {
38
-		$this->parseOCRASuite($ocraSuite);
39
-	}
40
-
41
-	/**
42
-	 * Inspired by https://github.com/bdauvergne/python-oath
43
-	 */
44
-	private function parseOCRASuite($ocraSuite) {
45
-		if (!is_string($ocraSuite)) {
46
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
47
-		}
48
-
49
-		$ocraSuite = strtoupper($ocraSuite);
50
-		$this->OCRASuite = $ocraSuite;
51
-
52
-		$s = explode(':', $ocraSuite);
53
-		if (count($s) != 3) {
54
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
55
-		}
56
-
57
-		$algo = explode('-', $s[0]);
58
-		if (count($algo) != 2) {
59
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
60
-		}
61
-
62
-		if ($algo[0] !== 'OCRA') {
63
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
64
-		}
65
-
66
-		if ($algo[1] !== '1') {
67
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
68
-		}
69
-		$this->OCRAVersion = $algo[1];
70
-
71
-		$cf = explode('-', $s[1]);
72
-		if (count($cf) != 3) {
73
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
74
-		}
75
-
76
-		if ($cf[0] !== 'HOTP') {
77
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
78
-		}
79
-		$this->CryptoFunctionType = $cf[0];
80
-
81
-		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
82
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
83
-		}
84
-		$this->CryptoFunctionHash = $cf[1];
85
-		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
86
-
87
-		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
88
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
89
-		}
90
-		$this->CryptoFunctionTruncation = intval($cf[2]);
91
-
92
-		$di = explode('-', $s[2]);
93
-		if (count($cf) == 0) {
94
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
95
-		}
96
-
97
-		$data_input = array();
98
-		foreach($di as $elem) {
99
-			$letter = $elem[0];
100
-			if (array_key_exists($letter, $data_input)) {
101
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
102
-			}
103
-			$data_input[$letter] = 1;
104
-
105
-			if ($letter === 'C' && strlen($elem) == 1) {
106
-				$this->C = TRUE;
107
-			} elseif ($letter === 'Q') {
108
-				if (strlen($elem) == 1) {
109
-					$this->Q = TRUE;
110
-				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
111
-					$q_len = intval($match[2]);
112
-					if ($q_len < 4 || $q_len > 64) {
113
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
114
-					}
115
-					$this->Q = TRUE;
116
-					$this->QType = $match[1];
117
-					$this->QLength = $q_len;
118
-				} else {
119
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
120
-				}
121
-			} elseif ($letter === 'P') {
122
-				if (strlen($elem) == 1) {
123
-					$this->P = TRUE;
124
-				} else {
125
-					$p_algo = substr($elem, 1);
126
-					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
127
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
128
-					}
129
-					$this->P = TRUE;
130
-					$this->PType = $p_algo;
131
-					$this->PLength = $this->supportedHashFunctions[$p_algo];
132
-				}
133
-			} elseif ($letter === 'S') {
134
-				if (strlen($elem) == 1) {
135
-					$this->S = TRUE;
136
-				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
137
-					$s_len = intval($match[1]);
138
-					if ($s_len <= 0 || $s_len > 512) {
139
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
140
-					}
141
-
142
-					$this->S = TRUE;
143
-					$this->SLength = $s_len;
144
-				} else {
145
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
146
-				}
147
-			} elseif ($letter === 'T') {
148
-				if (strlen($elem) == 1) {
149
-					$this->T = TRUE;
150
-				} elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
151
-					preg_match_all('/(\d+)([HMS])/', $elem, $match);
152
-
153
-					if (count($match[1]) !== count(array_unique($match[2]))) {
154
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
155
-					}
156
-
157
-					$length = 0;
158
-					for ($i = 0; $i < count($match[1]); $i++) {
159
-						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
160
-					}
161
-					if ($length <= 0) {
162
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
163
-					}
164
-
165
-					$this->T = TRUE;
166
-					$this->TLength = $length;
167
-				} else {
168
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
169
-				}
170
-			} else {
171
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
172
-			}
173
-		}
174
-
175
-		if (!$this->Q) {
176
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
177
-		}
178
-	}
179
-
180
-	public function generateChallenge() {
181
-		$q_length = $this->QLength;
182
-		$q_type = $this->QType;
7
+    private $key = NULL;
8
+
9
+    private $OCRASuite = NULL;
10
+
11
+    private $OCRAVersion = NULL;
12
+
13
+    private $CryptoFunctionType = NULL;
14
+    private $CryptoFunctionHash = NULL;
15
+    private $CryptoFunctionHashLength = NULL;
16
+    private $CryptoFunctionTruncation = NULL;
17
+
18
+    private $C = FALSE;
19
+    private $Q = FALSE;
20
+    private $QType = 'N';
21
+    private $QLength = 8;
22
+
23
+    private $P = FALSE;
24
+    private $PType = 'SHA1';
25
+    private $PLength = 20;
26
+
27
+    private $S = FALSE;
28
+    private $SLength = 64;
29
+
30
+    private $T = FALSE;
31
+    private $TLength = 60; // 1M
32
+    private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
33
+
34
+    private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
35
+
36
+
37
+    public function __construct($ocraSuite) {
38
+        $this->parseOCRASuite($ocraSuite);
39
+    }
40
+
41
+    /**
42
+     * Inspired by https://github.com/bdauvergne/python-oath
43
+     */
44
+    private function parseOCRASuite($ocraSuite) {
45
+        if (!is_string($ocraSuite)) {
46
+            throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
47
+        }
48
+
49
+        $ocraSuite = strtoupper($ocraSuite);
50
+        $this->OCRASuite = $ocraSuite;
51
+
52
+        $s = explode(':', $ocraSuite);
53
+        if (count($s) != 3) {
54
+            throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
55
+        }
56
+
57
+        $algo = explode('-', $s[0]);
58
+        if (count($algo) != 2) {
59
+            throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
60
+        }
61
+
62
+        if ($algo[0] !== 'OCRA') {
63
+            throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
64
+        }
65
+
66
+        if ($algo[1] !== '1') {
67
+            throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
68
+        }
69
+        $this->OCRAVersion = $algo[1];
70
+
71
+        $cf = explode('-', $s[1]);
72
+        if (count($cf) != 3) {
73
+            throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
74
+        }
75
+
76
+        if ($cf[0] !== 'HOTP') {
77
+            throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
78
+        }
79
+        $this->CryptoFunctionType = $cf[0];
80
+
81
+        if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
82
+            throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
83
+        }
84
+        $this->CryptoFunctionHash = $cf[1];
85
+        $this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
86
+
87
+        if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
88
+            throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
89
+        }
90
+        $this->CryptoFunctionTruncation = intval($cf[2]);
91
+
92
+        $di = explode('-', $s[2]);
93
+        if (count($cf) == 0) {
94
+            throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
95
+        }
96
+
97
+        $data_input = array();
98
+        foreach($di as $elem) {
99
+            $letter = $elem[0];
100
+            if (array_key_exists($letter, $data_input)) {
101
+                throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
102
+            }
103
+            $data_input[$letter] = 1;
104
+
105
+            if ($letter === 'C' && strlen($elem) == 1) {
106
+                $this->C = TRUE;
107
+            } elseif ($letter === 'Q') {
108
+                if (strlen($elem) == 1) {
109
+                    $this->Q = TRUE;
110
+                } elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
111
+                    $q_len = intval($match[2]);
112
+                    if ($q_len < 4 || $q_len > 64) {
113
+                        throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
114
+                    }
115
+                    $this->Q = TRUE;
116
+                    $this->QType = $match[1];
117
+                    $this->QLength = $q_len;
118
+                } else {
119
+                    throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
120
+                }
121
+            } elseif ($letter === 'P') {
122
+                if (strlen($elem) == 1) {
123
+                    $this->P = TRUE;
124
+                } else {
125
+                    $p_algo = substr($elem, 1);
126
+                    if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
127
+                        throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
128
+                    }
129
+                    $this->P = TRUE;
130
+                    $this->PType = $p_algo;
131
+                    $this->PLength = $this->supportedHashFunctions[$p_algo];
132
+                }
133
+            } elseif ($letter === 'S') {
134
+                if (strlen($elem) == 1) {
135
+                    $this->S = TRUE;
136
+                } elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
137
+                    $s_len = intval($match[1]);
138
+                    if ($s_len <= 0 || $s_len > 512) {
139
+                        throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
140
+                    }
141
+
142
+                    $this->S = TRUE;
143
+                    $this->SLength = $s_len;
144
+                } else {
145
+                    throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
146
+                }
147
+            } elseif ($letter === 'T') {
148
+                if (strlen($elem) == 1) {
149
+                    $this->T = TRUE;
150
+                } elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
151
+                    preg_match_all('/(\d+)([HMS])/', $elem, $match);
152
+
153
+                    if (count($match[1]) !== count(array_unique($match[2]))) {
154
+                        throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
155
+                    }
156
+
157
+                    $length = 0;
158
+                    for ($i = 0; $i < count($match[1]); $i++) {
159
+                        $length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
160
+                    }
161
+                    if ($length <= 0) {
162
+                        throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
163
+                    }
164
+
165
+                    $this->T = TRUE;
166
+                    $this->TLength = $length;
167
+                } else {
168
+                    throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
169
+                }
170
+            } else {
171
+                throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
172
+            }
173
+        }
174
+
175
+        if (!$this->Q) {
176
+            throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
177
+        }
178
+    }
179
+
180
+    public function generateChallenge() {
181
+        $q_length = $this->QLength;
182
+        $q_type = $this->QType;
183 183
 
184 184
         $bytes = Tiqr_Random::randomBytes($q_length);
185 185
 
186
-		switch($q_type) {
187
-			case 'A':
188
-				$challenge = base64_encode($bytes);
189
-				$tr = implode("", unpack('H*', $bytes));
190
-				$challenge = rtrim(strtr($challenge, '+/', $tr), '=');
191
-				break;
192
-			case 'H':
193
-				$challenge = implode("", unpack('H*', $bytes));
194
-				break;
195
-			case 'N':
196
-				$challenge = implode("", unpack('N*', $bytes));
197
-				break;
198
-			default:
199
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
200
-				break;
201
-		}
202
-
203
-		$challenge = substr($challenge, 0, $q_length);
204
-
205
-		return $challenge;
206
-	}
207
-
208
-
209
-	public function generateSessionInformation() {
210
-		if (!$this->S) {
211
-			throw new Exception('Session information not defined in OCRASuite: ' . var_export($this->OCRASuite, TRUE));
212
-		}
213
-
214
-		$s_length = $this->SLength;
186
+        switch($q_type) {
187
+            case 'A':
188
+                $challenge = base64_encode($bytes);
189
+                $tr = implode("", unpack('H*', $bytes));
190
+                $challenge = rtrim(strtr($challenge, '+/', $tr), '=');
191
+                break;
192
+            case 'H':
193
+                $challenge = implode("", unpack('H*', $bytes));
194
+                break;
195
+            case 'N':
196
+                $challenge = implode("", unpack('N*', $bytes));
197
+                break;
198
+            default:
199
+                throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
200
+                break;
201
+        }
202
+
203
+        $challenge = substr($challenge, 0, $q_length);
204
+
205
+        return $challenge;
206
+    }
207
+
208
+
209
+    public function generateSessionInformation() {
210
+        if (!$this->S) {
211
+            throw new Exception('Session information not defined in OCRASuite: ' . var_export($this->OCRASuite, TRUE));
212
+        }
213
+
214
+        $s_length = $this->SLength;
215 215
         $bytes = Tiqr_Random::randomBytes($s_length);
216 216
 
217
-		// The OCRA spec doesn't specify that the session data should be hexadecimal.
218
-		// However the reference implementation in the RFC does treat it as hex.
219
-		$session = bin2hex($bytes);
217
+        // The OCRA spec doesn't specify that the session data should be hexadecimal.
218
+        // However the reference implementation in the RFC does treat it as hex.
219
+        $session = bin2hex($bytes);
220 220
 		
221
-		$session = substr($session, 0, $s_length);
221
+        $session = substr($session, 0, $s_length);
222 222
 		
223
-		return $session;
224
-	}
225
-
226
-
227
-	/**
228
-	 * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
229
-	 */
230
-	public static function constEqual($s1, $s2) {
231
-		if (strlen($s1) != strlen($s2)) {
232
-			return FALSE;
233
-		}
234
-
235
-		$result = TRUE;
236
-		$length = strlen($s1);
237
-		for ($i = 0; $i < $length; $i++) {
238
-			$result &= ($s1[$i] == $s2[$i]);
239
-		}
240
-
241
-		return (boolean)$result;
242
-	}
223
+        return $session;
224
+    }
225
+
226
+
227
+    /**
228
+     * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
229
+     */
230
+    public static function constEqual($s1, $s2) {
231
+        if (strlen($s1) != strlen($s2)) {
232
+            return FALSE;
233
+        }
234
+
235
+        $result = TRUE;
236
+        $length = strlen($s1);
237
+        for ($i = 0; $i < $length; $i++) {
238
+            $result &= ($s1[$i] == $s2[$i]);
239
+        }
240
+
241
+        return (boolean)$result;
242
+    }
243 243
 
244 244
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once ( __DIR__ . "/../Tiqr/Random.php");
3
+require_once (__DIR__."/../Tiqr/Random.php");
4 4
 
5 5
 class OATH_OCRAParser {
6 6
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	private function parseOCRASuite($ocraSuite) {
45 45
 		if (!is_string($ocraSuite)) {
46
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
46
+			throw new Exception('OCRASuite not in string format: '.var_export($ocraSuite, TRUE));
47 47
 		}
48 48
 
49 49
 		$ocraSuite = strtoupper($ocraSuite);
@@ -51,54 +51,54 @@  discard block
 block discarded – undo
51 51
 
52 52
 		$s = explode(':', $ocraSuite);
53 53
 		if (count($s) != 3) {
54
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
54
+			throw new Exception('Invalid OCRASuite format: '.var_export($ocraSuite, TRUE));
55 55
 		}
56 56
 
57 57
 		$algo = explode('-', $s[0]);
58 58
 		if (count($algo) != 2) {
59
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
59
+			throw new Exception('Invalid OCRA version: '.var_export($s[0], TRUE));
60 60
 		}
61 61
 
62 62
 		if ($algo[0] !== 'OCRA') {
63
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
63
+			throw new Exception('Unsupported OCRA algorithm: '.var_export($algo[0], TRUE));
64 64
 		}
65 65
 
66 66
 		if ($algo[1] !== '1') {
67
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
67
+			throw new Exception('Unsupported OCRA version: '.var_export($algo[1], TRUE));
68 68
 		}
69 69
 		$this->OCRAVersion = $algo[1];
70 70
 
71 71
 		$cf = explode('-', $s[1]);
72 72
 		if (count($cf) != 3) {
73
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
73
+			throw new Exception('Invalid OCRA suite crypto function: '.var_export($s[1], TRUE));
74 74
 		}
75 75
 
76 76
 		if ($cf[0] !== 'HOTP') {
77
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
77
+			throw new Exception('Unsupported OCRA suite crypto function: '.var_export($cf[0], TRUE));
78 78
 		}
79 79
 		$this->CryptoFunctionType = $cf[0];
80 80
 
81 81
 		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
82
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
82
+			throw new Exception('Unsupported hash function in OCRA suite crypto function: '.var_export($cf[1], TRUE));
83 83
 		}
84 84
 		$this->CryptoFunctionHash = $cf[1];
85 85
 		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
86 86
 
87 87
 		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
88
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
88
+			throw new Exception('Invalid OCRA suite crypto function truncation length: '.var_export($cf[2], TRUE));
89 89
 		}
90 90
 		$this->CryptoFunctionTruncation = intval($cf[2]);
91 91
 
92 92
 		$di = explode('-', $s[2]);
93 93
 		if (count($cf) == 0) {
94
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
94
+			throw new Exception('Invalid OCRA suite data input: '.var_export($s[2], TRUE));
95 95
 		}
96 96
 
97 97
 		$data_input = array();
98
-		foreach($di as $elem) {
98
+		foreach ($di as $elem) {
99 99
 			$letter = $elem[0];
100 100
 			if (array_key_exists($letter, $data_input)) {
101
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
101
+				throw new Exception('Duplicate field in OCRA suite data input: '.var_export($elem, TRUE));
102 102
 			}
103 103
 			$data_input[$letter] = 1;
104 104
 
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
111 111
 					$q_len = intval($match[2]);
112 112
 					if ($q_len < 4 || $q_len > 64) {
113
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
113
+						throw new Exception('Invalid OCRA suite data input question length: '.var_export($q_len, TRUE));
114 114
 					}
115 115
 					$this->Q = TRUE;
116 116
 					$this->QType = $match[1];
117 117
 					$this->QLength = $q_len;
118 118
 				} else {
119
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
119
+					throw new Exception('Invalid OCRA suite data input question: '.var_export($elem, TRUE));
120 120
 				}
121 121
 			} elseif ($letter === 'P') {
122 122
 				if (strlen($elem) == 1) {
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 				} else {
125 125
 					$p_algo = substr($elem, 1);
126 126
 					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
127
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
127
+						throw new Exception('Unsupported OCRA suite PIN hash function: '.var_export($elem, TRUE));
128 128
 					}
129 129
 					$this->P = TRUE;
130 130
 					$this->PType = $p_algo;
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
137 137
 					$s_len = intval($match[1]);
138 138
 					if ($s_len <= 0 || $s_len > 512) {
139
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
139
+						throw new Exception('Invalid OCRA suite data input session information length: '.var_export($s_len, TRUE));
140 140
 					}
141 141
 
142 142
 					$this->S = TRUE;
143 143
 					$this->SLength = $s_len;
144 144
 				} else {
145
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
145
+					throw new Exception('Invalid OCRA suite data input session information length: '.var_export($elem, TRUE));
146 146
 				}
147 147
 			} elseif ($letter === 'T') {
148 148
 				if (strlen($elem) == 1) {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 					preg_match_all('/(\d+)([HMS])/', $elem, $match);
152 152
 
153 153
 					if (count($match[1]) !== count(array_unique($match[2]))) {
154
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
154
+						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: '.var_export($elem, TRUE));
155 155
 					}
156 156
 
157 157
 					$length = 0;
@@ -159,21 +159,21 @@  discard block
 block discarded – undo
159 159
 						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
160 160
 					}
161 161
 					if ($length <= 0) {
162
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
162
+						throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
163 163
 					}
164 164
 
165 165
 					$this->T = TRUE;
166 166
 					$this->TLength = $length;
167 167
 				} else {
168
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
168
+					throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
169 169
 				}
170 170
 			} else {
171
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
171
+				throw new Exception('Unsupported OCRA suite data input field: '.var_export($elem, TRUE));
172 172
 			}
173 173
 		}
174 174
 
175 175
 		if (!$this->Q) {
176
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
176
+			throw new Exception('OCRA suite data input question not defined: '.var_export($s[2], TRUE));
177 177
 		}
178 178
 	}
179 179
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
         $bytes = Tiqr_Random::randomBytes($q_length);
185 185
 
186
-		switch($q_type) {
186
+		switch ($q_type) {
187 187
 			case 'A':
188 188
 				$challenge = base64_encode($bytes);
189 189
 				$tr = implode("", unpack('H*', $bytes));
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 				$challenge = implode("", unpack('N*', $bytes));
197 197
 				break;
198 198
 			default:
199
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
199
+				throw new Exception('Unsupported OCRASuite challenge type: '.var_export($q_type, TRUE));
200 200
 				break;
201 201
 		}
202 202
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 
209 209
 	public function generateSessionInformation() {
210 210
 		if (!$this->S) {
211
-			throw new Exception('Session information not defined in OCRASuite: ' . var_export($this->OCRASuite, TRUE));
211
+			throw new Exception('Session information not defined in OCRASuite: '.var_export($this->OCRASuite, TRUE));
212 212
 		}
213 213
 
214 214
 		$s_length = $this->SLength;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 			$result &= ($s1[$i] == $s2[$i]);
239 239
 		}
240 240
 
241
-		return (boolean)$result;
241
+		return (boolean) $result;
242 242
 	}
243 243
 
244 244
 }
Please login to merge, or discard this patch.