Passed
Push — master ( 1c7137...b5ef5e )
by Pieter van der
03:26 queued 14s
created

OATH_OCRATest::testRFCVectors()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 16
rs 9.5555
cc 5
nc 12
nop 4
1
<?php
2
3
require_once(realpath(dirname(__FILE__) . '/OCRA.php'));
4
5
class OATH_OCRATest extends PHPUnit_Framework_TestCase {
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
	/**
8
	 * @dataProvider RFCVectorsProvider
9
	 */
10
	public function testRFCVectors($ocrasuite, $key, $datainput, $expected_result) {
11
		$ocra = new OATH_OCRA($ocrasuite, $key, NULL, $datainput['Q']);
12
		$ocra->setKey($key, 'hexstring');
13
		$ocra->setQuestion($datainput['Q']);
14
		if (isset($datainput['C'])) {
15
			$ocra->setCounter($datainput['C']);
16
		}
17
		if (isset($datainput['P'])) {
18
			$ocra->setPin($datainput['P']);
19
		} elseif (isset($datainput['P:hexdigest'])) {
20
			$ocra->setPin($datainput['P:hexdigest'], 'hexdigest');
21
		}
22
		if (isset($datainput['T'])) {
23
			$ocra->setTimestamp($datainput['T']);
24
		}
25
		$this->assertTrue($ocra->verifyResponse($expected_result));
26
	}
27
28
29
	public function RFCVectorsProvider() {
30
		$pin = '1234';
0 ignored issues
show
Unused Code introduced by
The assignment to $pin is dead and can be removed.
Loading history...
31
		$pin_sha1 = '7110eda4d09e062aa5e4a390b0a572ac0d2c0220';
32
33
		$key20 = '3132333435363738393031323334353637383930';
34
		$key32 = '3132333435363738393031323334353637383930313233343536373839303132';
35
		$key64 = '31323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334';
36
37
		$tests = array(
38
			array(
39
				'ocrasuite' => 'OCRA-1:HOTP-SHA1-6:QN08',
40
				'key' => $key20,
41
				'vectors' => array(
42
					array('params' => array( 'Q' => '00000000' ), 'result' => '237653' ),
43
					array('params' => array( 'Q' => '11111111' ), 'result' => '243178' ),
44
					array('params' => array( 'Q' => '22222222' ), 'result' => '653583' ),
45
					array('params' => array( 'Q' => '33333333' ), 'result' => '740991' ),
46
					array('params' => array( 'Q' => '44444444' ), 'result' => '608993' ),
47
					array('params' => array( 'Q' => '55555555' ), 'result' => '388898' ),
48
					array('params' => array( 'Q' => '66666666' ), 'result' => '816933' ),
49
					array('params' => array( 'Q' => '77777777' ), 'result' => '224598' ),
50
					array('params' => array( 'Q' => '88888888' ), 'result' => '750600' ),
51
					array('params' => array( 'Q' => '99999999' ), 'result' => '294470' ),
52
				)
53
			),
54
			array(
55
				'ocrasuite' => 'OCRA-1:HOTP-SHA256-8:C-QN08-PSHA1',
56
				'key' => $key32,
57
				'pin_sha1' => $pin_sha1,
58
				'vectors' => array(
59
					array('params' => array( 'C' => 0, 'Q' => '12345678' ), 'result' => '65347737' ),
60
					array('params' => array( 'C' => 1, 'Q' => '12345678' ), 'result' => '86775851' ),
61
					array('params' => array( 'C' => 2, 'Q' => '12345678' ), 'result' => '78192410' ),
62
					array('params' => array( 'C' => 3, 'Q' => '12345678' ), 'result' => '71565254' ),
63
					array('params' => array( 'C' => 4, 'Q' => '12345678' ), 'result' => '10104329' ),
64
					array('params' => array( 'C' => 5, 'Q' => '12345678' ), 'result' => '65983500' ),
65
					array('params' => array( 'C' => 6, 'Q' => '12345678' ), 'result' => '70069104' ),
66
					array('params' => array( 'C' => 7, 'Q' => '12345678' ), 'result' => '91771096' ),
67
					array('params' => array( 'C' => 8, 'Q' => '12345678' ), 'result' => '75011558' ),
68
					array('params' => array( 'C' => 9, 'Q' => '12345678' ), 'result' => '08522129' ),
69
				)
70
			),
71
			array(
72
				'ocrasuite' => 'OCRA-1:HOTP-SHA256-8:QN08-PSHA1',
73
				'key' => $key32,
74
				'pin_sha1' => $pin_sha1,
75
				'vectors' => array(
76
					array('params' => array( 'Q' => '00000000' ), 'result' => '83238735' ),
77
					array('params' => array( 'Q' => '11111111' ), 'result' => '01501458' ),
78
					array('params' => array( 'Q' => '22222222' ), 'result' => '17957585' ),
79
					array('params' => array( 'Q' => '33333333' ), 'result' => '86776967' ),
80
					array('params' => array( 'Q' => '44444444' ), 'result' => '86807031' ),
81
				)
82
			),
83
			array(
84
				'ocrasuite' => 'OCRA-1:HOTP-SHA512-8:C-QN08',
85
				'key' => $key64,
86
				'vectors' => array(
87
					array('params' => array( 'C' => '00000', 'Q' => '00000000' ), 'result' => '07016083' ),
88
					array('params' => array( 'C' => '00001', 'Q' => '11111111' ), 'result' => '63947962' ),
89
					array('params' => array( 'C' => '00002', 'Q' => '22222222' ), 'result' => '70123924' ),
90
					array('params' => array( 'C' => '00003', 'Q' => '33333333' ), 'result' => '25341727' ),
91
					array('params' => array( 'C' => '00004', 'Q' => '44444444' ), 'result' => '33203315' ),
92
					array('params' => array( 'C' => '00005', 'Q' => '55555555' ), 'result' => '34205738' ),
93
					array('params' => array( 'C' => '00006', 'Q' => '66666666' ), 'result' => '44343969' ),
94
					array('params' => array( 'C' => '00007', 'Q' => '77777777' ), 'result' => '51946085' ),
95
					array('params' => array( 'C' => '00008', 'Q' => '88888888' ), 'result' => '20403879' ),
96
					array('params' => array( 'C' => '00009', 'Q' => '99999999' ), 'result' => '31409299' ),
97
				)
98
			),
99
			array(
100
				'ocrasuite' => 'OCRA-1:HOTP-SHA512-8:QN08-T1M',
101
				'key' => $key64,
102
				'vectors' => array(
103
					array('params' => array( 'Q' => '00000000', 'T' => intval('132d0b6', 16) ), 'result' => '95209754' ),
104
					array('params' => array( 'Q' => '11111111', 'T' => intval('132d0b6', 16) ), 'result' => '55907591' ),
105
					array('params' => array( 'Q' => '22222222', 'T' => intval('132d0b6', 16) ), 'result' => '22048402' ),
106
					array('params' => array( 'Q' => '33333333', 'T' => intval('132d0b6', 16) ), 'result' => '24218844' ),
107
					array('params' => array( 'Q' => '44444444', 'T' => intval('132d0b6', 16) ), 'result' => '36209546' ),
108
				)
109
			),
110
		);
111
112
		$data = array();
113
114
		foreach($tests as $test) {
115
			$ocrasuite = $test['ocrasuite'];
116
			foreach($test['vectors'] as $vector) {
117
				$datainput = $vector['params'];
118
				if (isset($test['pin'])) {
119
					$datainput['P'] = $test['pin'];
120
				} elseif (isset($test['pin_sha1'])) {
121
					$datainput['P:hexdigest'] = $test['pin_sha1'];
122
				}
123
				$data[] = array($ocrasuite, $test['key'], $datainput, $vector['result']);
124
			}
125
		}
126
127
		return $data;
128
	}
129
130
}
131