Completed
Push — master ( 8024f3...e355ed )
by Michiel
03:33 queued 14s
created
library/tiqr/OATH/OCRAParser.php 2 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.
library/tiqr/Tiqr/API/Client.php 1 patch
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.
library/tiqr/Tiqr/Message/FCM.php 1 patch
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.
library/tiqr/Tiqr/OATH/HOTP.php 2 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.
library/tiqr/Tiqr/OATH/OCRA.php 2 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.
library/tiqr/Tiqr/OATH/OCRA_v1.php 2 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.
library/tiqr/Tiqr/OATH/OCRAWrapper_v1.php 2 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.
library/tiqr/Tiqr/Service.php 2 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.
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.