|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author: Viskov Sergey |
|
4
|
|
|
* @date : 4/12/16 |
|
5
|
|
|
* @time : 1:00 PM |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace LTDBeget\dns\configurator\zoneEntities\record; |
|
9
|
|
|
|
|
10
|
|
|
use LTDBeget\dns\configurator\errors\ValidationError; |
|
11
|
|
|
use LTDBeget\dns\configurator\validators\Int16Validator; |
|
12
|
|
|
use LTDBeget\dns\configurator\zoneEntities\Node; |
|
13
|
|
|
use LTDBeget\dns\configurator\zoneEntities\record\base\Record; |
|
14
|
|
|
use LTDBeget\dns\enums\eErrorCode; |
|
15
|
|
|
use LTDBeget\dns\enums\eRecordType; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class CaaRecord |
|
19
|
|
|
* |
|
20
|
|
|
* @package LTDBeget\dns\configurator\zoneEntities\record |
|
21
|
|
|
*/ |
|
22
|
|
|
class CaaRecord extends Record |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var string explicity authorizes a single certificate authority to issue a certificate (any type) for the hostname */ |
|
25
|
|
|
const TAG_ISSUE = 'issue'; |
|
26
|
|
|
/** @var string explicity authorizes a single certificate authority to issue a wildcard certificate (and only wildcard) for the hostname */ |
|
27
|
|
|
const TAG_ISSUEWILD = 'issuewild'; |
|
28
|
|
|
/** @var string specifies a URL to which a certificate authority may report policy violations */ |
|
29
|
|
|
const TAG_IODEF = 'iodef'; |
|
30
|
|
|
/** @var string проверка по FQDN */ |
|
31
|
|
|
const PATTERN_FQDN = '/^([a-zа-яё0-9\_]([a-zа-яё0-9\-]{0,61}[a-zа-яё0-9])?\.)*([a-zа-яё0-9]([a-zа-яё0-9\-]{0,61}[a-zа-яё0-9])?\.)+[a-zа-яё0-9-]{2,30}$/i'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var Int |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $flags; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var String |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $tag; |
|
41
|
|
|
/** |
|
42
|
|
|
* @var String |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $value; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* CaaRecord constructor. |
|
48
|
|
|
* |
|
49
|
|
|
* @param Node $node |
|
50
|
|
|
* @param $ttl |
|
51
|
|
|
* @param int $flags |
|
52
|
|
|
* @param string $tag |
|
53
|
|
|
* @param string $value |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(Node $node, $ttl, int $flags, string $tag, string $value) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->flags = $flags; |
|
58
|
|
|
$this->tag = $tag; |
|
59
|
|
|
$this->value = $this->getFromQuotes($value); |
|
60
|
|
|
parent::__construct($node, eRecordType::CAA(), $ttl); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param $value |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
private function getFromQuotes(string $value) |
|
69
|
|
|
{ |
|
70
|
|
|
return str_replace(["\n", '"'], "", $value); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __toString(): string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->getMainRecordPart() . " {$this->getFlags()} {$this->getTag()} \"{$this->getValue()}\""; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return Int |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getFlags(): Int |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->flags; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param Int $flags |
|
91
|
|
|
* |
|
92
|
|
|
* @return CaaRecord |
|
93
|
|
|
*/ |
|
94
|
|
|
public function setFlags(Int $flags): CaaRecord |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->setAttribute('flags', $flags); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return String |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getTag(): String |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->tag; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param String $tag |
|
109
|
|
|
* |
|
110
|
|
|
* @return CaaRecord |
|
111
|
|
|
*/ |
|
112
|
|
|
public function setTag(String $tag): CaaRecord |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->setAttribute('tag', $tag); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return String |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getValue(): String |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->value; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param String $value |
|
127
|
|
|
* |
|
128
|
|
|
* @return CaaRecord |
|
129
|
|
|
*/ |
|
130
|
|
|
public function setValue(String $value): CaaRecord |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->setAttribute('value', $value); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @internal |
|
137
|
|
|
* @return bool |
|
138
|
|
|
*/ |
|
139
|
|
|
public function validate(): bool |
|
140
|
|
|
{ |
|
141
|
|
|
$errorStorage = $this->getNode()->getZone()->getErrorsStore(); |
|
142
|
|
|
|
|
143
|
|
|
\Yii::error($this->getTag(), 'check'); |
|
144
|
|
|
|
|
145
|
|
|
if (!in_array($this->tag, [self::TAG_ISSUE, self::TAG_ISSUEWILD, self::TAG_IODEF])) { |
|
146
|
|
|
$errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_CAA_TAG(), 'tag')); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
if ($this->flags < 0 || $this->flags > 128) { |
|
150
|
|
|
$errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_CAA_FLAG(), 'flag')); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
if (!Int16Validator::validate($this->getFlags())) { |
|
154
|
|
|
$errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_INT16(), 'flags')); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
if (in_array($this->getTag(), [self::TAG_ISSUEWILD, self::TAG_ISSUE]) && |
|
158
|
|
|
$this->getValue() !== ';' |
|
159
|
|
|
) { |
|
160
|
|
|
$parts = explode(";", $this->getValue()); |
|
161
|
|
|
|
|
162
|
|
|
if (!preg_match(self::PATTERN_FQDN, $parts[0])) { |
|
163
|
|
|
$errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_CAA_VALUE(), 'value')); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
if ($this->getTag() == self::TAG_IODEF) { |
|
168
|
|
|
if (!filter_var($this->getValue(), FILTER_VALIDATE_EMAIL) && !filter_var($this->getValue(), FILTER_VALIDATE_URL)) { |
|
169
|
|
|
$errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_CAA_VALUE(), 'value')); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** @noinspection PhpInternalEntityUsedInspection */ |
|
174
|
|
|
return parent::validate(); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @return array |
|
179
|
|
|
*/ |
|
180
|
|
|
protected function recordDataToArray(): array |
|
181
|
|
|
{ |
|
182
|
|
|
return [ |
|
183
|
|
|
'FLAGS' => $this->getFlags(), |
|
184
|
|
|
'TAG' => $this->getTag(), |
|
185
|
|
|
'VALUE' => $this->getValue() |
|
186
|
|
|
]; |
|
187
|
|
|
} |
|
188
|
|
|
} |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.