Completed
Push — master ( 8024f3...e355ed )
by Michiel
03:33 queued 14s
created
library/tiqr/OATH/OCRAParser.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -238,6 +238,7 @@  discard block
 block discarded – undo
238 238
 
239 239
 	/**
240 240
 	 * Borrowed from SimpleSAMLPHP http://simplesamlphp.org/
241
+	 * @param integer $length
241 242
 	 */
242 243
 	public static function generateRandomBytes($length, $fallback = TRUE) {
243 244
 		static $fp = NULL;
@@ -278,6 +279,8 @@  discard block
 block discarded – undo
278 279
 
279 280
 	/**
280 281
 	 * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
282
+	 * @param string $s1
283
+	 * @param string $s2
281 284
 	 */
282 285
 	public static function constEqual($s1, $s2) {
283 286
 		if (strlen($s1) != strlen($s2)) {
Please login to merge, or discard this patch.
Indentation   +288 added lines, -288 removed lines patch added patch discarded remove patch
@@ -2,295 +2,295 @@
 block discarded – undo
2 2
 
3 3
 class OATH_OCRAParser {
4 4
 
5
-	private $key = NULL;
6
-
7
-	private $OCRASuite = NULL;
8
-
9
-	private $OCRAVersion = NULL;
10
-
11
-	private $CryptoFunctionType = NULL;
12
-	private $CryptoFunctionHash = NULL;
13
-	private $CryptoFunctionHashLength = NULL;
14
-	private $CryptoFunctionTruncation = NULL;
15
-
16
-	private $C = FALSE;
17
-	private $Q = FALSE;
18
-	private $QType = 'N';
19
-	private $QLength = 8;
20
-
21
-	private $P = FALSE;
22
-	private $PType = 'SHA1';
23
-	private $PLength = 20;
24
-
25
-	private $S = FALSE;
26
-	private $SLength = 64;
27
-
28
-	private $T = FALSE;
29
-	private $TLength = 60; // 1M
30
-	private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
31
-
32
-	private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
33
-
34
-
35
-	public function __construct($ocraSuite) {
36
-		$this->parseOCRASuite($ocraSuite);
37
-	}
38
-
39
-	/**
40
-	 * Inspired by https://github.com/bdauvergne/python-oath
41
-	 */
42
-	private function parseOCRASuite($ocraSuite) {
43
-		if (!is_string($ocraSuite)) {
44
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
45
-		}
46
-
47
-		$ocraSuite = strtoupper($ocraSuite);
48
-		$this->OCRASuite = $ocraSuite;
49
-
50
-		$s = explode(':', $ocraSuite);
51
-		if (count($s) != 3) {
52
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
53
-		}
54
-
55
-		$algo = explode('-', $s[0]);
56
-		if (count($algo) != 2) {
57
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
58
-		}
59
-
60
-		if ($algo[0] !== 'OCRA') {
61
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
62
-		}
63
-
64
-		if ($algo[1] !== '1') {
65
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
66
-		}
67
-		$this->OCRAVersion = $algo[1];
68
-
69
-		$cf = explode('-', $s[1]);
70
-		if (count($cf) != 3) {
71
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
72
-		}
73
-
74
-		if ($cf[0] !== 'HOTP') {
75
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
76
-		}
77
-		$this->CryptoFunctionType = $cf[0];
78
-
79
-		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
80
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
81
-		}
82
-		$this->CryptoFunctionHash = $cf[1];
83
-		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
84
-
85
-		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
86
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
87
-		}
88
-		$this->CryptoFunctionTruncation = intval($cf[2]);
89
-
90
-		$di = explode('-', $s[2]);
91
-		if (count($cf) == 0) {
92
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
93
-		}
94
-
95
-		$data_input = array();
96
-		foreach($di as $elem) {
97
-			$letter = $elem[0];
98
-			if (array_key_exists($letter, $data_input)) {
99
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
100
-			}
101
-			$data_input[$letter] = 1;
102
-
103
-			if ($letter === 'C' && strlen($elem) == 1) {
104
-				$this->C = TRUE;
105
-			} elseif ($letter === 'Q') {
106
-				if (strlen($elem) == 1) {
107
-					$this->Q = TRUE;
108
-				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
109
-					$q_len = intval($match[2]);
110
-					if ($q_len < 4 || $q_len > 64) {
111
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
112
-					}
113
-					$this->Q = TRUE;
114
-					$this->QType = $match[1];
115
-					$this->QLength = $q_len;
116
-				} else {
117
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
118
-				}
119
-			} elseif ($letter === 'P') {
120
-				if (strlen($elem) == 1) {
121
-					$this->P = TRUE;
122
-				} else {
123
-					$p_algo = substr($elem, 1);
124
-					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
125
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
126
-					}
127
-					$this->P = TRUE;
128
-					$this->PType = $p_algo;
129
-					$this->PLength = $this->supportedHashFunctions[$p_algo];
130
-				}
131
-			} elseif ($letter === 'S') {
132
-				if (strlen($elem) == 1) {
133
-					$this->S = TRUE;
134
-				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
135
-					$s_len = intval($match[1]);
136
-					if ($s_len <= 0 || $s_len > 512) {
137
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
138
-					}
139
-
140
-					$this->S = TRUE;
141
-					$this->SLength = $s_len;
142
-				} else {
143
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
144
-				}
145
-			} elseif ($letter === 'T') {
146
-				if (strlen($elem) == 1) {
147
-					$this->T = TRUE;
148
-				} elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
149
-					preg_match_all('/(\d+)([HMS])/', $elem, $match);
150
-
151
-					if (count($match[1]) !== count(array_unique($match[2]))) {
152
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
153
-					}
154
-
155
-					$length = 0;
156
-					for ($i = 0; $i < count($match[1]); $i++) {
157
-						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
158
-					}
159
-					if ($length <= 0) {
160
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
161
-					}
162
-
163
-					$this->T = TRUE;
164
-					$this->TLength = $length;
165
-				} else {
166
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
167
-				}
168
-			} else {
169
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
170
-			}
171
-		}
172
-
173
-		if (!$this->Q) {
174
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
175
-		}
176
-	}
177
-
178
-	public function generateChallenge() {
179
-		$q_length = $this->QLength;
180
-		$q_type = $this->QType;
181
-
182
-		$bytes = self::generateRandomBytes($q_length);
183
-
184
-		switch($q_type) {
185
-			case 'A':
186
-				$challenge = base64_encode($bytes);
187
-				$tr = implode("", unpack('H*', $bytes));
188
-				$challenge = rtrim(strtr($challenge, '+/', $tr), '=');
189
-				break;
190
-			case 'H':
191
-				$challenge = implode("", unpack('H*', $bytes));
192
-				break;
193
-			case 'N':
194
-				$challenge = implode("", unpack('N*', $bytes));
195
-				break;
196
-			default:
197
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
198
-				break;
199
-		}
200
-
201
-		$challenge = substr($challenge, 0, $q_length);
202
-
203
-		return $challenge;
204
-	}
205
-
206
-
207
-	public function generateSessionInformation() {
208
-		if (!$this->S) {
209
-			throw new Exception('Session information not defined in OCRASuite: ' . var_export($this->OCRASuite, TRUE));
210
-		}
211
-
212
-		$s_length = $this->SLength;
213
-		$bytes = self::generateRandomBytes($s_length);
214
-
215
-		// The OCRA spec doesn't specify that the session data should be hexadecimal.
216
-		// However the reference implementation in the RFC does treat it as hex.
217
-		$session = bin2hex($bytes);
5
+    private $key = NULL;
6
+
7
+    private $OCRASuite = NULL;
8
+
9
+    private $OCRAVersion = NULL;
10
+
11
+    private $CryptoFunctionType = NULL;
12
+    private $CryptoFunctionHash = NULL;
13
+    private $CryptoFunctionHashLength = NULL;
14
+    private $CryptoFunctionTruncation = NULL;
15
+
16
+    private $C = FALSE;
17
+    private $Q = FALSE;
18
+    private $QType = 'N';
19
+    private $QLength = 8;
20
+
21
+    private $P = FALSE;
22
+    private $PType = 'SHA1';
23
+    private $PLength = 20;
24
+
25
+    private $S = FALSE;
26
+    private $SLength = 64;
27
+
28
+    private $T = FALSE;
29
+    private $TLength = 60; // 1M
30
+    private $TPeriods = array('H' => 3600, 'M' => 60, 'S' => 1);
31
+
32
+    private $supportedHashFunctions = array('SHA1' => 20, 'SHA256' => 32, 'SHA512' => 64);
33
+
34
+
35
+    public function __construct($ocraSuite) {
36
+        $this->parseOCRASuite($ocraSuite);
37
+    }
38
+
39
+    /**
40
+     * Inspired by https://github.com/bdauvergne/python-oath
41
+     */
42
+    private function parseOCRASuite($ocraSuite) {
43
+        if (!is_string($ocraSuite)) {
44
+            throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
45
+        }
46
+
47
+        $ocraSuite = strtoupper($ocraSuite);
48
+        $this->OCRASuite = $ocraSuite;
49
+
50
+        $s = explode(':', $ocraSuite);
51
+        if (count($s) != 3) {
52
+            throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
53
+        }
54
+
55
+        $algo = explode('-', $s[0]);
56
+        if (count($algo) != 2) {
57
+            throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
58
+        }
59
+
60
+        if ($algo[0] !== 'OCRA') {
61
+            throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
62
+        }
63
+
64
+        if ($algo[1] !== '1') {
65
+            throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
66
+        }
67
+        $this->OCRAVersion = $algo[1];
68
+
69
+        $cf = explode('-', $s[1]);
70
+        if (count($cf) != 3) {
71
+            throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
72
+        }
73
+
74
+        if ($cf[0] !== 'HOTP') {
75
+            throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
76
+        }
77
+        $this->CryptoFunctionType = $cf[0];
78
+
79
+        if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
80
+            throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
81
+        }
82
+        $this->CryptoFunctionHash = $cf[1];
83
+        $this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
84
+
85
+        if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
86
+            throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
87
+        }
88
+        $this->CryptoFunctionTruncation = intval($cf[2]);
89
+
90
+        $di = explode('-', $s[2]);
91
+        if (count($cf) == 0) {
92
+            throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
93
+        }
94
+
95
+        $data_input = array();
96
+        foreach($di as $elem) {
97
+            $letter = $elem[0];
98
+            if (array_key_exists($letter, $data_input)) {
99
+                throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
100
+            }
101
+            $data_input[$letter] = 1;
102
+
103
+            if ($letter === 'C' && strlen($elem) == 1) {
104
+                $this->C = TRUE;
105
+            } elseif ($letter === 'Q') {
106
+                if (strlen($elem) == 1) {
107
+                    $this->Q = TRUE;
108
+                } elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
109
+                    $q_len = intval($match[2]);
110
+                    if ($q_len < 4 || $q_len > 64) {
111
+                        throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
112
+                    }
113
+                    $this->Q = TRUE;
114
+                    $this->QType = $match[1];
115
+                    $this->QLength = $q_len;
116
+                } else {
117
+                    throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
118
+                }
119
+            } elseif ($letter === 'P') {
120
+                if (strlen($elem) == 1) {
121
+                    $this->P = TRUE;
122
+                } else {
123
+                    $p_algo = substr($elem, 1);
124
+                    if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
125
+                        throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
126
+                    }
127
+                    $this->P = TRUE;
128
+                    $this->PType = $p_algo;
129
+                    $this->PLength = $this->supportedHashFunctions[$p_algo];
130
+                }
131
+            } elseif ($letter === 'S') {
132
+                if (strlen($elem) == 1) {
133
+                    $this->S = TRUE;
134
+                } elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
135
+                    $s_len = intval($match[1]);
136
+                    if ($s_len <= 0 || $s_len > 512) {
137
+                        throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
138
+                    }
139
+
140
+                    $this->S = TRUE;
141
+                    $this->SLength = $s_len;
142
+                } else {
143
+                    throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
144
+                }
145
+            } elseif ($letter === 'T') {
146
+                if (strlen($elem) == 1) {
147
+                    $this->T = TRUE;
148
+                } elseif (preg_match('/^T(\d+[HMS])+$/', $elem)) {
149
+                    preg_match_all('/(\d+)([HMS])/', $elem, $match);
150
+
151
+                    if (count($match[1]) !== count(array_unique($match[2]))) {
152
+                        throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
153
+                    }
154
+
155
+                    $length = 0;
156
+                    for ($i = 0; $i < count($match[1]); $i++) {
157
+                        $length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
158
+                    }
159
+                    if ($length <= 0) {
160
+                        throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
161
+                    }
162
+
163
+                    $this->T = TRUE;
164
+                    $this->TLength = $length;
165
+                } else {
166
+                    throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
167
+                }
168
+            } else {
169
+                throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
170
+            }
171
+        }
172
+
173
+        if (!$this->Q) {
174
+            throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
175
+        }
176
+    }
177
+
178
+    public function generateChallenge() {
179
+        $q_length = $this->QLength;
180
+        $q_type = $this->QType;
181
+
182
+        $bytes = self::generateRandomBytes($q_length);
183
+
184
+        switch($q_type) {
185
+            case 'A':
186
+                $challenge = base64_encode($bytes);
187
+                $tr = implode("", unpack('H*', $bytes));
188
+                $challenge = rtrim(strtr($challenge, '+/', $tr), '=');
189
+                break;
190
+            case 'H':
191
+                $challenge = implode("", unpack('H*', $bytes));
192
+                break;
193
+            case 'N':
194
+                $challenge = implode("", unpack('N*', $bytes));
195
+                break;
196
+            default:
197
+                throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
198
+                break;
199
+        }
200
+
201
+        $challenge = substr($challenge, 0, $q_length);
202
+
203
+        return $challenge;
204
+    }
205
+
206
+
207
+    public function generateSessionInformation() {
208
+        if (!$this->S) {
209
+            throw new Exception('Session information not defined in OCRASuite: ' . var_export($this->OCRASuite, TRUE));
210
+        }
211
+
212
+        $s_length = $this->SLength;
213
+        $bytes = self::generateRandomBytes($s_length);
214
+
215
+        // The OCRA spec doesn't specify that the session data should be hexadecimal.
216
+        // However the reference implementation in the RFC does treat it as hex.
217
+        $session = bin2hex($bytes);
218 218
 		
219
-		$session = substr($session, 0, $s_length);
219
+        $session = substr($session, 0, $s_length);
220 220
 		
221
-		return $session;
222
-	}
223
-
224
-	/**
225
-	 * Borrowed from SimpleSAMLPHP http://simplesamlphp.org/
226
-	 */
227
-	public static function generateRandomBytesMTrand($length) {
228
-
229
-		/* Use mt_rand to generate $length random bytes. */
230
-		$data = '';
231
-		for($i = 0; $i < $length; $i++) {
232
-			$data .= chr(mt_rand(0, 255));
233
-		}
234
-
235
-		return $data;
236
-	}
237
-
238
-
239
-	/**
240
-	 * Borrowed from SimpleSAMLPHP http://simplesamlphp.org/
241
-	 */
242
-	public static function generateRandomBytes($length, $fallback = TRUE) {
243
-		static $fp = NULL;
244
-
245
-		if (function_exists('openssl_random_pseudo_bytes')) {
246
-			return openssl_random_pseudo_bytes($length);
247
-		}
248
-
249
-		if($fp === NULL) {
250
-			if (@file_exists('/dev/urandom')) {
251
-				$fp = @fopen('/dev/urandom', 'rb');
252
-			} else {
253
-				$fp = FALSE;
254
-			}
255
-		}
256
-
257
-		if($fp !== FALSE) {
258
-			/* Read random bytes from /dev/urandom. */
259
-			$data = fread($fp, $length);
260
-			if($data === FALSE) {
261
-				throw new Exception('Error reading random data.');
262
-			}
263
-			if(strlen($data) != $length) {
264
-				if ($fallback) {
265
-					$data = self::generateRandomBytesMTrand($length);
266
-				} else {
267
-					throw new Exception('Did not get requested number of bytes from random source. Requested (' . $length . ') got (' . strlen($data) . ')');
268
-				}
269
-			}
270
-		} else {
271
-			/* Use mt_rand to generate $length random bytes. */
272
-			$data = self::generateRandomBytesMTrand($length);
273
-		}
274
-
275
-		return $data;
276
-	}
277
-
278
-
279
-	/**
280
-	 * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
281
-	 */
282
-	public static function constEqual($s1, $s2) {
283
-		if (strlen($s1) != strlen($s2)) {
284
-			return FALSE;
285
-		}
286
-
287
-		$result = TRUE;
288
-		$length = strlen($s1);
289
-		for ($i = 0; $i < $length; $i++) {
290
-			$result &= ($s1[$i] == $s2[$i]);
291
-		}
292
-
293
-		return (boolean)$result;
294
-	}
221
+        return $session;
222
+    }
223
+
224
+    /**
225
+     * Borrowed from SimpleSAMLPHP http://simplesamlphp.org/
226
+     */
227
+    public static function generateRandomBytesMTrand($length) {
228
+
229
+        /* Use mt_rand to generate $length random bytes. */
230
+        $data = '';
231
+        for($i = 0; $i < $length; $i++) {
232
+            $data .= chr(mt_rand(0, 255));
233
+        }
234
+
235
+        return $data;
236
+    }
237
+
238
+
239
+    /**
240
+     * Borrowed from SimpleSAMLPHP http://simplesamlphp.org/
241
+     */
242
+    public static function generateRandomBytes($length, $fallback = TRUE) {
243
+        static $fp = NULL;
244
+
245
+        if (function_exists('openssl_random_pseudo_bytes')) {
246
+            return openssl_random_pseudo_bytes($length);
247
+        }
248
+
249
+        if($fp === NULL) {
250
+            if (@file_exists('/dev/urandom')) {
251
+                $fp = @fopen('/dev/urandom', 'rb');
252
+            } else {
253
+                $fp = FALSE;
254
+            }
255
+        }
256
+
257
+        if($fp !== FALSE) {
258
+            /* Read random bytes from /dev/urandom. */
259
+            $data = fread($fp, $length);
260
+            if($data === FALSE) {
261
+                throw new Exception('Error reading random data.');
262
+            }
263
+            if(strlen($data) != $length) {
264
+                if ($fallback) {
265
+                    $data = self::generateRandomBytesMTrand($length);
266
+                } else {
267
+                    throw new Exception('Did not get requested number of bytes from random source. Requested (' . $length . ') got (' . strlen($data) . ')');
268
+                }
269
+            }
270
+        } else {
271
+            /* Use mt_rand to generate $length random bytes. */
272
+            $data = self::generateRandomBytesMTrand($length);
273
+        }
274
+
275
+        return $data;
276
+    }
277
+
278
+
279
+    /**
280
+     * Constant time string comparison, see http://codahale.com/a-lesson-in-timing-attacks/
281
+     */
282
+    public static function constEqual($s1, $s2) {
283
+        if (strlen($s1) != strlen($s2)) {
284
+            return FALSE;
285
+        }
286
+
287
+        $result = TRUE;
288
+        $length = strlen($s1);
289
+        for ($i = 0; $i < $length; $i++) {
290
+            $result &= ($s1[$i] == $s2[$i]);
291
+        }
292
+
293
+        return (boolean)$result;
294
+    }
295 295
 
296 296
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	private function parseOCRASuite($ocraSuite) {
43 43
 		if (!is_string($ocraSuite)) {
44
-			throw new Exception('OCRASuite not in string format: ' . var_export($ocraSuite, TRUE));
44
+			throw new Exception('OCRASuite not in string format: '.var_export($ocraSuite, TRUE));
45 45
 		}
46 46
 
47 47
 		$ocraSuite = strtoupper($ocraSuite);
@@ -49,54 +49,54 @@  discard block
 block discarded – undo
49 49
 
50 50
 		$s = explode(':', $ocraSuite);
51 51
 		if (count($s) != 3) {
52
-			throw new Exception('Invalid OCRASuite format: ' . var_export($ocraSuite, TRUE));
52
+			throw new Exception('Invalid OCRASuite format: '.var_export($ocraSuite, TRUE));
53 53
 		}
54 54
 
55 55
 		$algo = explode('-', $s[0]);
56 56
 		if (count($algo) != 2) {
57
-			throw new Exception('Invalid OCRA version: ' . var_export($s[0], TRUE));
57
+			throw new Exception('Invalid OCRA version: '.var_export($s[0], TRUE));
58 58
 		}
59 59
 
60 60
 		if ($algo[0] !== 'OCRA') {
61
-			throw new Exception('Unsupported OCRA algorithm: ' . var_export($algo[0], TRUE));
61
+			throw new Exception('Unsupported OCRA algorithm: '.var_export($algo[0], TRUE));
62 62
 		}
63 63
 
64 64
 		if ($algo[1] !== '1') {
65
-			throw new Exception('Unsupported OCRA version: ' . var_export($algo[1], TRUE));
65
+			throw new Exception('Unsupported OCRA version: '.var_export($algo[1], TRUE));
66 66
 		}
67 67
 		$this->OCRAVersion = $algo[1];
68 68
 
69 69
 		$cf = explode('-', $s[1]);
70 70
 		if (count($cf) != 3) {
71
-			throw new Exception('Invalid OCRA suite crypto function: ' . var_export($s[1], TRUE));
71
+			throw new Exception('Invalid OCRA suite crypto function: '.var_export($s[1], TRUE));
72 72
 		}
73 73
 
74 74
 		if ($cf[0] !== 'HOTP') {
75
-			throw new Exception('Unsupported OCRA suite crypto function: ' . var_export($cf[0], TRUE));
75
+			throw new Exception('Unsupported OCRA suite crypto function: '.var_export($cf[0], TRUE));
76 76
 		}
77 77
 		$this->CryptoFunctionType = $cf[0];
78 78
 
79 79
 		if (!array_key_exists($cf[1], $this->supportedHashFunctions)) {
80
-			throw new Exception('Unsupported hash function in OCRA suite crypto function: ' . var_export($cf[1], TRUE));
80
+			throw new Exception('Unsupported hash function in OCRA suite crypto function: '.var_export($cf[1], TRUE));
81 81
 		}
82 82
 		$this->CryptoFunctionHash = $cf[1];
83 83
 		$this->CryptoFunctionHashLength = $this->supportedHashFunctions[$cf[1]];
84 84
 
85 85
 		if (!preg_match('/^\d+$/', $cf[2]) || (($cf[2] < 4 || $cf[2] > 10) && $cf[2] != 0)) {
86
-			throw new Exception('Invalid OCRA suite crypto function truncation length: ' . var_export($cf[2], TRUE));
86
+			throw new Exception('Invalid OCRA suite crypto function truncation length: '.var_export($cf[2], TRUE));
87 87
 		}
88 88
 		$this->CryptoFunctionTruncation = intval($cf[2]);
89 89
 
90 90
 		$di = explode('-', $s[2]);
91 91
 		if (count($cf) == 0) {
92
-			throw new Exception('Invalid OCRA suite data input: ' . var_export($s[2], TRUE));
92
+			throw new Exception('Invalid OCRA suite data input: '.var_export($s[2], TRUE));
93 93
 		}
94 94
 
95 95
 		$data_input = array();
96
-		foreach($di as $elem) {
96
+		foreach ($di as $elem) {
97 97
 			$letter = $elem[0];
98 98
 			if (array_key_exists($letter, $data_input)) {
99
-				throw new Exception('Duplicate field in OCRA suite data input: ' . var_export($elem, TRUE));
99
+				throw new Exception('Duplicate field in OCRA suite data input: '.var_export($elem, TRUE));
100 100
 			}
101 101
 			$data_input[$letter] = 1;
102 102
 
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 				} elseif (preg_match('/^Q([AHN])(\d+)$/', $elem, $match)) {
109 109
 					$q_len = intval($match[2]);
110 110
 					if ($q_len < 4 || $q_len > 64) {
111
-						throw new Exception('Invalid OCRA suite data input question length: ' . var_export($q_len, TRUE));
111
+						throw new Exception('Invalid OCRA suite data input question length: '.var_export($q_len, TRUE));
112 112
 					}
113 113
 					$this->Q = TRUE;
114 114
 					$this->QType = $match[1];
115 115
 					$this->QLength = $q_len;
116 116
 				} else {
117
-					throw new Exception('Invalid OCRA suite data input question: ' . var_export($elem, TRUE));
117
+					throw new Exception('Invalid OCRA suite data input question: '.var_export($elem, TRUE));
118 118
 				}
119 119
 			} elseif ($letter === 'P') {
120 120
 				if (strlen($elem) == 1) {
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 				} else {
123 123
 					$p_algo = substr($elem, 1);
124 124
 					if (!array_key_exists($p_algo, $this->supportedHashFunctions)) {
125
-						throw new Exception('Unsupported OCRA suite PIN hash function: ' . var_export($elem, TRUE));
125
+						throw new Exception('Unsupported OCRA suite PIN hash function: '.var_export($elem, TRUE));
126 126
 					}
127 127
 					$this->P = TRUE;
128 128
 					$this->PType = $p_algo;
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
 				} elseif (preg_match('/^S(\d+)$/', $elem, $match)) {
135 135
 					$s_len = intval($match[1]);
136 136
 					if ($s_len <= 0 || $s_len > 512) {
137
-						throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($s_len, TRUE));
137
+						throw new Exception('Invalid OCRA suite data input session information length: '.var_export($s_len, TRUE));
138 138
 					}
139 139
 
140 140
 					$this->S = TRUE;
141 141
 					$this->SLength = $s_len;
142 142
 				} else {
143
-					throw new Exception('Invalid OCRA suite data input session information length: ' . var_export($elem, TRUE));
143
+					throw new Exception('Invalid OCRA suite data input session information length: '.var_export($elem, TRUE));
144 144
 				}
145 145
 			} elseif ($letter === 'T') {
146 146
 				if (strlen($elem) == 1) {
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 					preg_match_all('/(\d+)([HMS])/', $elem, $match);
150 150
 
151 151
 					if (count($match[1]) !== count(array_unique($match[2]))) {
152
-						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: ' . var_export($elem, TRUE));
152
+						throw new Exception('Duplicate definitions in OCRA suite data input timestamp: '.var_export($elem, TRUE));
153 153
 					}
154 154
 
155 155
 					$length = 0;
@@ -157,21 +157,21 @@  discard block
 block discarded – undo
157 157
 						$length += intval($match[1][$i]) * $this->TPeriods[$match[2][$i]];
158 158
 					}
159 159
 					if ($length <= 0) {
160
-						throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
160
+						throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
161 161
 					}
162 162
 
163 163
 					$this->T = TRUE;
164 164
 					$this->TLength = $length;
165 165
 				} else {
166
-					throw new Exception('Invalid OCRA suite data input timestamp: ' . var_export($elem, TRUE));
166
+					throw new Exception('Invalid OCRA suite data input timestamp: '.var_export($elem, TRUE));
167 167
 				}
168 168
 			} else {
169
-				throw new Exception('Unsupported OCRA suite data input field: ' . var_export($elem, TRUE));
169
+				throw new Exception('Unsupported OCRA suite data input field: '.var_export($elem, TRUE));
170 170
 			}
171 171
 		}
172 172
 
173 173
 		if (!$this->Q) {
174
-			throw new Exception('OCRA suite data input question not defined: ' . var_export($s[2], TRUE));
174
+			throw new Exception('OCRA suite data input question not defined: '.var_export($s[2], TRUE));
175 175
 		}
176 176
 	}
177 177
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 
182 182
 		$bytes = self::generateRandomBytes($q_length);
183 183
 
184
-		switch($q_type) {
184
+		switch ($q_type) {
185 185
 			case 'A':
186 186
 				$challenge = base64_encode($bytes);
187 187
 				$tr = implode("", unpack('H*', $bytes));
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 				$challenge = implode("", unpack('N*', $bytes));
195 195
 				break;
196 196
 			default:
197
-				throw new Exception('Unsupported OCRASuite challenge type: ' . var_export($q_type, TRUE));
197
+				throw new Exception('Unsupported OCRASuite challenge type: '.var_export($q_type, TRUE));
198 198
 				break;
199 199
 		}
200 200
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 
207 207
 	public function generateSessionInformation() {
208 208
 		if (!$this->S) {
209
-			throw new Exception('Session information not defined in OCRASuite: ' . var_export($this->OCRASuite, TRUE));
209
+			throw new Exception('Session information not defined in OCRASuite: '.var_export($this->OCRASuite, TRUE));
210 210
 		}
211 211
 
212 212
 		$s_length = $this->SLength;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
 		/* Use mt_rand to generate $length random bytes. */
230 230
 		$data = '';
231
-		for($i = 0; $i < $length; $i++) {
231
+		for ($i = 0; $i < $length; $i++) {
232 232
 			$data .= chr(mt_rand(0, 255));
233 233
 		}
234 234
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 			return openssl_random_pseudo_bytes($length);
247 247
 		}
248 248
 
249
-		if($fp === NULL) {
249
+		if ($fp === NULL) {
250 250
 			if (@file_exists('/dev/urandom')) {
251 251
 				$fp = @fopen('/dev/urandom', 'rb');
252 252
 			} else {
@@ -254,17 +254,17 @@  discard block
 block discarded – undo
254 254
 			}
255 255
 		}
256 256
 
257
-		if($fp !== FALSE) {
257
+		if ($fp !== FALSE) {
258 258
 			/* Read random bytes from /dev/urandom. */
259 259
 			$data = fread($fp, $length);
260
-			if($data === FALSE) {
260
+			if ($data === FALSE) {
261 261
 				throw new Exception('Error reading random data.');
262 262
 			}
263
-			if(strlen($data) != $length) {
263
+			if (strlen($data) != $length) {
264 264
 				if ($fallback) {
265 265
 					$data = self::generateRandomBytesMTrand($length);
266 266
 				} else {
267
-					throw new Exception('Did not get requested number of bytes from random source. Requested (' . $length . ') got (' . strlen($data) . ')');
267
+					throw new Exception('Did not get requested number of bytes from random source. Requested ('.$length.') got ('.strlen($data).')');
268 268
 				}
269 269
 			}
270 270
 		} else {
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 			$result &= ($s1[$i] == $s2[$i]);
291 291
 		}
292 292
 
293
-		return (boolean)$result;
293
+		return (boolean) $result;
294 294
 	}
295 295
 
296 296
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/API/Client.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
      * @param string $method	The HTTP Method (GET, POST, PUT, DELETE)
46 46
      * @param array  $data		Data send with request as key => value pairs
47 47
      *
48
-     * @return Object
48
+     * @return Tiqr_API_Entity_APIResult
49 49
      *
50 50
      * @throws Exception
51 51
      */
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      */
26 26
     public function setBaseURL($apiBaseURL)
27 27
     {
28
-        $this->_apiBaseURL = rtrim($apiBaseURL, '/') . '/';
28
+        $this->_apiBaseURL = rtrim($apiBaseURL, '/').'/';
29 29
     }
30 30
 
31 31
     /**
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     protected function callAPI($resource, $method = "GET", $data = array(), $headers = array())
79 79
     {
80 80
         $ch = curl_init();
81
-        curl_setopt($ch, CURLOPT_URL, $this->_apiBaseURL . ltrim($resource, '/'));
81
+        curl_setopt($ch, CURLOPT_URL, $this->_apiBaseURL.ltrim($resource, '/'));
82 82
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
83 83
 
84 84
         // Explicitly empty null values, because http_build_query will throw away
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 
108 108
         $headerArray = array();
109 109
         foreach ($headers as $key => $value) {
110
-            $headerArray[] = $key . ': ' . $value;
110
+            $headerArray[] = $key.': '.$value;
111 111
         }
112 112
 
113 113
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Message/FCM.php 2 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,11 +48,10 @@
 block discarded – undo
48 48
     /**
49 49
      * Send a message to a device using the firebase API key.
50 50
      *
51
-     * @param $deviceToken string device ID
52
-     * @param $alert string alert message
51
+     * @param string $deviceToken string device ID
52
+     * @param string $alert string alert message
53 53
      * @param $challenge string tiqr challenge url
54 54
      * @param $apiKey string api key for firebase
55
-     * @param Tiqr_Message_Exception $gcmException
56 55
      *
57 56
      * @throws Tiqr_Message_Exception_SendFailure
58 57
      */
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/HOTP.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * Calculate a HOTP response 
32 32
      * @param String $secret
33 33
      * @param String $counter
34
-     * @return String The response
34
+     * @return integer The response
35 35
      */
36 36
     public function calculateResponse($secret, $counter)
37 37
     {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      * Truncate a response to a certain length.
73 73
      * @param String $hash
74 74
      * @param int $length
75
-     * @return String a truncated response
75
+     * @return integer a truncated response
76 76
      */
77 77
     protected function _truncate($hash, $length = 6)
78 78
     {
Please login to merge, or discard this patch.
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -48,24 +48,24 @@  discard block
 block discarded – undo
48 48
      */
49 49
     protected function _getHash ($secret, $counter)
50 50
     {
51
-         // Counter
52
-         //the counter value can be more than one byte long, so we need to go multiple times
53
-         $cur_counter = array(0,0,0,0,0,0,0,0);
54
-         for($i=7;$i>=0;$i--)
55
-         {
56
-             $cur_counter[$i] = pack ('C*', $counter);
57
-             $counter = $counter >> 8;
58
-         }
59
-         $bin_counter = implode($cur_counter);
60
-         // Pad to 8 chars
61
-         if (strlen ($bin_counter) < 8)
62
-         {
63
-             $bin_counter = str_repeat (chr(0), 8 - strlen ($bin_counter)) . $bin_counter;
64
-         }
51
+            // Counter
52
+            //the counter value can be more than one byte long, so we need to go multiple times
53
+            $cur_counter = array(0,0,0,0,0,0,0,0);
54
+            for($i=7;$i>=0;$i--)
55
+            {
56
+                $cur_counter[$i] = pack ('C*', $counter);
57
+                $counter = $counter >> 8;
58
+            }
59
+            $bin_counter = implode($cur_counter);
60
+            // Pad to 8 chars
61
+            if (strlen ($bin_counter) < 8)
62
+            {
63
+                $bin_counter = str_repeat (chr(0), 8 - strlen ($bin_counter)) . $bin_counter;
64
+            }
65 65
      
66
-         // HMAC
67
-         $hash = hash_hmac ('sha1', $bin_counter, $secret);
68
-         return $hash;
66
+            // HMAC
67
+            $hash = hash_hmac ('sha1', $bin_counter, $secret);
68
+            return $hash;
69 69
     }
70 70
  
71 71
     /**
@@ -76,22 +76,22 @@  discard block
 block discarded – undo
76 76
      */
77 77
     protected function _truncate($hash, $length = 6)
78 78
     {
79
-         // Convert to dec
80
-         foreach(str_split($hash,2) as $hex)
81
-         {
82
-             $hmac_result[]=hexdec($hex);
83
-         }
79
+            // Convert to dec
80
+            foreach(str_split($hash,2) as $hex)
81
+            {
82
+                $hmac_result[]=hexdec($hex);
83
+            }
84 84
      
85
-         // Find offset
86
-         $offset = $hmac_result[19] & 0xf;  
85
+            // Find offset
86
+            $offset = $hmac_result[19] & 0xf;  
87 87
      
88
-         // Algorithm from RFC
89
-         return
90
-         (
91
-             (($hmac_result[$offset+0] & 0x7f) << 24 ) |
92
-             (($hmac_result[$offset+1] & 0xff) << 16 ) |
93
-             (($hmac_result[$offset+2] & 0xff) << 8 ) |
94
-             ($hmac_result[$offset+3] & 0xff)
95
-         ) % pow(10,$length);
88
+            // Algorithm from RFC
89
+            return
90
+            (
91
+                (($hmac_result[$offset+0] & 0x7f) << 24 ) |
92
+                (($hmac_result[$offset+1] & 0xff) << 16 ) |
93
+                (($hmac_result[$offset+2] & 0xff) << 8 ) |
94
+                ($hmac_result[$offset+3] & 0xff)
95
+            ) % pow(10,$length);
96 96
     }
97 97
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -46,25 +46,25 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRA.php 4 patches
Doc Comments   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,6 +32,9 @@  discard block
 block discarded – undo
32 32
      * @param String crypto     the crypto algorithm (sha1, sha256 or sha512)
33 33
      * @param String keyBytes   the bytes to use for the HMAC key
34 34
      * @param String text       the message or text to be authenticated.
35
+     * @param string $crypto
36
+     * @param string $keyBytes
37
+     * @param string $text
35 38
      */
36 39
     private static function _hmac_sha1($crypto,
37 40
             $keyBytes,
@@ -58,19 +61,22 @@  discard block
 block discarded – undo
58 61
      * set of parameters.
59 62
      *
60 63
      * @param ocraSuite    the OCRA Suite
61
-     * @param key          the shared secret, HEX encoded
62
-     * @param counter      the counter that changes
64
+     * @param key          string shared secret, HEX encoded
65
+     * @param counter      string counter that changes
63 66
      *                     on a per use basis,
64 67
      *                     HEX encoded
65
-     * @param question     the challenge question, HEX encoded
68
+     * @param question     string challenge question, HEX encoded
66 69
      * @param password     a password that can be used,
67 70
      *                     HEX encoded
68 71
      * @param sessionInformation
69 72
      *                     Static information that identifies the
70 73
      *                     current session, Hex encoded
71 74
      * @param timeStamp    a value that reflects a time
75
+     * @param string $password
76
+     * @param string $sessionInformation
77
+     * @param string $timeStamp
72 78
      *
73
-     * @return A numeric String in base 10 that includes
79
+     * @return string numeric String in base 10 that includes
74 80
      * {@link truncationDigits} digits
75 81
      */
76 82
     static function generateOCRA($ocraSuite,
@@ -251,6 +257,7 @@  discard block
 block discarded – undo
251 257
 
252 258
     /**
253 259
      * Truncate a result to a certain length
260
+     * @param string $hash
254 261
      */    
255 262
     static function _oath_truncate($hash, $length = 6)
256 263
     {
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
             $keyBytes,
38 38
             $text)
39 39
     {
40
-         $hash = hash_hmac ($crypto, $text, $keyBytes);
41
-         return $hash;
40
+            $hash = hash_hmac ($crypto, $text, $keyBytes);
41
+            return $hash;
42 42
     }
43 43
 
44 44
     /**
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
      * {@link truncationDigits} digits
75 75
      */
76 76
     static function generateOCRA($ocraSuite,
77
-                                 $key,
78
-                                 $counter,
79
-                                 $question,
80
-                                 $password,
81
-                                 $sessionInformation,
82
-                                 $timeStamp)
77
+                                    $key,
78
+                                    $counter,
79
+                                    $question,
80
+                                    $password,
81
+                                    $sessionInformation,
82
+                                    $timeStamp)
83 83
     {
84 84
         $codeDigits = 0;
85 85
         $crypto = "";
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 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
         }
@@ -255,19 +255,19 @@  discard block
 block discarded – undo
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);
Please login to merge, or discard this patch.
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.
library/tiqr/Tiqr/OATH/OCRA_v1.php 4 patches
Doc Comments   +12 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,6 +41,9 @@  discard block
 block discarded – undo
41 41
      * @param String crypto     the crypto algorithm (sha1, sha256 or sha512)
42 42
      * @param String keyBytes   the bytes to use for the HMAC key
43 43
      * @param String text       the message or text to be authenticated.
44
+     * @param string $crypto
45
+     * @param string $keyBytes
46
+     * @param string $text
44 47
      */
45 48
     private static function _hmac_sha1($crypto,
46 49
             $keyBytes,
@@ -66,20 +69,23 @@  discard block
 block discarded – undo
66 69
      * This method generates an OCRA HOTP value for the given
67 70
      * set of parameters.
68 71
      *
69
-     * @param ocraSuite    the OCRA Suite
70
-     * @param key          the shared secret, HEX encoded
71
-     * @param counter      the counter that changes
72
+     * @param ocraSuite    string OCRA Suite
73
+     * @param key          string shared secret, HEX encoded
74
+     * @param counter      string counter that changes
72 75
      *                     on a per use basis,
73 76
      *                     HEX encoded
74
-     * @param question     the challenge question, HEX encoded
77
+     * @param question     string challenge question, HEX encoded
75 78
      * @param password     a password that can be used,
76 79
      *                     HEX encoded
77 80
      * @param sessionInformation
78 81
      *                     Static information that identifies the
79 82
      *                     current session, Hex encoded
80 83
      * @param timeStamp    a value that reflects a time
84
+     * @param string $password
85
+     * @param string $sessionInformation
86
+     * @param string $timeStamp
81 87
      *
82
-     * @return A numeric String in base 10 that includes
88
+     * @return integer numeric String in base 10 that includes
83 89
      * {@link truncationDigits} digits
84 90
      */
85 91
     static function generateOCRA($ocraSuite,
@@ -223,6 +229,7 @@  discard block
 block discarded – undo
223 229
 
224 230
     /**
225 231
      * Truncate a result to a certain length
232
+     * @param string $hash
226 233
      */    
227 234
     function _oath_truncate($hash, $length = 6)
228 235
     {
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   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +24 added lines, -16 removed lines patch added patch discarded remove patch
@@ -101,12 +101,15 @@  discard block
 block discarded – undo
101 101
         $sessionInformationLength = 0;
102 102
         $timeStampLength = 0;
103 103
 
104
-        if(stripos($ocraSuite, "sha1")!==false)
105
-            $crypto = "sha1";
106
-        if(stripos($ocraSuite, "sha256")!==false)
107
-            $crypto = "sha256";
108
-        if(stripos($ocraSuite, "sha512")!==false)
109
-            $crypto = "sha512";
104
+        if(stripos($ocraSuite, "sha1")!==false) {
105
+                    $crypto = "sha1";
106
+        }
107
+        if(stripos($ocraSuite, "sha256")!==false) {
108
+                    $crypto = "sha256";
109
+        }
110
+        if(stripos($ocraSuite, "sha512")!==false) {
111
+                    $crypto = "sha512";
112
+        }
110 113
 
111 114
         // How many digits should we return
112 115
         $oS = substr($ocraSuite, strpos($ocraSuite, ":")+1, strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1) -strpos($ocraSuite, ":")-1);
@@ -116,31 +119,35 @@  discard block
 block discarded – undo
116 119
         // Counter
117 120
         if(stripos($ocraSuite, ":c") !==false) {
118 121
             // Fix the length of the HEX string
119
-            while(strlen($counter) < 16)
120
-                $counter = "0" . $counter;
122
+            while(strlen($counter) < 16) {
123
+                            $counter = "0" . $counter;
124
+            }
121 125
             $counterLength=8;
122 126
         }
123 127
         // Question
124 128
         if(stripos($ocraSuite, ":q")!==false ||
125 129
                 stripos($ocraSuite, "-q")!==false) {
126
-            while(strlen($question) < 256)
127
-                $question = $question . "0";
130
+            while(strlen($question) < 256) {
131
+                            $question = $question . "0";
132
+            }
128 133
             $questionLength=128;
129 134
         }
130 135
 
131 136
         // Password
132 137
         if(stripos($ocraSuite, ":p")!==false ||
133 138
                 stripos($ocraSuite, "-p") !==false) {
134
-            while(strlen($password) < 40)
135
-                $password = "0" . $password;
139
+            while(strlen($password) < 40) {
140
+                            $password = "0" . $password;
141
+            }
136 142
             $passwordLength=20;
137 143
         }
138 144
 
139 145
         // sessionInformation
140 146
         if(stripos($ocraSuite, ":s") !==false ||
141 147
                 stripos($ocraSuite, "-s", strpos($ocraSuite, ":", strpos($ocraSuite, ":")+1)) !== false) {
142
-            while(strlen($sessionInformation) < 128)
143
-                $sessionInformation = "0" . $sessionInformation;
148
+            while(strlen($sessionInformation) < 128) {
149
+                            $sessionInformation = "0" . $sessionInformation;
150
+            }
144 151
 
145 152
             $sessionInformationLength=64;
146 153
         }
@@ -148,8 +155,9 @@  discard block
 block discarded – undo
148 155
         // TimeStamp
149 156
         if(stripos($ocraSuite, ":t") !==false ||
150 157
                 stripos($ocraSuite, "-t") !== false) {
151
-            while(strlen($timeStamp) < 16)
152
-                $timeStamp = "0" . $timeStamp;
158
+            while(strlen($timeStamp) < 16) {
159
+                            $timeStamp = "0" . $timeStamp;
160
+            }
153 161
             $timeStampLength=8;
154 162
         }
155 163
 
Please login to merge, or discard this patch.
library/tiqr/Tiqr/OATH/OCRAWrapper_v1.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
72 72
      * @param String $secret a hex representation of the user's secret
73 73
      * @param String $challenge a hex or (alfa)numeric challenge question
74 74
      * @param String $sessionKey a hex sessionKey identifying the current session
75
-     * @return String An OCRA response, the length of which is determined by the
75
+     * @return integer An OCRA response, the length of which is determined by the
76 76
      *             OCRA suite.
77 77
      */
78 78
     public function calculateResponse($secret, $challenge, $sessionKey) 
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,9 +90,9 @@
 block discarded – undo
90 90
      */
91 91
     public function verifyResponse($response, $secret, $challenge, $sessionKey)
92 92
     {
93
-         $expected = $this->calculateResponse($secret, $challenge, $sessionKey);
93
+            $expected = $this->calculateResponse($secret, $challenge, $sessionKey);
94 94
 
95
-         return ($expected == $response);
95
+            return ($expected == $response);
96 96
     }
97 97
 
98 98
     /**
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -107,19 +107,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,9 @@
 block discarded – undo
107 107
     {
108 108
         // find the :QN10, -QN10, QH10 etc. bit
109 109
         $pos = stripos($ocraSuite, ":q");
110
-        if ($pos===false) $pos = stripos($ocraSuite, "-q");
110
+        if ($pos===false) {
111
+            $pos = stripos($ocraSuite, "-q");
112
+        }
111 113
         if ($pos===false) {
112 114
             // No challenge config specified. Since we only support challenge based OCRA, we fallback to default 10 digit hexadecimal.
113 115
             return array("format"=>"H", "length"=>10);
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Service.php 4 patches
Doc Comments   +1 added lines, -8 removed lines patch added patch discarded remove patch
@@ -334,10 +334,6 @@  discard block
 block discarded – undo
334 334
      * application, for example to create a link in a mobile website on the
335 335
      * same device as where the application is installed
336 336
      * @param String $sessionKey The session key identifying this authentication session
337
-     * @param String $userId The userId of a pre-authenticated user, if in  
338
-     *                       step-up mode. NULL in other scenario's.
339
-     * @param String $sessionId The application's session identifier. 
340
-     *                          (defaults to php session)
341 337
      */
342 338
     public function generateAuthURL($sessionKey)
343 339
     {
@@ -613,7 +609,7 @@  discard block
 block discarded – undo
613 609
      *                           session.
614 610
      * @param String $response   The response to the challenge that the phone
615 611
      *                           has posted.
616
-     * @return String The result of the authentication. This is one of the
612
+     * @return integer The result of the authentication. This is one of the
617 613
      *                AUTH_RESULT_* constants of the Tiqr_Server class.
618 614
      *                (do not make assumptions on the values of these 
619 615
      *                constants.)
@@ -710,9 +706,6 @@  discard block
 block discarded – undo
710 706
     /**
711 707
      * Generate a challenge URL
712 708
      * @param String $sessionKey The key that identifies the session.
713
-     * @param String $challenge The authentication challenge
714
-     * @param String $userId The userid to embed in the challenge url (only
715
-     *                       if a user was pre-authenticated)
716 709
      *                       
717 710
      */
718 711
     protected function _getChallengeUrl($sessionKey)
Please login to merge, or discard this patch.
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -514,17 +514,17 @@  discard block
 block discarded – undo
514 514
         }
515 515
 
516 516
         $metadata = array("service"=>
517
-                               array("displayName"       => $this->_name,
518
-                                     "identifier"        => $this->_identifier,
519
-                                     "logoUrl"           => $this->_logoUrl,
520
-                                     "infoUrl"           => $this->_infoUrl,
521
-                                     "authenticationUrl" => $authenticationUrl,
522
-                                     "ocraSuite"         => $this->_ocraSuite,
523
-                                     "enrollmentUrl"     => $enrollmentUrl
524
-                               ),
525
-                          "identity"=>
526
-                               array("identifier" =>$data["userId"],
527
-                                     "displayName"=>$data["displayName"]));
517
+                                array("displayName"       => $this->_name,
518
+                                        "identifier"        => $this->_identifier,
519
+                                        "logoUrl"           => $this->_logoUrl,
520
+                                        "infoUrl"           => $this->_infoUrl,
521
+                                        "authenticationUrl" => $authenticationUrl,
522
+                                        "ocraSuite"         => $this->_ocraSuite,
523
+                                        "enrollmentUrl"     => $enrollmentUrl
524
+                                ),
525
+                            "identity"=>
526
+                                array("identifier" =>$data["userId"],
527
+                                        "displayName"=>$data["displayName"]));
528 528
 
529 529
         $this->_stateStorage->unsetValue("enroll".$enrollmentKey);
530 530
 
@@ -547,10 +547,10 @@  discard block
 block discarded – undo
547 547
      */
548 548
     public function getEnrollmentSecret($enrollmentKey)
549 549
     {
550
-         $data = $this->_stateStorage->getValue("enroll".$enrollmentKey);
551
-         $secret = $this->_uniqueSessionKey("enrollmentsecret");
552
-         $this->_stateStorage->setValue("enrollsecret".$secret, array("userId"=>$data["userId"], "sessionId"=>$data["sessionId"]), self::ENROLLMENT_EXPIRE); 
553
-         return $secret;
550
+            $data = $this->_stateStorage->getValue("enroll".$enrollmentKey);
551
+            $secret = $this->_uniqueSessionKey("enrollmentsecret");
552
+            $this->_stateStorage->setValue("enrollsecret".$secret, array("userId"=>$data["userId"], "sessionId"=>$data["sessionId"]), self::ENROLLMENT_EXPIRE); 
553
+            return $secret;
554 554
     } 
555 555
 
556 556
     /**
@@ -565,13 +565,13 @@  discard block
 block discarded – undo
565 565
      */
566 566
     public function validateEnrollmentSecret($enrollmentSecret)
567 567
     {
568
-         $data = $this->_stateStorage->getValue("enrollsecret".$enrollmentSecret);
569
-         if (is_array($data)) { 
570
-             // Secret is valid, application may accept the user secret. 
571
-             $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_PROCESSED);
572
-             return $data["userId"];
573
-         }
574
-         return false;
568
+            $data = $this->_stateStorage->getValue("enrollsecret".$enrollmentSecret);
569
+            if (is_array($data)) { 
570
+                // Secret is valid, application may accept the user secret. 
571
+                $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_PROCESSED);
572
+                return $data["userId"];
573
+            }
574
+            return false;
575 575
     }
576 576
     
577 577
     /**
@@ -588,13 +588,13 @@  discard block
 block discarded – undo
588 588
      */
589 589
     public function finalizeEnrollment($enrollmentSecret) 
590 590
     {
591
-         $data = $this->_stateStorage->getValue("enrollsecret".$enrollmentSecret);
592
-         if (is_array($data)) {
593
-             // Enrollment is finalized, destroy our session data.
594
-             $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED);
595
-             $this->_stateStorage->unsetValue("enrollsecret".$enrollmentSecret);
596
-         }
597
-         return true;
591
+            $data = $this->_stateStorage->getValue("enrollsecret".$enrollmentSecret);
592
+            if (is_array($data)) {
593
+                // Enrollment is finalized, destroy our session data.
594
+                $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED);
595
+                $this->_stateStorage->unsetValue("enrollsecret".$enrollmentSecret);
596
+            }
597
+            return true;
598 598
     }
599 599
 
600 600
     /**
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 
631 631
         $challengeUserId = NULL;
632 632
         if (isset($state["userId"])) {
633
-          $challengeUserId = $state["userId"];
633
+            $challengeUserId = $state["userId"];
634 634
         }
635 635
         // Check if we're dealing with a second factor
636 636
         if ($challengeUserId!=NULL && ($userId != $challengeUserId)) {
@@ -769,6 +769,6 @@  discard block
 block discarded – undo
769 769
      */
770 770
     protected function _setEnrollmentStatus($sessionId, $status)
771 771
     {
772
-       $this->_stateStorage->setValue("enrollstatus".$sessionId, $status, self::ENROLLMENT_EXPIRE);
772
+        $this->_stateStorage->setValue("enrollstatus".$sessionId, $status, self::ENROLLMENT_EXPIRE);
773 773
     }
774 774
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 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
     /**
79 79
      * Default timeout values
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
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.
library/tiqr/Tiqr/UserStorage/Encryption/Dummy.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @param String $data Data to encrypt.
42 42
      *
43
-     * @return encrypted data
43
+     * @return string data
44 44
      */
45 45
     public function encrypt($data)
46 46
     {
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @param String $data Data to decrypt.
54 54
      *
55
-     * @return decrypted data
55
+     * @return string data
56 56
      */
57 57
     public function decrypt($data)
58 58
     {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
     }
49 49
     
50 50
     /**
51
-      * Decrypts the given data.
51
+     * Decrypts the given data.
52 52
      *
53 53
      * @param String $data Data to decrypt.
54 54
      *
Please login to merge, or discard this patch.