1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @copyright (c) 2015, Paul Sohier |
5
|
|
|
* @copyright (c) 2014 Yubico AB |
6
|
|
|
* @license BSD-2-Clause |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
* Orignal Copyright: |
10
|
|
|
* Copyright (c) 2014 Yubico AB |
11
|
|
|
* All rights reserved. |
12
|
|
|
* |
13
|
|
|
* Redistribution and use in source and binary forms, with or without |
14
|
|
|
* modification, are permitted provided that the following conditions are |
15
|
|
|
* met: |
16
|
|
|
* |
17
|
|
|
* * Redistributions of source code must retain the above copyright |
18
|
|
|
* notice, this list of conditions and the following disclaimer. |
19
|
|
|
* |
20
|
|
|
* * Redistributions in binary form must reproduce the above |
21
|
|
|
* copyright notice, this list of conditions and the following |
22
|
|
|
* disclaimer in the documentation and/or other materials provided |
23
|
|
|
* with the distribution. |
24
|
|
|
* |
25
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
26
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
27
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
28
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
29
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
30
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
31
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
32
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
33
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
34
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
35
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
36
|
|
|
*/ |
37
|
|
|
|
38
|
|
|
namespace paul999\u2f; |
39
|
|
|
use JsonSerializable; |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Class for building a registration request |
44
|
|
|
* |
45
|
|
|
* @package u2flib_server |
46
|
|
|
*/ |
47
|
|
|
class RegisterRequest implements RegisterRequestInterface, JsonSerializable |
48
|
|
|
{ |
49
|
|
|
/** Protocol version */ |
50
|
|
|
private $version = U2F_interface::U2F_VERSION; |
51
|
|
|
|
52
|
|
|
/** Registration challenge */ |
53
|
|
|
private $challenge; |
54
|
|
|
|
55
|
|
|
/** Application id */ |
56
|
|
|
private $appId; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $challenge |
60
|
|
|
* @param string $appId |
61
|
|
|
*/ |
62
|
|
|
public function __construct($challenge, $appId) |
63
|
|
|
{ |
64
|
|
|
$this->setChallenge($challenge); |
65
|
|
|
$this->setAppId($appId); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function getVersion() |
72
|
|
|
{ |
73
|
|
|
return $this->version; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param mixed $version |
78
|
|
|
* @return RegisterRequestInterface |
79
|
|
|
*/ |
80
|
|
|
public function setVersion($version) |
81
|
|
|
{ |
82
|
|
|
$this->version = $version; |
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return mixed |
88
|
|
|
*/ |
89
|
|
|
public function getChallenge() |
90
|
|
|
{ |
91
|
|
|
return $this->challenge; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param mixed $challenge |
96
|
|
|
* @return RegisterRequestInterface |
97
|
|
|
*/ |
98
|
|
|
public function setChallenge($challenge) |
99
|
|
|
{ |
100
|
|
|
$this->challenge = $challenge; |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
public function getAppId() |
108
|
|
|
{ |
109
|
|
|
return $this->appId; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param mixed $appId |
114
|
|
|
* @return RegisterRequestInterface |
115
|
|
|
*/ |
116
|
|
|
public function setAppId($appId) |
117
|
|
|
{ |
118
|
|
|
$this->appId = $appId; |
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Specify data which should be serialized to JSON |
124
|
|
|
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
125
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
126
|
|
|
* which is a value of any type other than a resource. |
127
|
|
|
* @since 5.4.0 |
128
|
|
|
*/ |
129
|
|
|
function jsonSerialize() |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
return [ |
132
|
|
|
'version' => $this->getVersion(), |
133
|
|
|
'appId' => $this->getAppId(), |
134
|
|
|
'challenge' => $this->getChallenge(), |
135
|
|
|
]; |
136
|
|
|
} |
137
|
|
|
} |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.