Passed
Push — develop ( 22eefe...e65dcd )
by Pieter van der
06:04
created

Tiqr_OCRAWrapper::generateChallenge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of the tiqr project.
5
 * 
6
 * The tiqr project aims to provide an open implementation for 
7
 * authentication using mobile devices. It was initiated by 
8
 * SURFnet and developed by Egeniq.
9
 *
10
 * More information: http://www.tiqr.org
11
 *
12
 * @author Ivo Jansch <[email protected]>
13
 * 
14
 * @package tiqr
15
 *
16
 * @license New BSD License - See LICENSE file for details.
17
 *
18
 * @copyright (C) 2010-2011 SURFnet BV
19
 */
20
21
22
/**
23
 * @internal includes
24
 */
25
require_once("OATH/OCRAParser.php");
26
require_once("Tiqr/Random.php");
27
require_once("Tiqr/OATH/OCRA.php");
28
29
/**
30
 * A wrapper for the OCRA algorithm implementing just the features we support.
31
 * @author ivo
32
 */
33
class Tiqr_OCRAWrapper
34
{
35
    private $_ocraParser;
36
    private $_ocraSuite;
37
38 7
    public function __construct($ocraSuite) {
39 7
        $this->_ocraSuite = $ocraSuite;
40 7
        $this->_ocraParser = new OATH_OCRAParser($ocraSuite);
41 7
    }
42
43
44
    /**
45
     * Generate a challenge string based on an ocraSuite
46
     * @return String An OCRA challenge that matches the specification of
47
     *         the ocraSuite.
48
     */
49 1
    public function generateChallenge()
50
    {
51 1
        return $this->_ocraParser->generateChallenge();
52
    }
53
    
54
    /**
55
     * Generate a session key based on an ocraSuite
56
     * @return String Hexadecimal session key
57
     */
58 3
    public function generateSessionKey()
59
    {
60 3
        return $this->_ocraParser->generateSessionInformation();
61
    }
62
63
    /**
64
     * Calculate an OCRA repsonse to a given OCRA challenge, according to
65
     * the algorithm specified by an OCRA Suite.
66
     * @param String $secret a hex representation of the user's secret
67
     * @param String $challenge a hex or (alfa)numeric challenge question
68
     * @param String $sessionKey a hex sessionKey identifying the current session
69
     * @return String An OCRA response, the length of which is determined by the
70
     *             OCRA suite.
71
     */
72 3
    public function calculateResponse($secret, $challenge, $sessionKey)
73
    {
74 3
        return OCRA::generateOCRA($this->_ocraSuite, $secret, "", $challenge, "", $sessionKey, "");
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type a expected by parameter $password of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        return OCRA::generateOCRA($this->_ocraSuite, $secret, "", $challenge, /** @scrutinizer ignore-type */ "", $sessionKey, "");
Loading history...
Bug introduced by
'' of type string is incompatible with the type a expected by parameter $timeStamp of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        return OCRA::generateOCRA($this->_ocraSuite, $secret, "", $challenge, "", $sessionKey, /** @scrutinizer ignore-type */ "");
Loading history...
Bug introduced by
$challenge of type string is incompatible with the type the expected by parameter $question of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        return OCRA::generateOCRA($this->_ocraSuite, $secret, "", /** @scrutinizer ignore-type */ $challenge, "", $sessionKey, "");
Loading history...
Bug introduced by
'' of type string is incompatible with the type the expected by parameter $counter of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        return OCRA::generateOCRA($this->_ocraSuite, $secret, /** @scrutinizer ignore-type */ "", $challenge, "", $sessionKey, "");
Loading history...
Bug introduced by
$secret of type string is incompatible with the type the expected by parameter $key of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        return OCRA::generateOCRA($this->_ocraSuite, /** @scrutinizer ignore-type */ $secret, "", $challenge, "", $sessionKey, "");
Loading history...
75
    }
76
77
    /**
78
     * Calculate and verify an OCRA response.
79
     * @param String $response Expected OCRA response
80
     * @param String $secret a hex representation of the user's secret
81
     * @param String $challenge a hex or (alfa)numeric challenge question
82
     * @param String $sessionKey the sessionKey identifying the current session
83
     * @return Boolean True if response matches, false otherwise
84
     */
85 2
    public function verifyResponse($response, $secret, $challenge, $sessionKey)
86
    {
87 2
        $expected = OCRA::generateOCRA($this->_ocraSuite, $secret, "", $challenge, "", $sessionKey, "");
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type a expected by parameter $timeStamp of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $expected = OCRA::generateOCRA($this->_ocraSuite, $secret, "", $challenge, "", $sessionKey, /** @scrutinizer ignore-type */ "");
Loading history...
Bug introduced by
'' of type string is incompatible with the type a expected by parameter $password of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $expected = OCRA::generateOCRA($this->_ocraSuite, $secret, "", $challenge, /** @scrutinizer ignore-type */ "", $sessionKey, "");
Loading history...
Bug introduced by
$secret of type string is incompatible with the type the expected by parameter $key of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $expected = OCRA::generateOCRA($this->_ocraSuite, /** @scrutinizer ignore-type */ $secret, "", $challenge, "", $sessionKey, "");
Loading history...
Bug introduced by
'' of type string is incompatible with the type the expected by parameter $counter of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $expected = OCRA::generateOCRA($this->_ocraSuite, $secret, /** @scrutinizer ignore-type */ "", $challenge, "", $sessionKey, "");
Loading history...
Bug introduced by
$challenge of type string is incompatible with the type the expected by parameter $question of OCRA::generateOCRA(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $expected = OCRA::generateOCRA($this->_ocraSuite, $secret, "", /** @scrutinizer ignore-type */ $challenge, "", $sessionKey, "");
Loading history...
88 2
        return $this->_ocraParser->constEqual($expected, $response);
89
        
90
    }
91
}
92