1 | <?php |
||
23 | class IPSECKEY implements RdataInterface |
||
24 | { |
||
25 | 1 | use RdataTrait; |
|
26 | |||
27 | const TYPE = 'IPSECKEY'; |
||
28 | const TYPE_CODE = 45; |
||
29 | const ALGORITHM_NONE = 0; |
||
30 | const ALGORITHM_DSA = 1; |
||
31 | const ALGORITHM_RSA = 2; |
||
32 | const ALGORITHM_ECDSA = 3; |
||
33 | |||
34 | /** |
||
35 | * This is an 8-bit precedence for this record. It is interpreted in |
||
36 | * the same way as the PREFERENCE field described in section 3.3.9 of |
||
37 | * RFC 1035. |
||
38 | * |
||
39 | * Gateways listed in IPSECKEY records with lower precedence are to be |
||
40 | * attempted first. Where there is a tie in precedence, the order |
||
41 | * should be non-deterministic. |
||
42 | * |
||
43 | * @var int |
||
44 | */ |
||
45 | private $precedence; |
||
46 | |||
47 | /** |
||
48 | * The gateway type field indicates the format of the information that |
||
49 | * is stored in the gateway field. |
||
50 | * |
||
51 | * The following values are defined: |
||
52 | * - 0: No gateway is present. |
||
53 | * - 1: A 4-byte IPv4 address is present. |
||
54 | * - 2: A 16-byte IPv6 address is present. |
||
55 | * - 3: A wire-encoded domain name is present. The wire-encoded format is |
||
56 | * self-describing, so the length is implicit. The domain name MUST |
||
57 | * NOT be compressed. (See Section 3.3 of RFC 1035.) |
||
58 | * |
||
59 | * @var int |
||
60 | */ |
||
61 | private $gatewayType; |
||
62 | |||
63 | /** |
||
64 | * 7-bit The algorithm type field identifies the public key's crypto- |
||
65 | * graphic algorithm and determines the format of the public key field. |
||
66 | * A value of 0 indicates that no key is present. |
||
67 | * |
||
68 | * The following values are defined: |
||
69 | * - 1: A DSA key is present, in the format defined in RFC 2536. |
||
70 | * - 2: A RSA key is present, in the format defined in RFC 3110. |
||
71 | * - 3: An ECDSA key is present, in the format defined in RFC 6605. |
||
72 | * |
||
73 | * @var int |
||
74 | */ |
||
75 | private $algorithm = 0; |
||
76 | |||
77 | /** |
||
78 | * The gateway field indicates a gateway to which an IPsec tunnel may be. |
||
79 | * created in order to reach the entity named by this resource record. |
||
80 | * |
||
81 | * There are three formats: |
||
82 | * |
||
83 | * A 32-bit IPv4 address is present in the gateway field. The data |
||
84 | * portion is an IPv4 address as described in section 3.4.1 of RFC 1035. |
||
85 | * This is a 32-bit number in network byte order. |
||
86 | * |
||
87 | * A 128-bit IPv6 address is present in the gateway field. The data |
||
88 | * portion is an IPv6 address as described in section 2.2 of RFC 3596 |
||
89 | * This is a 128-bit number in network byte order. |
||
90 | * |
||
91 | * The gateway field is a normal wire-encoded domain name, as described |
||
92 | * in section 3.3 of RFC 1035. Compression MUST NOT be used. |
||
93 | * |
||
94 | * @var string|null |
||
95 | */ |
||
96 | private $gateway; |
||
97 | |||
98 | /** |
||
99 | * Both the public key types defined in this document (RSA and DSA) |
||
100 | * inherit their public key formats from the corresponding KEY RR |
||
101 | * formats. Specifically, the public key field contains the |
||
102 | * algorithm-specific portion of the KEY RR RDATA, which is all the KEY |
||
103 | * RR DATA after the first four octets. This is the same portion of the |
||
104 | * KEY RR that must be specified by documents that define a DNSSEC |
||
105 | * algorithm. Those documents also specify a message digest to be used |
||
106 | * for generation of SIG RRs; that specification is not relevant for |
||
107 | * IPSECKEY RRs. |
||
108 | * |
||
109 | * @var string|null |
||
110 | */ |
||
111 | private $publicKey = null; |
||
112 | |||
113 | 12 | public function getPrecedence(): int |
|
117 | |||
118 | /** |
||
119 | * @throws \InvalidArgumentException |
||
120 | */ |
||
121 | 24 | public function setPrecedence(int $precedence): void |
|
128 | |||
129 | 12 | public function getGatewayType(): int |
|
133 | |||
134 | 12 | public function getAlgorithm(): int |
|
138 | |||
139 | /** |
||
140 | * @throws \InvalidArgumentException |
||
141 | */ |
||
142 | 24 | private function setAlgorithm(int $algorithm): void |
|
149 | |||
150 | 12 | public function getGateway(): ?string |
|
154 | |||
155 | /** |
||
156 | * @param string|null $gateway either &null for no gateway, a fully qualified domain name, or an IPv4 or IPv6 address |
||
157 | * |
||
158 | * @throws \InvalidArgumentException |
||
159 | */ |
||
160 | 24 | public function setGateway(?string $gateway): void |
|
177 | |||
178 | /** |
||
179 | * @return string|null base64 encoded public key |
||
180 | */ |
||
181 | 12 | public function getPublicKey(): ?string |
|
185 | |||
186 | /** |
||
187 | * @param int $algorithm either IPSECKEY::ALGORITHM_NONE, IPSECKEY::ALGORITHM_DSA, IPSECKEY::ALGORITHM_RSA, or IPSECKEY::ALGORITHM_ECDSA |
||
188 | * @param string|null $publicKey base64 encoded public key |
||
189 | * |
||
190 | * @throws \InvalidArgumentException |
||
191 | */ |
||
192 | 24 | public function setPublicKey(int $algorithm, ?string $publicKey): void |
|
197 | |||
198 | 12 | public function toText(): string |
|
208 | |||
209 | 6 | public function toWire(): string |
|
227 | |||
228 | 6 | public function fromText(string $text): void |
|
238 | |||
239 | /** |
||
240 | * @throws DecodeException |
||
241 | */ |
||
242 | 6 | public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void |
|
262 | |||
263 | /** |
||
264 | 6 | * @throws DecodeException |
|
265 | */ |
||
266 | 6 | private static function extractGateway(int $gatewayType, string $rdata, int &$offset): string |
|
292 | } |
||
293 |