|
| 1 | +<?php |
| 2 | +namespace ScriptFUSION\Porter\Net\Ssl; |
| 3 | + |
| 4 | +use ScriptFUSION\Porter\Options\EncapsulatedOptions; |
| 5 | + |
| 6 | +/** |
| 7 | + * Encapsulates SSL context options. |
| 8 | + * |
| 9 | + * @see http://php.net/manual/en/context.ssl.php |
| 10 | + */ |
| 11 | +final class SslOptions extends EncapsulatedOptions |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @return string |
| 15 | + */ |
| 16 | + public function getPeerName() |
| 17 | + { |
| 18 | + return $this->get('peer_name'); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * @param string $peerName |
| 23 | + * |
| 24 | + * @return $this |
| 25 | + */ |
| 26 | + public function setPeerName($peerName) |
| 27 | + { |
| 28 | + return $this->set('peer_name', "$peerName"); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @return bool |
| 33 | + */ |
| 34 | + public function getVerifyPeer() |
| 35 | + { |
| 36 | + return $this->get('verify_peer'); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @param bool $verifyPeer |
| 41 | + * |
| 42 | + * @return $this |
| 43 | + */ |
| 44 | + public function setVerifyPeer($verifyPeer) |
| 45 | + { |
| 46 | + return $this->set('verify_peer', (bool)$verifyPeer); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @return bool |
| 51 | + */ |
| 52 | + public function getVerifyPeerName() |
| 53 | + { |
| 54 | + return $this->get('verify_peer_name'); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @param bool $verifyPeerName |
| 59 | + * |
| 60 | + * @return $this |
| 61 | + */ |
| 62 | + public function setVerifyPeerName($verifyPeerName) |
| 63 | + { |
| 64 | + return $this->set('verify_peer_name', (bool)$verifyPeerName); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @return bool |
| 69 | + */ |
| 70 | + public function getAllowSelfSigned() |
| 71 | + { |
| 72 | + return $this->get('allow_self_signed'); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * @param bool $allowSelfSigned |
| 77 | + * |
| 78 | + * @return $this |
| 79 | + */ |
| 80 | + public function setAllowSelfSigned($allowSelfSigned) |
| 81 | + { |
| 82 | + return $this->set('allow_self_signed', (bool)$allowSelfSigned); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @return string |
| 87 | + */ |
| 88 | + public function getCertificateAuthorityFilePath() |
| 89 | + { |
| 90 | + return $this->get('cafile'); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @param string $certificateAuthorityFilePath |
| 95 | + * |
| 96 | + * @return $this |
| 97 | + */ |
| 98 | + public function setCertificateAuthorityFilePath($certificateAuthorityFilePath) |
| 99 | + { |
| 100 | + return $this->set('cafile', "$certificateAuthorityFilePath"); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * @return string |
| 105 | + */ |
| 106 | + public function getCertificateAuthorityDirectory() |
| 107 | + { |
| 108 | + return $this->get('capath'); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * @param string $certificateAuthorityDirectory |
| 113 | + * |
| 114 | + * @return $this |
| 115 | + */ |
| 116 | + public function setCertificateAuthorityDirectory($certificateAuthorityDirectory) |
| 117 | + { |
| 118 | + return $this->set('capath', "$certificateAuthorityDirectory"); |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * @return string |
| 123 | + */ |
| 124 | + public function getCertificateFilePath() |
| 125 | + { |
| 126 | + return $this->get('local_cert'); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * @param string $certificateFilePath |
| 131 | + * |
| 132 | + * @return $this |
| 133 | + */ |
| 134 | + public function setCertificateFilePath($certificateFilePath) |
| 135 | + { |
| 136 | + return $this->set('local_cert', "$certificateFilePath"); |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * @return string |
| 141 | + */ |
| 142 | + public function getCertificatePassphrase() |
| 143 | + { |
| 144 | + return $this->get('passphrase'); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * @param string $certificatePassphrase |
| 149 | + * |
| 150 | + * @return $this |
| 151 | + */ |
| 152 | + public function setCertificatePassphrase($certificatePassphrase) |
| 153 | + { |
| 154 | + return $this->set('passphrase', "$certificatePassphrase"); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * @return string |
| 159 | + */ |
| 160 | + public function getPrivateKeyFilePath() |
| 161 | + { |
| 162 | + return $this->get('local_pk'); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * @param string $privateKeyFilePath |
| 167 | + * |
| 168 | + * @return $this |
| 169 | + */ |
| 170 | + public function setPrivateKeyFilePath($privateKeyFilePath) |
| 171 | + { |
| 172 | + return $this->set('local_pk', "$privateKeyFilePath"); |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * @return int |
| 177 | + */ |
| 178 | + public function getVerificationDepth() |
| 179 | + { |
| 180 | + return $this->get('verify_depth'); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * @param int $verificationDepth |
| 185 | + * |
| 186 | + * @return $this |
| 187 | + */ |
| 188 | + public function setVerificationDepth($verificationDepth) |
| 189 | + { |
| 190 | + return $this->set('verify_depth', $verificationDepth | 0); |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * @return string |
| 195 | + */ |
| 196 | + public function getCiphers() |
| 197 | + { |
| 198 | + return $this->get('ciphers'); |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * @param string $ciphers |
| 203 | + * |
| 204 | + * @return $this |
| 205 | + */ |
| 206 | + public function setCiphers($ciphers) |
| 207 | + { |
| 208 | + return $this->set('ciphers', "$ciphers"); |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | + * @return bool |
| 213 | + */ |
| 214 | + public function getCapturePeerCertificate() |
| 215 | + { |
| 216 | + return $this->get('capture_peer_cert'); |
| 217 | + } |
| 218 | + |
| 219 | + /** |
| 220 | + * @param bool $capturePeerCertificate |
| 221 | + * |
| 222 | + * @return $this |
| 223 | + */ |
| 224 | + public function setCapturePeerCertificate($capturePeerCertificate) |
| 225 | + { |
| 226 | + return $this->set('capture_peer_cert', (bool)$capturePeerCertificate); |
| 227 | + } |
| 228 | + |
| 229 | + /** |
| 230 | + * @return bool |
| 231 | + */ |
| 232 | + public function getCapturePeerCertificateChain() |
| 233 | + { |
| 234 | + return $this->get('capture_peer_cert_chain'); |
| 235 | + } |
| 236 | + |
| 237 | + /** |
| 238 | + * @param bool $capturePeerCertificateChain |
| 239 | + * |
| 240 | + * @return $this |
| 241 | + */ |
| 242 | + public function setCapturePeerCertificateChain($capturePeerCertificateChain) |
| 243 | + { |
| 244 | + return $this->set('capture_peer_cert_chain', (bool)$capturePeerCertificateChain); |
| 245 | + } |
| 246 | + |
| 247 | + /** |
| 248 | + * @return bool |
| 249 | + */ |
| 250 | + public function getSniEnabled() |
| 251 | + { |
| 252 | + return $this->get('SNI_enabled'); |
| 253 | + } |
| 254 | + |
| 255 | + /** |
| 256 | + * @param bool $sniEnabled |
| 257 | + * |
| 258 | + * @return $this |
| 259 | + */ |
| 260 | + public function setSniEnabled($sniEnabled) |
| 261 | + { |
| 262 | + return $this->set('SNI_enabled', (bool)$sniEnabled); |
| 263 | + } |
| 264 | + |
| 265 | + /** |
| 266 | + * @return bool |
| 267 | + */ |
| 268 | + public function getDisableCompression() |
| 269 | + { |
| 270 | + return $this->get('disable_compression'); |
| 271 | + } |
| 272 | + |
| 273 | + /** |
| 274 | + * @param bool $disableCompression |
| 275 | + * |
| 276 | + * @return $this |
| 277 | + */ |
| 278 | + public function setDisableCompression($disableCompression) |
| 279 | + { |
| 280 | + return $this->set('disable_compression', (bool)$disableCompression); |
| 281 | + } |
| 282 | + |
| 283 | + /** |
| 284 | + * @return string|array |
| 285 | + */ |
| 286 | + public function getPeerFingerprint() |
| 287 | + { |
| 288 | + return $this->get('peer_fingerprint'); |
| 289 | + } |
| 290 | + |
| 291 | + /** |
| 292 | + * @param string|array $peerFingerprint |
| 293 | + * |
| 294 | + * @return $this |
| 295 | + */ |
| 296 | + public function setPeerFingerprint($peerFingerprint) |
| 297 | + { |
| 298 | + return $this->set('peer_fingerprint', is_array($peerFingerprint) ? $peerFingerprint : "$peerFingerprint"); |
| 299 | + } |
| 300 | + |
| 301 | + /** |
| 302 | + * Extracts a list of SSL context options. |
| 303 | + * |
| 304 | + * @return array SSL context options. |
| 305 | + */ |
| 306 | + public function extractSslContextOptions() |
| 307 | + { |
| 308 | + return $this->copy(); |
| 309 | + } |
| 310 | +} |
0 commit comments